Programming 1 Assignment 2, 2015 Sem 2 Page 1 of 7
ITECH1000 Programming 1, Semester 2 2015
Assignment 2 – Development of a Simple Program Involving Multiple
Classes
Due Date: Week 11 - see Course Description for full details
Please see the Course Description for further information related to extensions for assignments and Special
Consideration.
Important Notes
1. Code that does not successfully compile will not be marked. In such cases, only the specification, design and
question sections of the assignment will be awarded marks. If you are unable to get sections of your code to
compile prior to handing it in, please state this clearly in your submission and comment out the offending code.
Marks will also be deducted if your code compiles but contains warnings. Please see your tutor for help if you are
unable to successfully compile your code.
2. If you use any resources apart from the course material to complete your assignment you MUST provide an in-text
citation within your documentation and/or code, as well as providing a list of references in APA formatting. This
includes the use of any websites, online forums, books or text books. If you are unsure of how to do this please
either see the online guide or ask your tutor for help.
3. You are strongly urged to keep backup files as you work on the project so that you can revert to an earlier version if
you break an aspect of the program while attempting to implement one of the later requirements.
4. If you encounter any problems in uploading files to Moodle please report this to your lecturer or other staff
member as soon as possible. It is your responsibility to check that you are submitting the correct version of your
files and the correct assignment.
5. You may be required to demonstrate and explain your working code to your tutor in your lab class.
Project Specification
Please read through the entire specification PRIOR to beginning work. The assignment should be
completed in the stages mentioned below. The objectives of this assignment are for you to:
• Write your own classes from a specification
• Instantiate objects of these classes
• Perform required tasks by creating and manipulating objects in the code of one class through the public
interfaces (methods) of the classes of the objects being manipulated.
The context for this assignment will be creating a software system to support the management of a Building,
which a number of Apartments that are for rent.
ITECH 1000/5000 Programming 1 Assignment 2 Specification Semester 2, 2015 Page 2 of 7
Resources:
The following files/links are available on Moodle:
• An electronic copy of this assignment specification sheet
• A sample program with similar features to the assignment requirements involving multiple classes
• Starter code for some of the classes which you will need to create
Design Constraints
Your program should conform to the following constraints.
• Use a while-loop when the number of iterations is not known before loop execution.
• Use a for-loop when the number of iterations is known before loop execution.
• Indent your code correctly to aid readability and use a consistent curly bracket placement scheme.
• Use white space to make your code as readable as possible.
• Validation of input should be limited to ensuring that the user has entered values that are within correct
bounds. You do not have to check that they have entered the correct data type.
• Comment your code appropriately.
Part A – Code Comprehension
A Sample program is provided. Make sure you understand this code as it will help you with your own
programming for this assignment. Using the uncommented sample code for classes provided, answer the
following questions:
1. Draw a UML diagram of the Shoe class using the code that has been provided. Complete this using the
examples that have been provide in the lecture slides.
2. Draw a UML diagram of the Store class using the code that has been provided. Complete this using the
examples that have been provide in the lecture slides.
3. Copy the code from Store.java into your report and appropriately comment the code. At a minimum, explain the
purpose of each method. For the more complex methods reading input from a file, sorting the data and
exporting data to the file, insert comments to explain the code.
4. Briefly explain the code in sortInventory. What is the inventory being sorted by? What is the sort algorithm
that is being used. Explain in words how it works. Why do you need to use two for loops?
5. Briefly explain what other sorting algorithms could have been used.
6. What method of searching for shoes has been used in the program? What other algorithm could have been
used.
7. Examine the lines to open the output file and write the outputString in the ShoeStore class:
File file = new File(“export.txt”);
System.out.println(file.getAbsolutePath());
output = new BufferedWriter(new FileWriter(file));
output.write(outputString);
Where is the output file located? Find BufferedWriter in the Java API documentation and describe the use of
this object.
8. Examine the code in the exportToFile method in the ShoeShop.java file. What is the purpose of the ‘
’ in the
toString() method that is used to produce the output string?
ITECH 1000/5000 Programming 1 Assignment 2 Specification Semester 2, 2015 Page 3 of 7
9. Explain the use of the return value (result) of the compareTo method in the Shoe class.
10. Briefly explain why the line to open the input file:
Scanner inputFile = new Scanner(new File(-C:\orders.txt-));
has two \ in the filename specification. Where is the file located? What happens if only one is used? Is there
another option that would not require these?
11. Examine the code in the saveToFile method. How could this be improved for readability of the output file?
What is the purpose of the ‘
’?
12. Briefly explain why a try and catch clause has been included in the code to read from the file. Remove this from
the code and remove the input file and take note of the error. Re-add the line and investigate what happens if
the input file is not present. Record your observations in your report.
Part B – Development of a Basic Class – Person
Your first coding task is to implement and test a class that represents an Apartment. An Apartment object
has the following attributes: number of bedrooms, number of bathrooms, the size of the apartment, the
number of living areas, an indication of whether the apartment is available for rent, the owner of the
apartment and the amount of rent per week. To complete this task, you are required to:
1. Create a new package in eclipse named assignTwoStudentNNNNN where NNNNN is your student
number. You will author a number of classes for this assignment and they will all be in this package.
2. Use the UML diagram provided to implement the class Person in a file called Person.java. Starter code
has been provided with this assignment, copy this starter code into your Apartment.java file. Complete
the constructors that will create a Person object.
a. Author all mutator and accessor (set and get) methods and the toString() as indicated in the UML
diagram.
Person
- String name;
- String address;
~ Person(name:String, address:String)
+ getName():String
+ setName (_aName:String):boolean
+ getAddress():String
+ setAddress (_anAddress:String):boolean
+ toString():String
Figure 1: Person class UML
3. Update the class TestClass.java adding in code to:
a. Create an instance of the Person class
b. Set the name and address of the instance
c. Display the details of the Person that you have created using the toString() method in the Person class.
ITECH 1000/5000 Programming 1 Assignment 2 Specification Semester 2, 2015 Page 4 of 7
Part C – Development of a Basic Class - Apartment
1. Use the UML diagram provided to implement the class Apartment in a file called Apartment.java adding
the class to your package assignTwoStudentNNNNN. Starter code has been provided with this
assignment, copy this starter code into your Apartment.java file. Complete the constructors that will
create an Apartment object.
a. Author all mutator and accessor (set and get) methods and the toString() as indicated in the UML
diagram.
b. Ensure that your Apartment class includes the following validation within the mutator (set) methods:
i. The owner of the Apartment cannot be null.
ii. The rent per week of the Apartment must be greater than zero. If an attempt is made to set the
value of the rent to an invalid value the method should return false and not change the value of
the attributes.
Apartment
- int numberOfBedrooms;
- int numberOfBathrooms;
- int numberOfLiving;
- int floorNumber;
- char apartmentLetter;
- Person owner;
- boolean available;
- double rent;
~ Apartment(numberofBedrooms:int,, numberOfBathrooms:int,
numberOfLiving:int,, owner:Person, available:boolean, rent:double)
+ getOwner():Person
+ setOwner (_aPerson:Person):boolean
+ getNumberOfBedrooms():int
+ setNumberOfBedrooms(_numBedrooms:int)
+ getNumberOfBathrooms():int
+ setNumberOfBathrooms(_numBathrooms:int)
+ getNumberOfLiving():int
+ setNumberOffLivings(_numfLiving:int)
+ getAvailable():boolean
+ setAvailable(_available:boolean)
+ getRent():float
+ setRent(_rent:double):boolean
+ toString():String
ITECH 1000/5000 Programming 1 Assignment 2 Specification Semester 2, 2015 Page 5 of 7
Figure 2: Apartment class UML Diagram
4. Update the class TestClass.java adding in code to:
a. Create an instance of the Apartment class
b. Create an instance of the Person class
c. Set all of the instance variables of the instance of the Apartment class that you have created including
the owner (using the Person created in b. above)
d. Display the details of the Apartment that you have created using the toString() method in the
Apartment class.
Part D – Development of the Building class
Using the UML diagrams provided and the information below you are required to implement and test classes
that represent a Building object. For this assignment a Building contains multiple Apartments up to a
specified capacity. (This may be modeled on the classes in the sample code. Your Building will in a similar
way contain multiple Apartments in an array.)
Building.java
Building
- name: String
- apartments: Apartment[]
- numberOfApartments: int
- capacity: int
~ Building (initName: String, capacity: int) create
+ getName():String
+ getNumberOfApartments():int
+ setName(newName: String): boolean
+ addApartment(newApartment: Apartment): boolean
+ sortApartments()
+ numberEmpty(): int
+ exportToFile() //itech5000 students only
+ readFromFile() //itech5000 students only
+ toString():String
Figure 3: UML Diagram for the class Garage
1. You have been provided with starting point in Building.java - add the provided class to your package
assignTwoStudentNNNNN.. Write get and set methods as well as an addApartment method. addApartment
should return false if an attempt is made to add an apartment after the Building has already reached its maximum
capacity.
2. Create a method for sorting the addApartment in the Building
ITECH 1000/5000 Programming 1 Assignment 2 Specification Semester 2, 2015 Page 6 of 7
3. Update the class TestClass.java adding in code to:
a. Create an instance of the Building class
b. Add at least two Apartments created to the Building class using the addApartment () method
c. Add at least two other Apartments to the Building class
d. Display the details of the Building that you have created using the toString() method in the Building class
– these should be accessed via the instance of the Building class that you have created
Part E – Using the Classes
Create a new class called Driver.java . This class is to be used to implement a basic menu system. You may
find some of the code you have already written in the TestClass.java can be copied and used with some
modification here. You may also find the menu code from assignment one helpful as an example of a menu,
although in this case you should use a switch statement to process the menu options. Each menu item
should be enacted by choosing the appropriate method on the Building object. The menu should include the
following options:
1. Populate the Building
2. Display Apartments in the Building
3. Sort Apartment data
4. Reports
5. Import data (ITECH5000 students only)
6. Export data (ITECH5000 students only
7. Exit
Further information:
• Populate the Building – this option will either allow the user to enter data for each apartment OR you
may write a populate method that will insert data hardcoded in your method directly into each
Apartment.
• Display Data – display the data of all Apartments in the Building, using your toString() method on the
Building object.
• Sort data should utilise some form of sorting algorithm to sort the Apartments into order based on
apartment number.
• Reports – design a report that would be useful for the manager of the building. As a minimum you
should display about the Apartments in the Building including:
o The number and percentage of empty apartments
o Current total rent per week (calculated for apartments that are currently being rented)
You will need to include 2 further reports in your code.
For students enrolled in ITECH5000 ONLY:
• Import data – this menu should read in data from the file called sampleData.txt. You are required to
add the additional data described above to this file.
• Export data – save the data to a new file exportData.txt
ITECH 1000/5000 Programming 1 Assignment 2 Specification Semester 2, 2015 Page 7 of 7
Assignment Submission
The following criteria will be used when marking your assignment:
• successful completion of the required tasks
• quality of code that adheres to the programming standards for the course; including:
• comments and documentation
• code layout
• meaningful variable names
You are required to provide documentation, contained in an appropriate file, which includes:
• a front page - indicating your name, a statement of what has been completed and acknowledgement of the
names of all people (including other students and people outside of the university) who have assisted you and
details on what parts of the assignment that they have assisted you with
• a table of contents and page numbers
• answers to the questions from Part A
• UML diagrams and design of your report for part Part E
• A copy of the javadocs created from your assignment code
• list of references used (APA style); please specify if none have been used
• An appendix containing copies of your code and evidence of your testing
Using the link provided in Moodle, please upload the following:
1. All of the classes created in a single zip file – SurnameStudentIdAssign2.zip
2. A copy of your report – surnameStudentIDAssign2.pdf
Marking Guide
PART A – Code Comprehension
/20
PART B – Person class + Testing
/20
PART C - Apartment class + Testing
/20
PART D - Building Class + Testing
/40
PART E – Implementation of Menu
/20
Quality of code created
/15
Presentation of documentation / report
/5
Total /20 /140
GET ANSWERS / LIVE CHAT