September 30, 2020

CRICOS Provider No. 00103D Programming 1 Assignment 2, 2014 Sem 2 Page 1 of 9 ITECH1000 Programming

11 min read

CRICOS Provider No. 00103D Programming 1 Assignment 2, 2014 Sem 2 Page 1 of 9
ITECH1000 Programming 1, Semester 2 2014
Assignment 2 – Development of a Simple Program Involving Multiple Classes
Due Date: see Course Description for full details Please see the Course Description for further information related to extensions for assignments and Special Consideration.
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.
Resources Required 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 ? Starting (incomplete) code for four of the classes to be developed Note: 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 ask for help.
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.

CRICOS Provider No. 00103D ITECH 1000 Programming 1 Assignment 2 Specification Semester 2, 2014 Page 2 of 9
Part A – Code Comprehension A Sample program is provided that creates a list of shapes stored in an array. This program uses classes: Shapes, Square, Rectangle and ShapesList. The main method is in the class: TestingShapesListClass. Conduct a careful examination of this code. 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: Shapes, Square, Rectangle and ShapesList provided, answer the following questions: 1. Draw a UML diagram of each of the Shapes, Rectangle and Square classes 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 ShapesList class using the code that has been provided. Complete this using the examples that have been provide in the lecture slides. 3. Add appropriate comments into the file: ShapesList.java to explain all the methods. At a mimimum, 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. Explain in what the purpose of the call to hasNextLine() in readFromFile() in ShapesList.java. 5. Briefly explain the code in bubbleSort() in the ShapesList class. What attribute are the shapes being sorted by? Name the sort algorithm that is being used. Explain in words how it works, using an example. Why do we need to use two for loops? 6. Briefly name and describe one other sorting algorithm that could have been used. 7. Explain the use of the return value in the getArea() method in the Rectangle class. What is it returning? Where does the value come from? 8. Examine the lines to open the output file and write the outputString in the ShapesList 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. 9. Examine the code in the exportToFile method. What is the purpose of the ‘ ’ in the toString() method that is used to produce the output string? 10. 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.
Part B – Development of a basic Class Your first coding task is to implement and test a class that represents a Vehicle. A Vehicle object has a make a model, a registration number, vinnumber and year of manufacture. 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.

CRICOS Provider No. 00103D ITECH 1000 Programming 1 Assignment 2 Specification Semester 2, 2014 Page 3 of 9
2. Use the UML diagram provided to implement the class Vehicle in a file called Vehicle.java. Starter code has been provided with this assignment, copy this starter code into your Vehicle.java file. Complete the constructors that will create a Vehicle object. 3. Author all mutator and accessor (set and get) methods and the toString() as indicated in the UML diagram. 4. Ensure that your Vehicle class includes the following validation within the mutator (set) methods: a. The make of the Vehicle cannot be null nor an empty String (ie “”). If an attempt is made to set the name to an invalid value the method should return false. b. The year of manufacture of the Vehicle must be greater than or equal to 1950. If an attempt is made to set the value of the year of manufacture to an invalid value the method should return false and not change the value of the yearOfManufacture.
Vehicle
– String make; – String model; – String registration; – String vinNumber; – int yearOfManufacture;
~ Vehicle(make:String, model:String, registration:String, vinNumber:String, yearOfManufacture:int) create ~ Vehicle() create + getMake():String + setMake(_make:String):boolean + getModel():String + setModel(_model:String) + getRegistration():String + setRegistration(_registration:String) + getVinNumber():String + setVinNumber(_vinNumber:String) + getYearOfManufacture():int + setYearOfManufacture(_year:int):boolean + toString():String Figure 1: UML Diagram for the class Vehicle
Part C – Development of extended Classes using inheritance Your second coding task is to implement and test a class that represents a Car. For this assignment a Car is a vehicle with additional attributes such as number of seats, number of doors, whether it is a hatchback or not, whether or not it has tinted windows and whether it has manual transmission or automatic transition. A Car isA Vehicle. The Car class will extend a Vehicle class, so the make, model, registration, vin number and

CRICOS Provider No. 00103D ITECH 1000 Programming 1 Assignment 2 Specification Semester 2, 2014 Page 4 of 9
year of manufacture will be inherited from the Vehicle class. After you have created the Car class, you are asked to create a similar class for another type of vehicle that you choose (e.g. Truck, Caravan, Boat, Tractor….).
To complete this task you are required to:
1. Use the UML diagram provided to implement the class Car in a file called Car.java. Ensure that you adhere to the naming used below as this class will be used by other classes that you will develop. Starter code is provided for you to copy. 2. Make sure that your Car class extends the Vehicle class. 3. Ensure that your class includes the following validation within the mutator (set) methods: a. numSeats cannot be less than two. If an attempt is made to set the numSeats to an invalid amount, then the method should set the numSeats to two and return false, otherwise set the numSeats as given and return true. b. The numDoors cannot be less than two. If an attempt is made to set the value of the numDoors to an invalid value the method should return false. 4. Write additional methods for toString() and a method to check equality with another car (equality should be based on vinNumber being the same for both vehicles). 5. Select two Cars that you will create. Choose values for each of the data attributes for each car. Write a class called TestClass (starter code is provided to copy from) and within the main method write code that will : a. Instantiate an instance of the Car class for one of the Cars you selected using the Car() constructor b. Sets all of the instance variables to the appropriate values using the mutator methods (set) c. Change the yearOfManufacture to increase the yearOfManufacture of the first Car by 5 years. d. Instantiates an instance of the Class Car for a second different Car contained in the table below using the Car(make:String, model:String, registration: String, vinNumber: String, yearOfManufacture: int, numSeats:int, numDoors: int, hatch: boolean, tintedWindows: boolean,manual: boolean) constructor e. Display both of the Cars that you have created using the toString() method f. Display both of the Cars that you have created using individual accessor (get) methods in a print statement

CRICOS Provider No. 00103D ITECH 1000 Programming 1 Assignment 2 Specification Semester 2, 2014 Page 5 of 9

Car
– numSeats: int – numDoors: int – hatch: boolean – tintedWindows: boolean – manual: boolean
~ Car(make:String, model:String, registration: String, vinNumber: String, yearOfManufacture: int, numSeats:int, numDoors: int, hatch: boolean, tintedWindows: boolean,manual: boolean) create ~ Car() create + setNumSeats(_numSeats: int): boolean + getNumSeats(): int + setNumDoors(_numDoors: int): boolean + getNumDoors(): int + setHatch(_hatch: boolean) + getHatch(): boolean + setTintedWindows(_tinted: boolean) + getTintedWindows() : boolean + getManual(): boolean + setManual(_manual: boolean) + equalsIgnoreCase(anotherCar: Car): boolean + toString():String Figure 2: UML Diagram for the class Car 6. Now create a second class representing another vehicle (e.g. bike, trailer, caravan, truck, or tractor etc.) in a similar fashion to the way you created the car class. (The car class is similar to the square class in the sample code provided. The square class extends the Shapes class. The Rectangle class also extends the Shapes class. Your second vehicle type is similar to the Rectangle class. Your vehicle e.g. truck will extend the Vehicle class.) a. Decide on your vehicle type and then choose attributes particular to that vehicle that will be instance variables b. Draw a UML class diagram for your new class c. Create your new class in a new file named appropriately e.g. Tractor.java d. Make sure your new class extends the Vehicle class e. Write get and set methods for your new class f. Write a toString() method for your new class g. Test your new class by writing code to create an object based on this class in your TestClass class h. Test your object by modifying one of the instance variables using a set method then display the object

CRICOS Provider No. 00103D ITECH 1000 Programming 1 Assignment 2 Specification Semester 2, 2014 Page 6 of 9
Part D – Development of the Garage class Using the UML diagrams provided and the information below you are required to implement and test classes that represent a Garage object. For this assignment a Garage contains multiple vehicles up to a specified capacity. (This may be modeled on the ShapesList class in the sample code. The ShapesList class contains multiple Shapes in an array. Your Garage will in a similar way contain multiple Vehicles in an array.)
Garage.java
Garage
– name: String – Vehicles: Vehicle[] – numVehicles: int – capacity: int
~ Garage (initName: String, capacity: int) create + getName():String + getNumVehicles():int + setName(newName: String): boolean + addVehicle(newVehicle: Vehicle): Boolean + sortVehicles() + 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 Garage.java Write get and set methods as well as an addVehicle method. 2. Create a method for sorting the Vehicles in the Garage (model this on the ShapesList bubblesort method) 3. Update the class TestClass adding in code to: a. Create an instance of the Garage class b. Add at least two Cars created to the Garage class using the addVehicle() method c. Add at least two other vehicles (e.g. Tractor or Bike) to the Garage class d. Display the details of the garage that you have created using the toString() method in the Garage class – these should be accessed via the instance of the garage class that you have created e. Display all of the vehicles in the garage by looping through and accessing each vehicle in turn. Each vehicle should be accessed via the instance of the Garage class you have created, then printed using the toString() method on that vehicle.
(Hint: Look at the TestingShapesListClass.java class for examples of similar code to the code you will need in your TestClass. In TestingShapesListClass, Shapes are added to a ShapesList object. In your code Vehicles are added to the Garage object).

CRICOS Provider No. 00103D ITECH 1000 Programming 1 Assignment 2 Specification Semester 2, 2014 Page 7 of 9
Part D – Using the Classes Create a new class called GarageSystem.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 using a switch statement to process the menu options. Each menu item should be enacted by choosing the appropriate method on the Garage object. The menu should include the following options: 1. Populate the Garage 2. Display Vehicles in Garage 3. Sort Vehicles data 4. Import data (ITECH5000 students only) 5. Export data (ITECH5000 students only 6. Exit ? Populate the Garage – this option will allow the user to enter data for each vehicle OR you may write a populate method that will insert data hardcoded in your method directly into each vehicle. You will use the set methods on your Car object and the set methods on your additional vehicle (Hint: copy this code from your TestClass.) ? Display Data – display the data of all vehicles in the garage, using your toString() method on the Garage object. ? Sort data should utilise some form of sorting algorithm to sort the vehicles into alphabetical order based on name. (Hint: look at the sort method in the ShapesList class. It sorts on area of the shape, you need to sort based on name of the vehicle.) For students enrolled in ITECH5000 ONLY: ? Import data – this menu should read in data from the filed 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
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 ? 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

CRICOS Provider No. 00103D ITECH 1000 Programming 1 Assignment 2 Specification Semester 2, 2014 Page 8 of 9
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.docx or surnameStudentIDAssign2.pdf
Marking Guide PART A – Code Comprehension /20 PART B – Vehicle class + Testing /20 PART C – Car and another vehicle Classes + Testing /40 PART D – Garage Class + Testing /40 PART E – Implementation of Menu /20 Quality of code created /15 Presentation of documentation / report /5
Total /20 /160

CRICOS

Provider No. 00103D
Appendix
gar
vehi
car
D ITECH 100

x Figure 4. U
rage
icle
00 Programming 1 As
co
is UML Class Di
ssignment 2 Specific
ontains
A
iagram for th
cation Semester 2, 20
he Garage sy
014
ystem
Page 9 9 of 9

Copyright © All rights reserved. | Newsphere by AF themes.