Department of Computer Science and Information Technology La Trobe University
CSE1OOF/4OOF Semester 1, 2015 Assignment Part C
Due Date: Monday, 11th May 2015, at 10.00 a.m.
First and Final date for SUBMISSION Monday 11th May 2015 at 10.00 am
Delays caused by computer downtime cannot be accepted as a valid reason for a late submission without penalty. Students must plan their work to allow for both scheduled and unscheduled downtime. There are no days late or extensions on this assignment as execution test marking will begin on Tuesday 12th May in your normal lab (Week 10)
This is an individual assignment. You are not permitted to work as a group when writing this assignment.
Copying, Plagiarism: Plagiarism is the submission of somebody elses work in a manner that gives the impression that the work is your own. The Department of Computer Science and Information Technology treats academic misconduct seriously. When it is detected, penalties are strictly imposed. Refer to the unit guide for further information and strategies you can use to avoid a charge of academic misconduct. All submissions will be electronically checked for plagiarism.
Assessment Objectives:
- to design programs that conform to given specifications
- to practise combining multiple classes and methods into a whole program
- to implement programs in Java.
Submission Details: Full instructions on how to submit electronic copies of your source code files from your latcs8 account are given at the end. If you have not been able to complete a program that compiles and executes containing all functionality, then you should submit a program that compiles and executes with as much functionality as you have completed. (You may comment out code that does not compile.)
Note you must submit electronic copies of your source code files using the submit command on latcs8. Ensure you submit all required files, one file at a time. For example, the file Module.java would be submitted with the command:
>submitOOFModule.java
PLEASE NOTE: While you are free to develop the code for this progress check on any operating system, your solution must run on the latcs8 system.
Marking Scheme: This assignment is worth 5% of your final mark in this subject. Implementation (Execution of code) 90%, explanation of code 10%
You may be required to attend a viva voce (verbal) assessment (to be used as a weighting factor on the final mark).
Do NOT use the LMS to submit your files, use latcs8 only |
OOF Assignment Part C due: 10:00 am Mon 11th May this is the first and final hand in date Page 1 of 13
Return of Mark sheets:
The face to face execution test marking in the lab (Week 10) constitutes a return of the assignment mark, subject to the conditions on page 10.
Please note carefully:
The submit server will close at 10:00 am on Monday May 11th
After the submit server has closed, NO assignments can be accepted.
Please make sure that you have submitted all your assignment files before the submit server closes. (see page 10)
There can be NO extensions or exceptions.
Your assignment will be marked in your normal lab, starting week 10, Tuesday May 12th 2015.
You must attend your normal lab to have your assignment marked. Non-attendance will result in your assignment being awarded 0. You may come to any lab (if you cant make your normal lab).
If you cannot attend any of the labs please email me ([email protected]) to arrange another time.
Marking scheme:
90% for the code executing correctly
10%, you will be asked to explain (and / or alter) parts of your code.
Any code that is submitted that is not part of the OOF syllabus will have to be explained thoroughly. Failure to do so will result in a major loss of marks for this assignment. I got it off the web is NOT an acceptable reason for not being able to explain code outside of the OOF syllabus.
OOF Assignment Part C due: 10:00 am Mon 11th May this is the first and final hand in date Page 2 of 13
Problem Background
As human kind expands into space, there is a requirement for building cities in space.
Initially, these space cities are to be built up from components known as Modules. Modules come in all different sizes and purposes, but they are engineered so that they all fit together.
Modules, and the city as a whole, requires power. This power comes from solar panels attached to the Modules. Solar panels are a standard 12 metres wide. In order that the Space City has orbital stability, solar panels are only attached to 2, opposite, sides of Modules. Whilst Modules have a length, width and height, it is the length of the Module that provides the reference for determining how many solar panels an individual Module can accommodate.
The two sides of the Module to which solar panels are attached are known as the A and B sides. The first panel (if it can be fitted) is attached to side A, the second panel to side B, the third panel (again, if it can be fitted) is attached to side A and so on.
Given that the length of the Module determines the number of solar panels, for each Module, it is easy to calculate the maximum number of solar panels that can be attached to a particular Module.
Each solar panel generates 4.78 units of power.
Each Module has a unique identification, known as an ident. This always begins with an uppercase character, which must be one of A, C, E, F, I, P or S, any other starting character is invalid and should be rejected.
There may be any number of digits after this initial character.
The first character of the ident also determines the type of the Module, as follows: .
A corresponds to Admin
C corresponds to Crew Quarters
E corresponds to Engineering
F corresponds to Food
I corresponds to Computers and Information Technology P corresponds to Flight Deck
S corresponds to Science
As this is the very early development of Space Cities, each Module can have at most one Crew Member.
A Crew Member has a name and an id. The name is text and may consist of more than one word. The id is also a String.
It should be possible to change the id of a Crew Member, but not the Crew Members name.
Further, as this is very early in the development phase of Space Cities, there will only be 2 Modules connected together. The 2 Modules can be of different types or the same type.
OOF Assignment Part C due: 10:00 am Mon 11th May this is the first and final hand in date Page 3 of 13
Program Requirements
You have been asked to write an interactive program, in Java, to aid in construction and maintenance of a Space City.
To aid in the rapid development of this program, 4 Java files and 2 input files are provided for you:
SpaceCity.java, Util.java, CrewMember.java, Module.java and the sample input files mod01.dat and mod02.dat
Copy them from the unit library area into your current directory using:
cp /home/1st/csilib/cse1oof/assignC/* .
Task 1
Design and implement the CrewMember class (by completing CrewMember.java) so that we can create and use a CrewMember object.
All CrewMember objects have the following attributes: name (a string, can be more than one word)
id ( a string)
The CrewMember class requires a constructor that has a parameter for each of the 2 attributes of the class. The CrewMember class also requires a copy constructor (lectures Fri Apr 24) The CrewMember class also requires get methods (accessor) for each of the attributes and a single set method (mutator) to change the value of the id attribute. Provide a toString() method.
Task 2
Design and implement the Module class (by completing Module.java) so that we can create and use a Module object.
All Module objects have the following attributes:
length (an int)
height (an int)
width (an int )
number of panels on side A (an int) number of panels on side B (an int) maximum number of panels (an int) ident ( a string)
type (a string, can be more than one word)
crewMember (an object reference to a CrewMember object)
The Module class requires a constructor that takes just the attributes, length, height, width and ident. This constructor is for constructing a Module object with keyboard input.
These 4 attributes are the only ones required with keyboard input, all other attributes can either be derived or are set to their default values. The maximum number of panels will be set by
OOF Assignment Part C due: 10:00 am Mon 11th May this is the first and final hand in date Page 4 of 13
calling a method in the Util utility class. The Util class is Task 3. Similarly, the type will be set by calling the appropriate method in the Util utility class. This is so because we have to construct a Module object first to be able to later add values to the object like a CrewMember or solar panels.
The Module class also requires an overloaded constructor that takes all of the attributes of the Module class. This constructor will be used to create a Module object when we read the inputs
from a text file. When we read from a text file, the values of all the attributes will be known, we need to copy them from the file into the appropriate attributes of the object. This constructor must have a way of passing in the details of a Crew Member, if those details are in the text file.
Note: when reading the information from the text file, there may not be a Crew Member associated with this particular Module object, be careful to only attempt to construct a CrewMember object if there is a name and id, otherwise leave the value of crewMember as null.
The Module class will require a number of accessor methods. Which ones are up to you to decide. The Module class must have a method that allows the class to add a solar panel.
First the appropriate method in the Util utility class should be called to check whether or not this Module can actually add a solar panel. If this Module can add a solar panel, then the method determines whether the solar panel is added to the A or B side of the Module and the appropriate attribute is incremented by 1.
The Module must also be able to add a CrewMember object. This method may make use of the appropriate method in the Util class to first check if a CrewMember can be added (recall that there is only one CrewMember object per Module). If a CerwMember object can be added then the values for the name and id come from the main driver class (SpaceCity.java)
As one of the accessor methods of the Module class, you need to design a method that will return information about the CrewMember object. Based on the lectures on Apr 24, write this method so that there is no privacy leak. Hint: this is where the copy constructor for the CrewMember class could be used.
Finally provide a toString( ) method for the Module class.
Note: the Module class does not take keyboard input inside the class.
Task 3
Util.java is a utility class that contains all the constants and the skeletons of static (or class) methods that do all the calculations needed to update the state of a module. Read the comments before each static method explaining what the method does and implement each method. Note: It must not be possible to create a Util object in the main driver class.
OOF Assignment Part C due: 10:00 am Mon 11th May this is the first and final hand in date Page 5 of 13
Task 4
The driver program, SpaceCity.java already contains some implementation, in particular the menus and some Module object references. Recall that there are only 2 Module objects in this stage of the driver program.
The driver program, SpaceCity.java, starts by presenting the user with a menu, as follows: Space City Main Menu
1. Add Module from file2. Add Module from keyboard3. Display Modules4. Add Panel5. Add Crew6. Close Space City program
Enter choice >>
Implement the functionality of each method as follows (assume user input is correct):
1. Add Module from file
This method reads information about a Module from a text file, if there is an unused Module object reference. That is, a Module object reference that is to null. Re-call that you have to check whether or not there is a CrewMember in this Module.
Provided that there is an available Module object reference, then the method first prompts (asks) the user for an input file name. Assume the text file exists, is correctly formatted and contains information on just one Module object (with or without associated CrewMember information).
If there are no available Module object references, then this method displays an appropriate message and returns to the main menu.
If the first Module object reference is available, then a Module object is created with the information from the text file and the address of this object is stored in the first Module object reference.
If the second Module object reference is the one that is available then the address of newly created Module object is stored in this Module object reference.
Modules that do not have a CrewMember consist of 9 lines, Modules that do have a CrewMember consist of 11 lines.
OOF Assignment Part C due: 10:00 am Mon 11th May this is the first and final hand in date Page 6 of 13
Information on a Module without a CrewMember as follows (and is known as a record):
length of the Module |
an integer |
height of the Module |
an integer |
width of the Module |
an integer |
ident of the Module |
text |
type of the Module |
text, can be more than one word |
number of solar panels on side A |
an integer |
number of solar panels on side A |
an integer |
maximum number of solar panels on Module |
an integer |
has a CrewMember, or not |
a boolean |
Information on a Module with a CrewMember as follows (and is known as a record):
length of the Module |
an integer |
height of the Module |
an integer |
width of the Module |
an integer |
ident of the Module |
text |
type of the Module |
text, can be more than one word |
number of solar panels on side A |
an integer |
number of solar panels on side A |
an integer |
maximum number of solar panels on Module |
an integer |
has a CrewMember, or not |
a boolean |
name of the CrewMember |
text, can be more than one word |
id of the CrewMember |
text |
An example of a text file without a CrewMember is shown below:
241023C34Crew Quarters1
1
4 false
An example of a text file with a CrewMember is now shown below:
361528P0001Flight Deck3
26trueChief Pilot StariusP1-01
OOF Assignment Part C due: 10:00 am Mon 11th May this is the first and final hand in date
Page 7 of 13
Your program must work with any file in the correct format, it is NOT necessary to check for empty files.
2. Add Module from keyboard
This method is chosen when the user wants to create a new Module object from details entered at the keyboard (rather than read from a file). Use meaningful prompts to ask the user to enter, from the keyboard, all 4 pieces of data needed, and create a new Module object. Reminder, the 4 pieces of information are the length, height, width and ident of the Module.
As with Add Module from a file, this method must check that there is an available Module object reference before asking the user to enter the 4 pieces of information. If there are no Module object references available, then this method should display an appropriate message and return to the main menu.
Also, as with Add Module from a file, the address of the newly created Module object is stored in the first Module if that Module object reference is available, else it is stored in the second Module object reference.
3. Display Modules
This method displays all the information about the Modules in the Space City, including the details of any CrewMembers, if present. If there are no Modules in the Space City then an appropriate message is displayed.
If there are solar panels on a Module, then the total power output of that Module must be shown.
4. Add Panel
This method prompts the user for the ident of a Module or displays an appropriate message
to the screen if there are no Module objects available.
If there are Module object(s) available and one of the Module objects matches the ident entered by the user, then a solar panel is added to the appropriate side of that Module, provided, of course, that that Module has not already reached its maximum number of solar panels.
Recall that a solar panel is 12 metres wide so there must be sufficient space on the length of the Module to fit the solar panel. Call the appropriate method from the Util class to check that the solar panel can actually be added.
5. Add Crew
This method prompts the user for the ident of a Module or displays an appropriate message
to the screen if there are no Module objects available.
If there are Module object(s) available and one of the Module objects matches the ident entered by the user and that Module object does not already have a CrewMember, then the method prompts the user for the details of a CrewMember. The CrewMember object is constructed and the address is stored in the crewMember object reference.
OOF Assignment Part C due: 10:00 am Mon 11th May this is the first and final hand in date Page 8 of 13
If a CrewMember object cannot be constructed, every effort should be made to display to the screen the appropriate reason why crew cannot be added to that Module.
6. Close Space City program
Selecting this menu choice closes the program, closing any open files (there should be none open).
Electronic Submission of the Source Code
- Submit all the Java files that you have developed in the tasks above.
- The code has to run under Unix on the latcs8 machine.
- You submit your files from your latcs8 account. Make sure you are in the same directory as the files
you are submitting. Submit each file separately using the submit command.
submit OOF Module.javasubmit OOF Util.javasubmit OOF CrewMember.javasubmit OOF SpaceCity.java
After submitting the files, you can run the following command that lists the files submitted from your account:
verify
You can submit the same filename as many times as you like before the assignment deadline; the previously submitted copy will be replaced by the latest one.
Please make sure that you have read page 2 about the submission close off date and time and the compulsory requirement to attend the execution test in Week 10 (May 12 2015) and the requirement to thoroughly explain any code that is outside of the OOF syllabus.
Failure to do any of these things will result in your assignment be awarded a mark of 0, regardless of the correctness of the program.
Execution test marks are provisional and subject to final plagiarism checks and checks on the compliance of your code to this assignment document.
As such final assignment marks may be lower or withdrawn completely.
Example run of the program (note: not every condition is shown in the examples)
user input in bold
> java SpaceCitySpace City Main Menu
1. Add Module from file2. Add Module from keyboard3. Display Modules4. Add Panel5. Add Crew6. Close Space City program
Enter choice >> 3 No modules to display
OOF Assignment Part C due: 10:00 am Mon 11th May this is the first and final hand in date
Page 9 of 13
Space City Main Menu
1. Add Module from file2. Add Module from keyboard3. Display Modules4. Add Panel5. Add Crew6. Close Space City program
Enter choice >> 4
No modules, cannot add panel
Space City Main Menu
1. Add Module from file2. Add Module from keyboard3. Display Modules4. Add Panel5. Add Crew6. Close Space City program
Enter choice >> 1
Enter filename >> mod01.dat
Space City Main Menu
1. Add Module from file2. Add Module from keyboard3. Display Modules4. Add Panel5. Add Crew6. Close Space City program
Enter choice >> 3
Module 1
Module [ id : C34 type : Crew Quarters
length : 24 width : 23 height : 10 panels A side : 1 panels B side 1 max number of panels : 4
power output : 9.56
No crew in this Module ]
Space City Main Menu
1. Add Module from file2. Add Module from keyboard3. Display Modules4. Add Panel5. Add Crew6. Close Space City program
Enter choice >> 2 Enter length >> 44 Enter height >> 10 Enter width >> 23 Enter ident >> P00001
OOF Assignment Part C due: 10:00 am Mon 11th May this is the first and final hand in date
Page 10 of 13
Space City Main Menu
1. Add Module from file2. Add Module from keyboard3. Display Modules4. Add Panel5. Add Crew6. Close Space City program
Enter choice >> 3
Module 1
Module [ id : C34 type : Crew Quarters
length : 24 width : 23 height : 10 panels A side : 1 panels B side 1 max number of panels : 4
power output : 9.56
No crew in this Module ]
Module 2
Module [ id : P00001 type : Flight Deck
length : 44 width : 23 height : 10 panels A side : 0 panels B side 0 max number of panels : 6
power output : 0.0
No crew in this Module ]
Space City Main Menu
1. Add Module from file2. Add Module from keyboard3. Display Modules4. Add Panel5. Add Crew6. Close Space City program
Enter choice >> 4 Enter Module ident >> C34 Panel added to Module 1
Space City Main Menu
1. Add Module from file2. Add Module from keyboard3. Display Modules4. Add Panel5. Add Crew6. Close Space City program
Enter choice >> 3
Module 1
Module [ id : C34 type : Crew Quarters
length : 24 width : 23 height : 10 panels A side : 2 panels B side 1 max number of panels : 4
power output : 14.34
No crew in this Module ]
Module 2
Module [ id : P00001 type : Flight Deck
OOF Assignment Part C due: 10:00 am Mon 11th May this is the first and final hand in date
Page 11 of 13
length : 44 width : 23 height : 10 panels A side : 0 panels B side 0 max number of panels : 6
power output : 0.0
No crew in this Module ]
Space City Main Menu
1. Add Module from file2. Add Module from keyboard3. Display Modules4. Add Panel5. Add Crew6. Close Space City program
Enter choice >> 5
Enter Module ident >> P00001 Enter crew name >> Luke Skywalker Enter crew id >> P34-AE
Crew member added to Module 2
Space City Main Menu
1. Add Module from file2. Add Module from keyboard3. Display Modules4. Add Panel5. Add Crew6. Close Space City program
Enter choice >> 4 Enter Module ident >> C34
Panel added to Module 1Space City Main Menu
1. Add Module from file2. Add Module from keyboard3. Display Modules4. Add Panel5. Add Crew6. Close Space City program
Enter choice >> 4
Enter Module ident >> C34
Module 1 has all possible panels
Space City Main Menu
1. Add Module from file2. Add Module from keyboard3. Display Modules4. Add Panel5. Add Crew6. Close Space City program
Enter choice >> 3
OOF Assignment Part C due: 10:00 am Mon 11th May this is the first and final hand in date
Page 12 of 13
Module 1
Module [ id : C34 type : Crew Quarters
length : 24 width : 23 height : 10 panels A side : 2 panels B side 2 max number of panels : 4
power output : 19.12
No crew in this Module ]
Module 2
Module [ id : P00001 type : Flight Deck
length : 44 width : 23 height : 10 panels A side : 0 panels B side 0 max number of panels : 6
power output : 0.0
CrewMember [ name : Luke Skywalker id : P34-AE ] ]
Space City Main Menu
1. Add Module from file2. Add Module from keyboard3. Display Modules4. Add Panel5. Add Crew6. Close Space City program
Enter choice >> 6
Space City program now closing
OOF Assignment Part C due: 10:00 am Mon 11th May this is the first and final hand in date
Page 13 of 13
Reviews
There are no reviews yet.