Assignment 1
Semester 2, 2014
Assignment Overview:
This assignment requires you to complete various tasks involving classes you write yourself. You may also use classes that you find in the SDK. The theme will be chosen by you, modelling on example code you are provided for an imaginary Car hire company system. Note that this is a conceptual modelling and programming exercise only. It is designed to test your understanding of various aspects of object oriented design using Java programming. It is not intended to be a model of what happens in the real world – so you can make assumptions that may not “make sense†in the real world.
You will be required to develop your application using Java in the Eclipse environment. You will need to zip the whole project up when you are finished and submit it on Moodle by the due date. You will also need to submit a report (both electronically in Moodle and as a hard copy). The report will require some written and diagrammatic information describing your system as well as answers to questions which will be outlined in the various tasks. Please write clearly and IN YOUR OWN WORDS (plagiarism is NOT acceptable – refer to Course Description).
It is expected that each student will creatively design and author a unique system based on individual choices that fit with the requirements listed in each task. Before you begin, read over the entire assignment and understand all the tasks. Read through the sample code provided, test it and play with it so that you understand how it works. The sample code is provided as an example system. You are to write your own system yourself, although you may find some code from the sample that helps you. Acknowledge all code that you do not write yourself with in code comments.
If you are repeating this course, you must choose a different scenario of classes compared to any previous attempts of a similar assignment.
All code must conform to stylistic standards including proper commenting, appropriate choice of identifier names, proper indenting and other readability issues. Otherwise, marks will be deducted. Consult http://www.oracle.com/technetwork/java/codeconventions-150003.pdf
Task 1 Designing and Documenting your system
Examine the sample code you have been provided with. This code is for a simple Car Hire management system. It contains a number of classes. Class Diagrams for Car and Person classes are provided here for illustration purposes. (Note that get and set methods are not shown in the class diagrams, in keeping with convention, although they do exist.)
Car class Person class
Car
String make
String model
String registrationNumber
String colour
int warrantyDist
String toString ( )
Person
String name
Car car
String city
String toString ( )
1. Create a document named: surnameStudentIDAssign1.doc . In your document, you must include the following section headings: System Overview, Class Diagram, Class Descriptions, Testing.
System Overview
In the System Overview section you are to write 100-200 words describing your system and a made up use for your system in an imaginary/real world scenario. You will need to review this after completing all tasks and ensure that your overview explains your entire system. State any assumptions you are making in your system.
Class Diagram
In this section, you are to provide a class diagram for every user authored class in your system.
Class Descriptions
In this section, you are to describe each class you have written. For each class describe the instance variables as well as methods provided in that class. For each method, describe parameters (if any) as well as any output produced. Give examples of the output if appropriate. Describe the functionality achieved by each method.
Testing
As you develop your classes and methods, you will write testing code to verify that your code is working correctly. In this section, you will describe your chosen test data and explain how that data helps you test your code. Make sure that you choose a variety of test cases to ensure you can be satisfied that your code is working. Include screen shots of your testing results in this section.
Task 2 Creating your base classes
Create a new project in Eclipse called Assignment 1.
Within this project create a package called task02.
1. Author two new classes within your newly created package. Choose two related real world objects (similar to the Person and Car objects in the sample code provided) that you are modelling where one object might own or use or provide a service to the other object. e.g. a Person might own a Pet, a library might own a Book, a Person might hire a Video, a Teacher might teach a Student, a Coach might train an Athlete, a Dentist might treat a Patient etc. Due to this relationship, one of your objects will have a reference to the other object (similar to the Person having a Car).
2. Descriptions of each class and Class diagrams must be entered into your document created in task1. List any assumptions you make. Describe the relationship between the classes.
3. Explain the methods that you have authored – provide a description and type of any parameters and describe the purpose for each method.
4. Give an example of output that would be produced by your method/s.
5. Explain the constructors that you have provided. You must provide at least 2 constructors:
a. A no-parameter constructor which assigns each instance variable a default value. The String variables (e.g. name) should be initialised to “unknownâ€, and object fields initialised to null.
b. A constructor with parameters which assigns values to each instance variable. Note that the values to initialise the fields and objects should be passed in using arguments when the constructor is called – the fields should not be instantiated in the constructor.
6. Write get and set methods for your classes for each instance variable.
7. Write a toString method that will return a String containing all the relevant data for each of your objects.
8. Create a new Test02 class. In this class, provide a main method containing code to test both constructors, at least one get and one set method and your toString method. Run your test and make sure your class is behaving correctly.
9. In your documentation, explain how you have tested your code and the results of your testing. Include screen shots demonstrating the output when you tested your code.
Task 3 New objects based on extending other objects
1. Create another new package, called task03, within the project Assignment 1. In this package you will create two new classes that extend classes from the task02 package. It is likely that you will be able to say your subclass ‘IS A’ special type of your superclass. For example, A HireCar IS A Car, similar to HireCar which extends the class Car and A Customer ISA Person, Customer extends task01.Person in the sample code you were provided. Be creative and think of two(2) new classes that can extend your existing classes.
a. One of the new classes must be based on a reference extending an existing class from package task02 directly (similar to how Customer extends Person in the sample code). Do not repeat that package task02 class in the task03 package.
b. With the second new class, you may create a modified copy of your original class from package task02 in task03. Modify that copy of the original class so that it cannot be instantiated alone, but only the new class can be created.
Discuss your choice of classes and sub-classes with your tutor during a labclass prior to week 5.
2. Some further descriptions and class diagrams of classes in the sample code are provided in Appendix A. Refer to the sample code you were provided. Read these and understand them, then you need to create class diagrams for your own system and add descriptions of your new classes to your report document.
3. In your new classes, create at least 2 new methods that act on the new objects e.g. by performing a calculation based on the data in the object. Document these methods in your report. You may need to be creative with the instance variables you associate with your objects to think of a calculation you can provide. If you have any difficulty with ideas, discuss this with your tutor.
4. Test your classes to check they are working correctly. Document your testing process – describe your test data and the outcome of your testing. Include screen shots in your report document illustrating your testing process and the outcome of your testing.
Task 4 Arrays of objects
Create a new package called task04. Copy your classes from package task03 into this package. Create a new class: Manager class.
Manager class
Create a Manager class. In the Manager class create an instance variable which is an ArrayList of at least five objects. Create methods to:
1. add an object to the end of the ArrayList of objects
2. display all objects in the ArrayList of objects (output the ArrayList to the screen using toString on each object)
3. display a particular object retrieved from the ArrayList based on particular criteria. Write a method that will return a particular object. The method has a String parameter which corresponds to a name or something identifying the object. It should search the ArrayList one element at a time. If it finds the object whose name corresponds with the String parameter it should return a reference to that object from the ArrayList and also output a message informing the user of the location where this object was found (e.g. the list position). If it searches all of the elements and cannot find the name it should return null and output the position as -1.
4. delete an object from the ArrayList.
5. Test your manager class with appropriate test data in your main method. Provide screen shots of your testing in your final report.
Task 5 File input
1. Create an input file data.txt containing at least 10 objects’ data.
2. In your report describe the format of data in your data.txt file.
3. Write a method to read each object’s data from the file, data.txt inserting each into the ArrayList.
4. Write a method with one parameter input (File f). This method reads object’s data from a file, given that file as the argument.
5. Create a class called TestSystem and write a test method which tests your system using a scenario. In your report document, describe the testing scenario and the expected behaviour of your system. Provide screen shots of your system testing in your final report.
Task 6 (ITECH 6100 students only)
Using examples from your own code, write half a page (at least 250 words) explaining the difference between an abstract class and when/how it is used, compared with extending a non-abstract class.
Allocated Marks: See Course Description
Due Date: See Course Description
Please refer to the Course Description for information relating to late assignments and special consideration.
Plagiarism:
Please refer to the Course Description for information regarding Plagiarism.
Assignment Submission:
Assignments must be submitted by the due date and your assignment should be completed according to the document “General Guidelines for Presentation of Academic Work†(see https://federation.edu.au/students/assistance-support-and-services/academic-support/general-guide-for-the-presentation-of-academic-work) and the Java programming standards (see http://www.oracle.com/technetwork/java/codeconventions-150003.pdf).
The following criteria will be used when marking of your assignment:
• successful compilation
• successful completion the required tasks
• adherence to the guidelines provided
• 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 the following documentation, contained in an appropriate folder:
• 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
• tasks requiring written responses
• class diagrams
• list of references (including websites, the text book and any other resources) used (APA style); please clearly specify if none have been used.
• a printed copy of your code (this may be included as an Appendix). Please include this because we can provide more feedback this way
In addition to submitting a printed copy of your written report into your tutor’s assignment box, you should also submit the following using Moodle:
• an electronic copy of your code. Zip up the project itself and submit with the name surname idNo .zip
• a copy of your report (surnameStudentIDAssign1.doc)
Student ID: Student Name:
Task 1 5
System Description 2
Class Diagrams 3
Task 2 12
class 1
get / set methods
constructors
toString method
standards followed, appropriate comments 2
1
1
1
class 2
get / set methods
constructors
toString method 2
1
1
1
Test methods 2
Task 3 13
Class Diagrams for new classes 2
new classes added that extend classes in task 2 1
Class that extends a class from package task02 1
Class that extends a class that itself cannot be instantiated 1
Methods that do something useful with the new classes (3 marks for each method)
Method designed appropriately Method Name: ½
Comments to describe the Method ½
Method code 2
Method designed appropriately Method Name: ½
Comments to describe the Method ½
Method code 2
Test Methods with appropriate test data proving correctness of code 1
Appropriate Object Oriented design 1
Task 4 10
Method involving creating array of objects 2
Method involving adding an object into array 2
Method involving deleting an object from array 2
Method involving looking up an object based on criteria 2
Testing method/s 2
Task 5 10
Documentation of file format in report, including example data from test data.txt file and description of testing scenario 1.5
Method involving reading data from file and creating an associated array of objects 2.5
Method producing String output appropriately including all object data 2.5
Method reading data from a file, given the filename as input 1.5
TestSystem class with methods that verify the system is working, appropriately chosen test data 2
Task 6 (ITECH6100 students only) 10
Appropriate referencing 2
Use of appropriate examples from code authored by student in this assignment 3
Clear and well expressed explanation 5
Appendix A. The following diagrams and descriptions refer to the sample code you are provided. You are expected to learn from this code by understanding how it works and then transferring your ideas to your own work.
HireCar class
Here are class diagrams for HireCar which extends the Car class, and Customer which extends Person class.
Car
String make
String model
String registrationNumber
String colour
int warrantyDist
String toString ( )
Person
String name
Car car
String city
String toString ( )
Customer
Date dateHired
Date dateReturned
float discountRate
String toString ( )
int calculateDaysHired()
double calculateHiringCharge()
void createInvoice()
HireCar
Int position
boolean available
double rentalRate
String toString ( )
Further Descriptions of Customer class:
The base Person class is accessed from package task01 rather than being copied into task02
The method, calculateDaysHired() examines the dateHired and dateReturned fields and calculate a number of days hired. A customer is charged for each full day and any part days. For the sake of simplicity, we don’t worry about time of day. If a customer hires the car on the first day and returns it on the second day, he/she is charged for 2 days.
The method calculateHiringCharge() calculates the charge for the rental based upon the value calculated by calculateDaysHired.
The createInvoice method is invoked after the car has been returned. It consists mainly of output to the screen.
GET ANSWERS / LIVE CHAT