Introduction to Computer Science II by James Tam Return to the course web page

CPSC 231: Assignment 3 (Worth 7%)

New concepts to be applied in this assignment

  1. Dynamic memory allocation using references and class constructors
  2. Arrays of references
  3. Using code in predefined Java classes (e.g., String)
 

Introduction

For this assignment you are to write a Java program that allows a person to track a list of potential vacation sites.  The full version of the program will allow the user to perform some of the common list management functions, such as add, displaying, modifying or removing sites.  

 

Assignment description

Each site will be described by three fields:

  1. Site name: Consists series of alphabetic characters
  2. Site rating: An integer value between one and five
  3. Vacation type: A single alphabetic character

Description of the fields

1. Site name

The name of the site will be stored as a string of characters.

2. Vacation type

This field describes the main reason for traveling to this location.  There can be four different categories of sites with each one being represented by a single character code: relaxation (r), excitement (e), culture (c) or food (f).     For features #1 & #2 (listed below) your program must be able to check that the user only enters one of these characters for the vacation type and if not it will prompt him or her to enter a valid value.  For this assignment you can assume a particular site will not be categorized in multiple ways.  Note: When the user is prompted to enter in the information for a new site he or she will be prompted to only enter in a single character.  However when the information for a site is displayed it show a full description for the vacation type.  (For example, instead of displaying 'r' the program should display something more descriptive like 'relaxation' - run the sample executable for some ideas of how your descriptions may look).

3. Rating

This field is a numerical value from 1 - 5 that indicates how much that the person wants to go to a particular vacation spot with 5 being the most desirable and 1 being the least desirable.  Similar to the vacation type when you implement features #1 & #2 (listed below) your program must be able to check that the user enters a value within this range and will prompt him or her to enter in a proper value when this doesn't occur.   

 

Grades for working assignments:

To help you out here is a checklist to make sure that you haven't missed anything.  Obviously you won't get credit for your assignment if you use someone else's Java code (e.g., the ArrayList class) instead of writing your own.

Basic assignment: C+

Your program provides definitions for the following classes: Vacation, Manager, Site, Debug.

  1. Vacation: The starting execution point for your program.  You should probably instantiate an instance of class Manager in the 'main' method.

  2. Manager: Stores the array of vacation sites, implements the list management functions (display, add, modify, remove, search).  Your program should be able to track a reasonably large number of vacation sites (e.g., 100).

  3. Site: Tracks all the information associated with each vacation site (at the very least the three fields).

  4. Debug: This class has only a single purpose that is quite important, to track (via a boolean static attribute) the whether or not the program is in debugging mode.   The normal operating mode for the program is when no debugging messages appear to the user (the attribute is set to false).  A hidden menu option will allow the debugging mode to be toggled on and off (by setting the value of the attribute).  The specific content of the debugging messages is up to your discretion - this feature is meant as a tool to help you find and diagnosis the errors in your program as you write it.  What you shouldn't do is write your whole program without using this debugging mechanism and then only add the debugging mode as an after thought.

Features that need to be implemented:

  1. Properly initialize all starting values for attributes (e.g., the list of vacation sites starts off as empty).

  2. Display a menu of options (display, add, modify, remove or search for a site as well an option to quit the program - remember the ability to toggle the debugging mode on and off is a hidden feature and it shouldn't be displayed).  For this version, your program only has to be able to display the list and to quit the program (as well as have the hidden ability to toggle the debugging mode).

  3. The display of the list should show it in a neat and presentable fashion (try running the executable for an example of how the output of your program may look).  To prevent the output from scrolling off the screen your program should 'pause' the display of sites every so often (say after displaying every half dozen sites) while it waits for a response from the user to tell it to continue (e.g., 'Hit return to continue').  The program should only display occupied array elements and not null values.

  4. Show a brief introduction when the program is run and some sort of conclusion when the user quits from the program.

Missing these features will result in a reduction of your grade (down to a minimum of D or D-, assuming that sufficient effort was put into the assignment):

 

Extra features: 

Except for the ability to add a new site you can complete as many of the features below as you wish in whatever combination that you desire.    Successful completion of  the most elaborate versions of the four features (i.e., feature 1b, 2, 3b & 4) will make you eligible for an A+.   You must also fulfill style requirements as well as the general submission assignment requirements to get full credit for your work.

  Feature one, add a new site.   The user will be prompted to enter in the information for a new vacation site (assuming that there is actually a free space in the list).  As mentioned above, to get credit for this feature your program must check that the vacation type and rating are valid values.  There are two different ways to implement this feature: adding the new site to the end of the list, adding the site in it's proper location in the list.  Of course you will of course only receive credit for implementing one of the two approaches.
     
  1. Add the new site to the end of the list (worth 1 letter step).  Your program will insert the new site in the first empty spot at the end of the list.
  2. Add the new site in the proper order (worth 2 letter steps).   Your program will insert the new site it's proper alphabetical order according to the name of the site (ignoring case).  This may require existing elements to be shifted 'down' the list if the insertion point is not at the end of the list.
       
  Note: For the three features listed below your program must first check if the list is empty.   If the list is empty then an appropriate status message should be displayed to the user (e.g., "Unable to remove site: List is empty") and it should only invoke the appropriate feature if the list is not empty.  In the cases where the user enters the name of the site, the search should be performed by performing case insensitive comparisons (e.g., 'Calgary' and 'CALGARY' should show as a match).
   
  Feature two, modify a site.   (Worth 1 letter step) Your program will prompt the user to enter in the name of the site to be modified.  If the site was found in the list then the user will be prompted, a field at a time, to enter in the new information for each field.  An appropriate status message should be displayed if the site is not in the list (e.g., "Unable to modify 'Calgary': This site is not in the list").
       
  Feature three, remove a site.   Similar to feature #1, there are two different ways of implementing this feature, you will only receive credit for implementing one of the approaches.
     
  1. Remove the last site in the list (worth 1 letter step).
  2. Prompt the user for the name of site to be remove (worth 2 letter steps).  Your program will then search the list: i) if the site could not be found in the list then an appropriate status message should be displayed (e.g., "Cannot remove 'Edmonton': Site was not found in the list") ii) remove the site from the list, and if necessary, shift existing elements 'up' the list (if the site to be removed is not at the end of the list).
       
  Feature four, search for a site.   (Worth 1 letter step)  Your program will prompt the user to enter the name of the site to search for and it will either: i) display all the details of the site if the search was successful  ii) display an appropriate status message if the search failed.

 

Grades for non-functional assignments

D level assignment

The student has invested considerable work in the assignment1 and the code compiles but it doesn't fulfill any of the above requirements.

D- level assignment

The student has invested considerable work in the assignment1 but it doesn't compile.

 

Other submission requirements

In addition to having fulfill the generic assignment requirements the requirements specific to this assignment include:

  1. Good coding style and documentation:  They will play a role in determining your final grade for this assignment.  Your grade can be reduced by a letter step or more (e.g., 'A' to 'A-' for poor programming style such as employing poor naming conventions for identifiers, insufficient documentation or the use of static variables or methods).  For additional details see the marking guide for coding style.

  2. Include a README file in your submission:  For this assignment your README file must indicate what grade level has been completed (e.g., 'A') and which features have been implemented This will allow your marker to quickly determine what he or she must look for and speed up the marking process.  Also you should include your contact information: your name, university identification number and UNIX login name so that your marker knows whose assignment that he or she is marking.  Omitting the necessary information from this file will result in the loss of a letter 'step' (assuming that the marker can actually figure out who the assignment belongs to, if it cannot be determined who the assignment belongs to then no grade will be given for the assignment, an 'F' will be assigned).

  3. Assignments (source code/'dot-java' files and the README file) must be electronically submitted via submit.  In addition a paper print out of the source code and README must be handed into the assignment drop box (located on the second floor of the Math Sciences building) for the tutorial that you are registered in.  Electronically submitting the assignment allows your marker to run the code in order to quickly determine what features were implemented.  Providing a paper printout makes it easier for your marker to read and flip through your source code.  Omitting the paper version of the source code file will result in the loss of a letter 'step'.  Omitting the electronic version of your assignment will only allow you to receive a maximum grade of 'D-' because it's too time consuming for your marker to check every program with a hand trace.  I suggest that as you complete the various features of the assignment that you immediately submit each version so if you forget to submit the final version you will at least have something that your marker can grade because you won't be allowed to submit anything after the deadline.

  4. As a reminder, you are not allowed to work in groups for this class.   Copying the work of another student will be regarded as academic misconduct (cheating).  For additional details about what is and is not okay for this class please refer to the following link.

 

Relevant Files

You can run the sample byte code file called 'Vacation.class' which can be found in Unix in the directory: /home/233/assignments/assignment3

1  What does and doesn't constitute a sufficient amount of time and effort?  It's a judgment call on the part of your marker.  More often than not if you put in a reasonable amount of effort into your assignment and for some reason you just couldn't get it to work then you will receive some credit for your work.   An example of when you wouldn't receive credit is when you simply handed someone else's work.  This latter case assumes that you properly cited the other person's work, if you didn't cite your source and tried to claim that it was your own work then it would be an example of academic misconduct (cheating).