Aims:
-
Practice how to apply a systematic object-oriented design process
-
Gain experience in implementing an object-oriented program with multiple interacting classes
-
Learn more about the Java class libraries
Due Date: Week 6, Friday, April 7, 11:59 p.m.
Value: 10%
Assessment will be based on the design of your program in addition to correctness. You should submit at least a UML class diagram used for the design of your program, i.e. not generated from code afterwards.
All input will be a sequence of lines of the following form, where, in addition, a comment (starting with a '#' character) can appear at the end of a line. Your program should be able to process and discard such comments (this includes whole lines that consist only of a comment).
Location <depot> <name> <type>
# specify that <depot> has a campervan with <name> that has transmission <type>
Request <id> <hour1> <month1> <date1> <hour2> <month2> <date2> <num1> <type1> [<num2> <type2>]
# booking request <id> is from <hour1> <month1> <date1> to <hour2> <month2> <date2> for <num1> vehicles of type <type1>, etc.
Change <id> <hour1> <month1> <date1> <hour2> <month2> <date2> <num1> <type1> [<num2> <type2>]
# change booking <id> to be from <hour1> <month1> <date1> to <hour2> <month2> <date2> with <num1> vehicles of type <type1>, etc.
Cancel <id>
# cancel booking <id> (if it exists) and free up vehicles
Print <depot>
# print record of all vehicles in <depot>
All campervans will be declared before any commands are issued. To remove any ambiguity, booking requests and changes are fulfilled as follows: depots are checked (in order in which they appear in the input file), and within each depot, vehicles are checked (again in order of definition in the input file) to determine whether the vehicle is available for the period of time requested, and if so, that vehicle is assigned to the booking. Note that the vehicles for each depot are declared in a block (see sample input), and vehicles from multiple depots may be used to fulfil a request. Campervans have a unique name, and there must be at least 1 hour between bookings of the same campervan for a booking to be made. The output for a booking or change should list the vehicles assigned to the booking in order of the declarations at the start of the input file (see examples below). Each booking and change request can ask for vehicles of a given type only once (e.g. does not include two separate numbers of Automatic cars). For printing, output the bookings of all vehicles at the specified depot in order of vehicle declaration, then date (with times in the hour:minute form HH:MM, months in three letter format and dates as two digits), with one booking per line.
Create all your Java source files in the default package. Call your main Java file VanRentalSystem.java. Read input from a file whose name is passed as an argument to the main method in the call to java VanRentalSystem and print output to System.out. For machine marking, the output will be redirected to a text file that will be compared to the expected output (so do not print out extra spaces, etc.) and remember to close the input file. For simplicity, each depot name will be just one word. You can assume that booking ids are unique. Print out months in the standard three letter format, and use the 24 hour time clock for hours. If a booking request cannot be fulfilled, print out Booking rejected, for a change that cannot be made, Change rejected, and for a cancellation that cannot be done, Cancel rejected.
To read input from a text file (whose name should be passed as a command line argument to java, e.g. java VanRentalSystem input.txt), use code such as:
Scanner sc = null;
try
{
sc = new Scanner(new FileReader(args[0])); # args[0] is the first command line argument
}
catch (FileNotFoundException e) {}
finally
{
if (sc != null) sc.close();
}
Sample Input
Below is an example of the input form and meaning. Note that you will have to submit at least three input test files with your assignment. These test files should include one or more comments to specify what scenario is being tested (see Requests 1 and 2 for illustration). However, the following sample input includes many comments added only to explain the input format; your input test files do not need to contain this many comments.
Location CBD Wicked Automatic # Location CBD has Wicked campervan with automatic transmission
Location CBD Zeppelin Automatic # Location CBD has Zeppelin campervan with automatic transmission
Location CBD Floyd Automatic # Location CBD has Floyd campervan with automatic transmission
Location Penrith Queen Manual # Location Penrith has Queen campervan with manual transmission
Location Cremorne Ramones Automatic # Location Cremorne has Ramones campervan with automatic transmission
Location Cremorne Nirvana Automatic # Location Cremorne has Nirvana campervan with automatic transmission
Location Sutherland Purple Manual # Location Sutherland has Purple campervan with manual transmission
Location Sutherland Hendrix Manual # Location Sutherland has Hendrix campervan with manual transmission
Location Sutherland Eagle Manual # Location Sutherland has Eagle campervan with manual transmission
Test whether campervans can be rented from different depots when one depot exhausts its allocation of vehicles
Request 1 23 Mar 25 12 Mar 26 3 Automatic 1 Manual
# Request 1 is
for 3 Automatic and 1 Manual campervan from 23:00 on Mar 25 to 12:00 on Mar 26
# Assign Wicked, Zeppelin, Floyd of CBD and Queen of Penrith
# Output Booking 1 CBD Wicked, Zeppelin, Floyd; Penrith Queen
Test whether vans already booked are skipped and the next available van in order of declaration is assigned to booking
Request 2 12 Mar 24 15 Mar 27 1 Manual
# Request 2 is for
1 Manual campervan from 12:00 on Mar 24 to 15:00 on Mar 27
# Assign Purple of Sutherland since Queen of Penrith is booked
# Output Booking 2 Sutherland Purple
Request 3 13 Mar 26 21 Mar 26 2 Automatic 2 Manual
# Request 3 is for
2 Automatic and 2 Manual vans from 13:00 on Mar 26 to 21:00 on Mar 26
# Assign Wicked and Zeppelin of CBD,
Queen of Penrith and Hendrix of Sutherland
# Output Booking 3 CBD Wicked, Zeppelin; Penrith Queen; Sutherland Hendrix
Change 1 23 Mar 27 23 Mar 29 3 Manual 2 Automatic
# Change booking 1 to
3 Manual and 2 Automatic vans from 23:00 on Mar 27 to 23:00 on Mar 29
# Deassign Wicked, Zeppelin, Floyd of CBD and Queen of Penrith, and assign Queen of Penrith,
# Purple and Hendrix of Sutherland and Wicked and Zeppelin of CBD
# Output Change 1 CBD Wicked, Zeppelin; Penrith Queen; Sutherland Purple, Hendrix
Request 4 11 Mar 25 09 Mar 26 1 Automatic
# Request 4 is for
1 Automatic campervan from 11:00 on Mar 25 to 9:00 on Mar 26
# Assign Wicked of CBD
# Output Booking 4 CBD Wicked
Cancel 3
# Cancel booking 3
# Deassign Wicked and Zeppelin of CBD, Queen of Penrith and Hendrix of Sutherland
# Output Cancel 3
Request 5 11 Mar 26 09 Mar 27 4 Manual
# Request 5 is for
4 Manual campervans from 11:00 on Mar 26 to 9:00 on Mar 27
# Request cannot be fulfilled
# Output Booking rejected
Print CBD
# Print out bookings of all campervans at CBD,
in order of campervan declarations, then date/time;
# for each booking
giving the start and end time and date in the format described above
Sample Output
The output corresponding to the above input is as follows:
Booking 1 CBD Wicked, Zeppelin, Floyd; Penrith Queen
Booking 2 Sutherland Purple
Booking 3 CBD Wicked, Zeppelin; Penrith Queen; Sutherland Hendrix
Change 1 CBD Wicked, Zeppelin; Penrith Queen; Sutherland Purple, Hendrix
Booking 4 CBD Wicked
Cancel 3
Booking rejected
CBD Wicked 11:00 Mar 25 09:00 Mar 26
CBD Wicked 23:00 Mar 27 23:00 Mar 29
CBD Zeppelin 23:00 Mar 27 23:00 Mar 29
- Submit one .zip
file using the following command:
- Your .zip file should contain at the top level, i.e. not within a directory when unzipped (see below for more specific instructions):
- All your .java source files (there is no need to include .class files: your Java files will be recompiled on the CSE machine)
- A .pdf file containing your design documents (a UML class diagram and, optionally, other diagrams necessary to understand your design)
- A series of .txt files (at least three) that you have used as input files to test your system (each including comments to indicate the scenarios tested), and the corresponding .txt output files (call these input1.txt, output1.txt, input2.txt, output2.txt, etc.)
-
When your file is submitted, a test will be done to ensure that your Java files compile on the CSE machine (take note of any error messages printed out)
-
Check that your submission has been received using the command:
-
To create your zip file:
Create and open the folder containing all the files, e.g. ass1
Select all the files in that folder that you want to submit (e.g. all files or just the Java files and the pdf and txt files)
Right click and select Send to -> Compressed (zipped) folder
This will create a zip file in the current directory
Double clicking on this file should give you the same list of files you selected, and there should not be a directory called ass1
Unix:
cd into the folder containing all the files, e.g. ass1
Type zip -r ~/ass1.zip *
This will create a file called ass1.zip in your home directory (you don't have to create this in the home directory of course)
Check the contents of this file by typing unzip -l ~/ass1.zip
You should see the list of files in the ass1 directory, and these files should not be contained in a directory called ass1
-
Correctness (automarked): 60%
-
Design and programming style: 40%
-
Correctness: Assessed on standard input tests, using calls of the form:
-
Design: Adherence to object-oriented design principles, clarity of UML diagrams and conformance of UML diagrams to code
-
Programming style: Adherence to standard Java programming style, understandable class and variable names, adequate Javadoc and comments