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

CPSC 233: Assignment 3

New concepts to be applied in this assignment

  1. Dynamic memory allocation using references and class constructors
  2. Arrays of references

Introduction

For this assignment you are to write a Java program that tracks a list of vacation sites.  The full version will perform some common list management functions such as: adding, displaying, modifying or removing sites.  

Assignment description

Each site will be described by three fields:

  1. Site name: A 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 (vacation)

1. Site name

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

2. Vacation type

This field describes the main reason for traveling to the site.  There can be four different categories of sites each one being represented by a single character code: relaxation (r), excitement (e), culture (c) or food (f). 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. When the user is prompted to enter the information for a new site he or she will be prompted to only enter a single character.  However when the information for a site is displayed it will show a full description for the vacation type.  (For example, instead of displaying 'r' the program should display something more descriptive like 'relaxation').

3. Rating

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

Class definitions.

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

  2. Menu: provides the user interface. It displays the program options and reacts to user input.

  3. Manager: Stores the list 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).

  4. Site: Tracks all the information associated with each vacation site (3 fields).

  5. Debug: This class has only a single purpose: to track (via a Boolean static attribute) 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 to be implemented

  1. Initialize: set default starting values for all the attributes of the classes.
  2. Display menu: show a menu of program options. The ability to toggle the debugging mode is a hidden feature and it shouldn't be displayed in the main menu.
  3. Show a brief introduction and signoff when the program starts and when it finishes.
  4. Display list: The list should be shown in a neat and presentable fashion (try running the executable for an example of how 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., 'Press enter to continue').  The program should only display occupied array elements and not null values.
  5. Add: The user will be prompted to enter the information for a new vacation site.  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 its proper alphabetical order (site name).  You will of course only receive credit for implementing one of the two approaches and you will get a higher mark if you implement the second approach. If the list is full then an error message should be displayed. Of course the add feature needs to be implemented before you can get credit for some of the other features so it should probably be one of the first ones that you work on after display. Your program doesn't need to check for duplicates. However it does need to make sure that the number of sites does not exceed the maximum capacity of the list and an error message should be displayed if the operation is attempted under these circumstances.
  6. Search for a site: Your program will prompt the user to enter the name of the site to search for and it will either: a) display all the details of the site if the search was successful  (all matches will be displayed in the case of duplicate entries) b) display an appropriate status message if the search failed.
  7. Modify information about a site: Your program will prompt the user to enter 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 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"). As is the case with the sample executable the user should be given the option to skip the modification process for a field and not be forced to change or re-enter the data for each field).
  8. Remove a site: Similar to feature #5 there's two ways that this feature can be implemented. One approach will yield a higher grade and you will only get credit for implementing one of the approaches. (a) Remove the last site in the list (b) Prompt the user for the name of site to be removed. (In the case of duplicates your program will remove the first match). 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.

For the last three features, 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).

Submitting your work:

  1. Assignments (source code/'dot-java' files) must be electronically submitted according to [the assignment submission requirements].  For this assignment you need to create a UML class diagram that shows: the classes implemented, their relationships as well the attributes/methods and their access permissions. Submit the class diagram along with your source code.
  2. 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].
  3. Before you submit your assignment to help make sure that you haven't missed anything here is a [checklist] of items to be used in marking.

External libraries that can be used

  1. Libraries that allow for text-based (console) input and output.

Sample executable