Project 1 — UMBC 4.0 Parking Garages
Assigned | Wednesday, February 15th |
---|---|
Program Due | Wednesday, February 29th by 9:00am |
Weight | 6% |
Updates |
Objectives
To gain experience:
- Implementing and using classes
- Separating an OO program’s user interface code from its application code
- Performing console input/output in Java
- Documenting classes
- Documenting methods
Project Policy
This project is considered an OPEN project. Please review the Project Policies on the Projects page before beginning your project.
Project Analysis
Once this project is turned in, the code will be reviewed in class as noted on the schedule as “Project 1 Analysis.” If you would like to volunteer your code to be reviewed in class as part of the analysis, please contact your instructor. Your name will be held in strict confidence. This practice has worked extremely well in the past. It is a wonderful way to compare and contrast the different designs that people have used. And think about it -- you get personel (yet anonymous) feedback on your project by your instructor!
Project Overview and Design
UMBC has decided to build three single-car parking garages next to the ITE building. The garages will be available for use by computer science majors who maintain a 4.0 GPA. Of course, there are certainly more than three CS majors with 4.0 GPAs at any given time. But times are tough. So, the garages are first-come, first-served every day.
The design of your first project will contain exactly two classes. One class will be a Garage class, which will contain the attributes and operations (e.g. open the door) for a single-car garage. The other class will be a user interface (UI) class called Project1 that contains the main() method from which the program begins execution. The Project1 class will also be used to perform user input/output and to invoke the appropriate methods of the Garage class. The program will be driven by a simple text-based menu with one-character menu options.
Project Specification
A parking garage will be able to be in one of six states at any given time. Those states are:
- The door is closed and the garage is empty.
- The door is closed and the garage has a car in it.
- The door is open and the garage is empty.
- The door is open and the garage has a car in it.
- The garage is not working because the door is broken (the door was closed when someone tried to either pull in or pull out).
- The garage is not working because there was an accident (someone tried to pull in when the door was open, but another car was in the garage).
Note that when either a garage's door is broken or there has been an accident in the garage, the garage is rendered non-functional. That is, it cannot be used (i.e. the user should be informed if they attempt to perform an action, such as open the door, on a non-functioning garage). Also, these are the only two types of malfunctions that can occur.
When your program starts, it will assume that all three garage doors are operating properly, but closed, and that all garages are empty.
Next, the following menu must be displayed.
O - Open door C - Close door P - Pull car in B - Back car out F - Find an empty space D - Display space state E - Exit the program
Further explanation of these options is as follows.
- Open door — Ask the user which garage door (1, 2, or 3) to open. Open the door if it is possible to do so.
- Close door — Ask the user which garage door (1, 2, or 3) to close. Close the door if it is possible to do so.
- Pull car in — Ask the user which garage (1, 2, or 3) to pull the car in to. Pull the car into the garage if it is possible to do so.
- Back car out — Ask the user which garage (1, 2, or 3) to back the car out of. Back the car out of the garage if it is possible to do so.
- Find an empty space — The program finds the first empty garage, beginning with space 1, if there is one. If there are no empty garages, the user is kindly told to park elsewhere.
- Display garage state — Ask the user which garage’s state (1, 2, or 3) to display, then display its state. A garage’s state consists of: if the door is open or closed, if the garage is occupied or empty, if the garage door is broken, if there has been an accident in the garage. Display each piece of data on a separate line. Make sure to state which garage’s state you are displaying and give each piece of state data an appropriate label.
- Exit the program — Display the state of all three garages, from 1 to 3, then exit the program.
Note that, where relevant, the garage on which to perform an action (1, 2, or 3) must be specified before any other needed inputs. In general, be sure to perform the tasks listed for each command in the exact order specified above and prompt for the input needed in the exact order specified above. Not doing so may result in the grading script not being able to handle your program, resulting in a lowered grade.
Project Hints, Notes, Requirements, Restrictions
-
The package name for this project must be
proj1
. -
The user interface class (that contains main()) must be called
Project1
. The garage class must be calledGarage
. - You may use an array object to hold the garages, but it is not required. However, you may not use any of the API container classes, such as ArrayList. That will be allowed later in the semester.
-
In keeping with the principle of separation of user interface and
applications code, the
Garage
class should not perform any user input or output. All user input/output should be performed byProject1
's main() or one of main’s helper methods. -
Be sure that you follow the OOP principle of encapsulation. Don’t use
accessors and mutators to write procedural code in main(); call appropriate
Garage
methods instead. Remember, we want to provide the “minimal public interface.” - You must comment using Javadoc formatting for both method and class headers.
-
All methods of the
Project1
andGarage
classes must have appropriate method header comments, including pre- and post-conditions, as shown in the course coding standards and discussed in class. Make sure that your Project 1 code does not violate any Garage method preconditions. If it does, the Garage method should throw a RuntimeException exception with an appropriate message (we will discuss this in class). -
Both the
Project1
andGarage
classes should have file header comments, but you may omit the Class Invariant portion (for now). -
Use the
Scanner
class for user input as discussed in lab. Be sure to create only oneScanner
object, which should be an instance variable in theProject1
class. If you do not follow this procedure, it is possible that the automated grading script will not work with your program (and that’s not good!). -
Since main() is by definition a static method, any constants,
instance variables, and helper methods that are also defined within the
Project1
class and used by main() should be defined asprivate static
. (We'll talk about how to get around this later in the semester.) -
Generally speaking, each main menu selection corresponds to a method of
the
Garage
class. -
Input Guarantees and Error Handling:
- All user input is guaranteed to be of the correct type, but not necessarily a valid value.
- Menu selections are guaranteed to be entered as a single character, but may be either upper- or lower-case. In the case of an invalid menu selection, display an informative error message to the user and redisplay the menu.
- In the case of the selection of a garage (1, 2, or 3), if the user enters other than these values, display an appropriate error message and reprompt the user for the garage number.
- For all other errors (e.g. attempting to open a broken garage door), display an appropriate error message and return the user to the main menu.
- Be informative. When your program performs an action, it should tell the user whether or not the action (say what it is) is successful or not. Also, tell the user on which garage the operation has been attempted (e.g. "Garage 1 has a broken door and cannot be opened."). Remember, the user should never be puzzled as to what is currently happening with the program.
Grading
See the course website for a description of how your project will be graded.
Project Compilation and Submission
Before submitting your project, be sure to compile and test your code on the GL system. See the compiling and executing on the GL system link on the course Projects page for details on how to compile and execute your project on GL.
See the Submitting your project for grading link on the Projects page for detailed instructions on how to submit your project.
You may resubmit your files as often as you like, but only the last submittal will be graded and will be used to determine if your project is late. For more information, see the Projects page on the course web site.
Remember — if you make any change to your program, no matter how insignificant it may seem, you should recompile and retest your program before submitting it. Even the smallest typo can cause errors and a reduction in your grade.