SlideShare a Scribd company logo
1 of 39
assignmentTwo/Car.javaassignmentTwo/Car.javapackage assign
mentTwo;
// incomplete starter code for assignment two programming 1, se
m 2 2014
// author: Kathleen Keogh version 1, incomplete. September 20
14
publicclassCarextendsVehicle{
// instance variables
privateint numSeats, numDoors;
privateboolean hatch, tintedWindows;
publicCar(){
}
publicCar(int _numSeats,int _numDoors,boolean _hatch,boolean
_tintedWindows){
// insert appropriate initialisation code here based on the parame
ters provided
}
// get and set methods for each car instance variable
publicint getNumSeats(){
return numSeats;
}
publicboolean setNumSeats(int _numSeats){
returntrue;// change this based on validation
}
publicint getNumDoors(){
return1;// change this to return appropriate value
}
publicvoid setNumDoors(){
}
publicboolean getHatch(){
returntrue;// change this to return the appropriate value
}
publicvoid setHatch(boolean _hatch){
}
publicboolean getTintedWindows(){
returntrue;// update this to return the appropriate value
}
publicvoid setTintedWindows(boolean _tintedWindows){
}
// toString method
publicString toString(){
// insert code here to appropriately return a string of data for thi
s car, use superclass methods where appropriate
return("Car. Make "+ getMake());// change this to return more t
han just the make
}
}
assignmentTwo/Garage.javaassignmentTwo/Garage.javapackage
assignmentTwo;
// Author, Version 1. Starter Code: Kathleen Keogh September 2
014
// Author, Version 2. :
// Garage class is for a garage that contains a number of vehicle
s
publicclassGarage{
//instance variables
Vehicle vehicleList[];
int maxVehicles=10;// default maximum number of vehicles is 1
0
int currsize;
publicGarage(){// constructor with no parameters
vehicleList =newVehicle[maxVehicles];
currsize=0;
}
publicGarage(int _numMaxVehicles){// constructor with one par
ameter - maximum number of vehicles for garage
maxVehicles = _numMaxVehicles;
vehicleList =newVehicle[maxVehicles];
currsize =0;
}
// TODO: add get and set methods
// TODO: add toString() method
// TODO: add other methods including addVehicle, sortVehicles
}
assignmentTwo/Rectangle.javaassignmentTwo/Rectangle.javapa
ckage assignmentTwo;
publicclassRectangleextendsShapes{
double length, width;// extra instance variables associated with
Rectangle particularly
publicRectangle(){// constructor to create an 'empty' triangle
super("","",0,0);
length =0.0;//initialise length and width to zero for new re
ctangle
width =0.0;
}
publicRectangle(double initLength,double initWidth,String init
Name,String initColour,double xCoord,double yCoord){
super(initName, initColour, xCoord, yCoord);// use constructor
from super class: Shapes
setLength(initLength);// initialise length to provided value
setWidth(initWidth);
}
publicboolean setLength(double _length){// mutator method to s
et length to new value
if(_length >0.0){// validate length is positive value greater than
zero
length = _length;
returntrue;
}
elsereturnfalse;
}
publicboolean setWidth(double _width){// mutator method to se
t width to new value
if(_width >0.0){// validate width is positive value greater than z
ero
width = _width;
returntrue;
}
elsereturnfalse;
}
publicdouble getWidth(){
return width;
}
publicdouble getLength(){
return length;
}
publicdouble calcArea (){
return length * width;
}
publicdouble getArea(){
return calcArea();
}
publicString toString(){
return("Rectangle "+ getName()+" Colour "+ getColour()+" Are
a "+ getArea()+" located at "+ getXcoord()+" "+ getYcoord());
}
}
assignmentTwo/Shapes.javaassignmentTwo/Shapes.javapackage
assignmentTwo;
publicclassShapes{
privateString name;
privateString colour;
privatedoubleXcoord;
privatedoubleYcoord;
publicShapes(){
name =newString("");
colour =newString("");
Xcoord=0.0;
Ycoord=0.0;
}
publicShapes(String initName,String initColour,double initXcoo
rd,double initYcoord){
name =newString(initName);
colour =newString(initColour);
setXcoord(initXcoord);
setYcoord(initYcoord);
}
publicvoid setName (String newName){
name =newString(newName);
}
publicboolean setXcoord(double newXcoord){
if(newXcoord >0.0){
Xcoord= newXcoord;
returntrue;
}
elsereturnfalse;
}
publicboolean setYcoord(double newYcoord){
if(newYcoord >0.0){
Ycoord= newYcoord;
returntrue;
}
elsereturnfalse;
}
publicvoid setColour (String newColour){
colour =newString(newColour);
}
publicdouble getXcoord (){
returnXcoord;
}
publicdouble getYcoord (){
returnYcoord;
}
publicString getName (){
return name;
}
publicString getColour (){
return colour;
}
publicdouble getArea (){
return0.0;//dummy method will be overridden in extended classe
s
}
}
assignmentTwo/ShapesList.javaassignmentTwo/ShapesList.java
package assignmentTwo;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
publicclassShapesList{
staticfinalint MAXSIZE =10;
Shapes myList[];// ShapesList contains multiple Shapes (up to
MAXSIZE)
int currsize =0;
publicShapesList(){// default constructor create a shapes list of
MAXSIZE size
myList =newShapes[MAXSIZE];
currsize =0;
}
publicShapesList(int _maxsize){// constructor to create a shapes
list of max size given
myList =newShapes[_maxsize];
currsize =0;
}
publicvoid addShape(Shapes _newShape){
if(currsize < MAXSIZE){
myList[currsize++]= _newShape;
}
elseSystem.out.println("shape list is full");
}
publicString toString(){
String result ="";
for(int i =0; i < currsize; i++)
result = result + myList[i].toString()+"; rn";
return(result);
}
publicvoid bubbleSort(){// sort shapes based on Area of shape
Shapes tempShape;
/*
* pseudo code for bubble sort:
* for index1 in range(len(sList) -1):
* for index2 in range (len(sList) - (index1 + 1)):
* if (sList[index2] > sList[index2 + 1]):
* swapListPositions (sList, index2, index2 + 1)
*
*/
for(int i =0; i <(currsize -1); i++)
{
for(int j =0; j <(currsize -(i +1)); j++)
{
if(((myList[j]).getArea())>((myList[j +1]).getArea()))
{
tempShape = myList [j +1];
myList [j +1]= myList [j];
myList [j]= tempShape;
}
}
}
}
publicvoid exportToFile (String outputString){
System.out.println("about to open export file");
try{
BufferedWriter output;
File file =newFile("export.txt");
System.out.println(file.getAbsolutePath());
output =newBufferedWriter(newFileWriter(file));
output.write(outputString);
output.newLine();
System.out.println("just wrote to file");
output.close();
}
catch(IOException e){
System.out.println("IO Error with file export");
e.printStackTrace();
}
}
publicvoid readFromFile(){
int numAdded=0;
File inputfile;
inputfile =newFile("ShapesFile.txt");
try{
Scanner inputScanner =newScanner(inputfile);
while(inputScanner.hasNextLine()){
//Read the shapes details from the file
String type = inputScanner.next();
switch(type){
case"square":{
System.out.println("processing a square...");
Square newSq =newSquare();
newSq.setName(inputScanner.next());
newSq.setColour(inputScanner.next());
newSq.setSide(inputScanner.nextDouble());
newSq.setXcoord(inputScanner.nextDouble());
newSq.setYcoord(inputScanner.nextDouble());
addShape(newSq);
break;
}
case"rectangle":{
System.out.println("processing a rectangle...");
Rectangle newRect =newRectangle();
newRect.setName(inputScanner.next());
newRect.setColour(inputScanner.next());
newRect.setLength(inputScanner.nextDouble())
;
newRect.setWidth(inputScanner.nextDouble());
newRect.setXcoord(inputScanner.nextDouble())
;
newRect.setYcoord(inputScanner.nextDouble())
;
addShape(newRect);
}
}
}
inputScanner.close();
}
catch(IOException e){
System.out.println("IO Exception reading shapes from file");
e.printStackTrace();
}
}
}
assignmentTwo/Square.javaassignmentTwo/Square.javapackage
assignmentTwo;
publicclassSquareextendsShapes{
double side;
publicSquare(){//create 'empty' square object with zero coord va
lues and "" for Strings name and colour
super("","",0,0);
side =0.0;//initialise side to zero for new square
}
publicSquare(double initside,String initName,String initColour,
double xCoord,double yCoord){
super(initName, initColour, xCoord, yCoord);// use constructor
from super class: Shapes
setSide(initside);// initialise length to provided value
}
publicvoid setSide (double newSide){
side = newSide;
}
publicdouble calcArea (){
return side * side;// area of Square is side * side
}
publicdouble getArea (){
return calcArea();
}
publicString toString(){
return("Square "+ getName()+" Colour "+ getColour()+" Area "
+ getArea()+" located at "+ getXcoord()+" "+ getYcoord());
}
}
assignmentTwo/TestClass.javaassignmentTwo/TestClass.javapa
ckage assignmentTwo;
// author, version 1: Kathleen Keogh September 2014. Version 1
is incomplete, provides stubs for some methods
// This test class is used to test the Garage system for assignmen
t 2, Programming 1, Sem 2 2014.
// author, version 2:
publicclassTestClass{
publicTestClass(){// constructor for TestClass
}
publicvoid runtest1(){
// first test case
// create a car object and test that it is working
Car myTestCar =newCar();
System.out.println(myTestCar.toString());
}
publicvoid runtest2(){
// second test case
// create another vehicle object and test that it is working
}
publicvoid runtest3(){
// third test case
// create a garage object with a number of vehicles in the garage
, then print it out to test it worked
}
publicstaticvoid main(String[] args){
// TODO write code here to invoke test methods to test the Gar
age system
TestClass mytest =newTestClass();
System.out.println("Running test1... ");
mytest.runtest1();
System.out.println("Running test2... ");
mytest.runtest2();
System.out.println("Running test3... ");
mytest.runtest3();
}
}
assignmentTwo/TestingShapesListClass.javaassignmentTwo/Tes
tingShapesListClass.javapackage assignmentTwo;
// this testing class is used to test classes : ShapesList, Rectangl
e, Square, Shapes.
publicclassTestingShapesListClass{
//instance reference variable to point to a shapes list object used
in testing
ShapesList shList;
publicTestingShapesListClass(){
shList =newShapesList();// create a shapes list object to us
e in testing
}
publicSquare testrun1a (){
Square s =newSquare(4.0,"mySquare","Blue",3.0,10.0);
System.out.println(s.toString());
return s;
}
publicSquare testrun1b (){
Square s1 =newSquare();// test empty constructor
s1.setName("Anothersquare");// use set methods to set val
ues for instance variables
s1.setSide(5.0);
s1.setColour("Red");// test set methods to change values of
colour and coords
s1.setXcoord(4.0);
s1.setYcoord(20.0);
System.out.println(s1.toString());
return s1;
}
publicRectangle testrun2 (){
// create a rectangle shape and print it out
Rectangle r =newRectangle(2.0,6.0,"rectangle","Orange",5.0,10.
0);
System.out.println(r.toString());
return r;
}
publicvoid testrun3(Square _s,Square _s1,Rectangle _r){
// test adding 3 shapes to the shapes list
System.out.println("My list of Shapes");
shList.addShape(_s);
shList.addShape(_s1);
shList.addShape(_r);
System.out.println(shList.toString());
}
publicvoid testrun4(){
// test reading shapes from file and adding to shapes list
shList.readFromFile();
}
publicvoid testrun5(){
// test sorting list of shapes
shList.bubbleSort();
System.out.println("My list of sorted Shapes");
System.out.println(shList.toString());
}
publicvoid testrun6(){
// test exporting shapes list to a file
shList.exportToFile(shList.toString());
}
publicstaticvoid main (String[] args){
TestingShapesListClass t =newTestingShapesListClass();
Square testSquare1 = t.testrun1a();
Square testSquare2 = t.testrun1b();
Rectangle testRectangle = t.testrun2();
t.testrun3(testSquare1, testSquare2, testRectangle);
t.testrun4();
t.testrun5();
t.testrun6();
}
}
assignmentTwo/Vehicle.javaassignmentTwo/Vehicle.javapackag
e assignmentTwo;
publicclassVehicle{
//instance variables
privateString make, model, registration, vinNum;
privateint yearOfManufacture;
publicVehicle(){// empty constructor
// code to initialise values to "" and 0 goes here
}
// constructor with initialisation values
publicVehicle(String _make,String _model,String _registration,
String _vinNum,int _yearOfManufacture ){
}
// get and set methods for instance variables
publicvoid setMake(String _make){
}
publicString getMake(){
return"";// change this to return appropriate value
}
publicvoid setModel(String _model){
}
publicString getModel(){
return"";// change this to return appropriate value
}
publicvoid setRegistration(String _registration){
}
publicString getRegistration(){
return"";// change this to return appropriate value
}
//vin num
publicvoid setVinNum(String _vinNum){
}
publicString getVinNum(){
return"";// change this to return appropriate value
}
// year of manufacture
publicvoid setYearOfManufacture(int _year){
}
publicint getYearOfManufacture(){
return1;// change this to return appropriate value
}
}
ITECH1000 5000 Programming 1_Assignment2Specification
2014-20.pdf
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 relate
d 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:
jects of these classes
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:
electronic copy of this assignment specification sheet
A sample program with similar features to the assignment requir
ements involving multiple classes
Starting (incomplete) code for four of the classes to be develope
d
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 b
ooks. 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 be
fore loop execution.
Use a for‐loop when the number of iterations is known before lo
op execution.
Indent your code correctly to aid readability and use a consisten
t curly bracket placement scheme.
white space to make your code as readable as possible.
Validation of input should be limited to ensuring that the user h
as entered values that are within correct
bounds. You do not have to check that they have entered the co
rrect data type.
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 Squ
are classes using the code that has been
provided. Complete this using the examples that have been pro
vide in the lecture slides.
2.
Draw a UML diagram of the ShapesList class using the code tha
t 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 expl
ain 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 read
FromFile() 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 ho
w it works, using an example. Why do we need
to use two for loops?
6.
Briefly name and describe one other sorting algorithm that coul
d have been used.
7.
Explain the use of the return value in the getArea() method in th
e Rectangle class. What is it returning? Where
does the value come from?
8.
Examine the lines to open the output file and write the outputStr
ing 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 Ja
va API documentation and describe the use of
this object.
9.
Examine the code in the exportToFile method. What is the pur
pose of the ‘rn’ 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. R
e‐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 to
String() 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 classe
s 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 t
he mutator (set) methods:
a.
numSeats cannot be less than two. If an attempt is made to set t
he 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 e
quality 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 t
he data attributes for each car. Write a class
called TestClass (starter code is provided to copy from) and wit
hin the main method write code that will :
a.
Instantiate an instance of the Car class for one of the Cars you s
elected 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 yearOfManufactu
re of the first Car by 5 years.
d.
Instantiates an instance of the Class Car for a second different C
ar contained in the table below using
the Car(make:String, model:String, registration: String, vinNum
ber: String, yearOfManufacture: int,
numSeats:int, numDoors: int, hatch: boolean, tintedWindows: b
oolean,manual: boolean) constructor
e.
Display both of the Cars that you have created using the toStrin
g() 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. bik
e, trailer, caravan, truck, or tractor etc.) in a
similar fashion to the way you created the car class. (The car cla
ss is similar to the square class in the sample
code provided. The square class extends the Shapes class. The R
ectangle 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 particul
ar 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. Tr
actor.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 usin
g 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 Writ
e get and set methods as well as an addVehicle
method.
2.
Create a method for sorting the Vehicles in the Garage (model t
his 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 add
Vehicle() method
c.
Add at least two other vehicles (e.g. Tractor or Bike) to the Gar
age 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 tha
t 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 exampl
es of similar code to the code you will need in your
TestClass. In TestingShapesListClass, Shapes are added to a Sh
apesList 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
– 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 the data of all vehicles in the garage,
using your toString() method on the
Garage object.
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:
– 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.
– save the data to a new file ExportData.txt
Assignment Submission
The following criteria will be used when marking your assignme
nt:
completion of the required tasks
quality of code that adheres to the programming standards for th
e course; including:
comments and documentation
code layout
meaningful variable names
You are required to provide documentation, contained in an app
ropriate file, which includes:
a front page ‐ indicating your name, a statement of what has bee
n 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 assist
ed you with
table of contents and page numbers
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 yo
ur 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.p
df
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 99 of 9
ShapesFile.txt
square mybestsquare purple 6.0 1.0 5.0
square mylastsquare green 7.0 3.0 4.0
rectangle myfirstrectangle aqua 8.0 3.0 2.5 6.5
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx

More Related Content

Similar to assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx

1.what is the difference between a instance variable and an local va.pdf
1.what is the difference between a instance variable and an local va.pdf1.what is the difference between a instance variable and an local va.pdf
1.what is the difference between a instance variable and an local va.pdfarchgeetsenterprises
 
Powering code reuse with context and render props
Powering code reuse with context and render propsPowering code reuse with context and render props
Powering code reuse with context and render propsForbes Lindesay
 
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDBTDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDBtdc-globalcode
 
codeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docx
codeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docxcodeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docx
codeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docxmonicafrancis71118
 
[PL] O klasycznej, programistycznej elegancji
[PL] O klasycznej, programistycznej elegancji[PL] O klasycznej, programistycznej elegancji
[PL] O klasycznej, programistycznej elegancjiJakub Marchwicki
 
import java-util--- import java-io--- class Vertex { -- Constructo.docx
import java-util--- import java-io---   class Vertex {   -- Constructo.docximport java-util--- import java-io---   class Vertex {   -- Constructo.docx
import java-util--- import java-io--- class Vertex { -- Constructo.docxBlake0FxCampbelld
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionDmitry Sheiko
 
Tank Battle - A simple game powered by JMonkey engine
Tank Battle - A simple game powered by JMonkey engineTank Battle - A simple game powered by JMonkey engine
Tank Battle - A simple game powered by JMonkey engineFarzad Nozarian
 
Clean code in JavaScript
Clean code in JavaScriptClean code in JavaScript
Clean code in JavaScriptMathieu Breton
 
TDC2016SP - Trilha .NET
TDC2016SP - Trilha .NETTDC2016SP - Trilha .NET
TDC2016SP - Trilha .NETtdc-globalcode
 
Introduction à Dart
Introduction à DartIntroduction à Dart
Introduction à DartSOAT
 
So here is the code from the previous assignment that we need to ext.pdf
So here is the code from the previous assignment that we need to ext.pdfSo here is the code from the previous assignment that we need to ext.pdf
So here is the code from the previous assignment that we need to ext.pdfleolight2
 
Relay Modern: architecture and workflow
Relay Modern: architecture and workflowRelay Modern: architecture and workflow
Relay Modern: architecture and workflowAlex Alexeev
 
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo....NET Conf UY
 
Java questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdfJava questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdfforwardcom41
 
Polygon.javapublic class Polygon { private int numSides; priva.pdf
Polygon.javapublic class Polygon { private int numSides; priva.pdfPolygon.javapublic class Polygon { private int numSides; priva.pdf
Polygon.javapublic class Polygon { private int numSides; priva.pdfapnafreez
 

Similar to assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx (20)

ES6 Overview
ES6 OverviewES6 Overview
ES6 Overview
 
1.what is the difference between a instance variable and an local va.pdf
1.what is the difference between a instance variable and an local va.pdf1.what is the difference between a instance variable and an local va.pdf
1.what is the difference between a instance variable and an local va.pdf
 
Powering code reuse with context and render props
Powering code reuse with context and render propsPowering code reuse with context and render props
Powering code reuse with context and render props
 
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDBTDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
 
codeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docx
codeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docxcodeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docx
codeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docx
 
[PL] O klasycznej, programistycznej elegancji
[PL] O klasycznej, programistycznej elegancji[PL] O klasycznej, programistycznej elegancji
[PL] O klasycznej, programistycznej elegancji
 
OOP Lab Report.docx
OOP Lab Report.docxOOP Lab Report.docx
OOP Lab Report.docx
 
import java-util--- import java-io--- class Vertex { -- Constructo.docx
import java-util--- import java-io---   class Vertex {   -- Constructo.docximport java-util--- import java-io---   class Vertex {   -- Constructo.docx
import java-util--- import java-io--- class Vertex { -- Constructo.docx
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Fact, Fiction, and FP
Fact, Fiction, and FPFact, Fiction, and FP
Fact, Fiction, and FP
 
Tank Battle - A simple game powered by JMonkey engine
Tank Battle - A simple game powered by JMonkey engineTank Battle - A simple game powered by JMonkey engine
Tank Battle - A simple game powered by JMonkey engine
 
Clean code in JavaScript
Clean code in JavaScriptClean code in JavaScript
Clean code in JavaScript
 
TDC2016SP - Trilha .NET
TDC2016SP - Trilha .NETTDC2016SP - Trilha .NET
TDC2016SP - Trilha .NET
 
DotNet Conference: code smells
DotNet Conference: code smellsDotNet Conference: code smells
DotNet Conference: code smells
 
Introduction à Dart
Introduction à DartIntroduction à Dart
Introduction à Dart
 
So here is the code from the previous assignment that we need to ext.pdf
So here is the code from the previous assignment that we need to ext.pdfSo here is the code from the previous assignment that we need to ext.pdf
So here is the code from the previous assignment that we need to ext.pdf
 
Relay Modern: architecture and workflow
Relay Modern: architecture and workflowRelay Modern: architecture and workflow
Relay Modern: architecture and workflow
 
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
 
Java questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdfJava questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdf
 
Polygon.javapublic class Polygon { private int numSides; priva.pdf
Polygon.javapublic class Polygon { private int numSides; priva.pdfPolygon.javapublic class Polygon { private int numSides; priva.pdf
Polygon.javapublic class Polygon { private int numSides; priva.pdf
 

More from ssuser562afc1

Pick an Apollo Mission that went to the Moon.  Some mission only orb.docx
Pick an Apollo Mission that went to the Moon.  Some mission only orb.docxPick an Apollo Mission that went to the Moon.  Some mission only orb.docx
Pick an Apollo Mission that went to the Moon.  Some mission only orb.docxssuser562afc1
 
Pick a topic from data.gov that has large number of data sets on wid.docx
Pick a topic from data.gov that has large number of data sets on wid.docxPick a topic from data.gov that has large number of data sets on wid.docx
Pick a topic from data.gov that has large number of data sets on wid.docxssuser562afc1
 
Pick an animal with sophisticated communication. Quickly find and re.docx
Pick an animal with sophisticated communication. Quickly find and re.docxPick an animal with sophisticated communication. Quickly find and re.docx
Pick an animal with sophisticated communication. Quickly find and re.docxssuser562afc1
 
Pick a real healthcare organization or create your own. Think about .docx
Pick a real healthcare organization or create your own. Think about .docxPick a real healthcare organization or create your own. Think about .docx
Pick a real healthcare organization or create your own. Think about .docxssuser562afc1
 
PHYS 102In the Real World” Discussion TopicsYou may choose yo.docx
PHYS 102In the Real World” Discussion TopicsYou may choose yo.docxPHYS 102In the Real World” Discussion TopicsYou may choose yo.docx
PHYS 102In the Real World” Discussion TopicsYou may choose yo.docxssuser562afc1
 
Photosynthesis and Cellular RespirationCellular respiration .docx
Photosynthesis and Cellular RespirationCellular respiration .docxPhotosynthesis and Cellular RespirationCellular respiration .docx
Photosynthesis and Cellular RespirationCellular respiration .docxssuser562afc1
 
Philosophy of Inclusion Research SupportIt is not enough to simp.docx
Philosophy of Inclusion Research SupportIt is not enough to simp.docxPhilosophy of Inclusion Research SupportIt is not enough to simp.docx
Philosophy of Inclusion Research SupportIt is not enough to simp.docxssuser562afc1
 
PHYSICS DATA SHEET.docx
PHYSICS DATA SHEET.docxPHYSICS DATA SHEET.docx
PHYSICS DATA SHEET.docxssuser562afc1
 
Physical Assessment Reflection Consider your learning and gr.docx
Physical Assessment Reflection Consider your learning and gr.docxPhysical Assessment Reflection Consider your learning and gr.docx
Physical Assessment Reflection Consider your learning and gr.docxssuser562afc1
 
Phonemic Awareness TableTaskScriptingDescription and.docx
Phonemic Awareness TableTaskScriptingDescription and.docxPhonemic Awareness TableTaskScriptingDescription and.docx
Phonemic Awareness TableTaskScriptingDescription and.docxssuser562afc1
 
Philosophy 2582 - Media Ethics Paper 1 (Noam Chomsky) 
.docx
Philosophy 2582 - Media Ethics Paper 1 (Noam Chomsky) 
.docxPhilosophy 2582 - Media Ethics Paper 1 (Noam Chomsky) 
.docx
Philosophy 2582 - Media Ethics Paper 1 (Noam Chomsky) 
.docxssuser562afc1
 
Pick a large company you like. Find their Statement of Cash Flow.docx
Pick a large company you like. Find their Statement of Cash Flow.docxPick a large company you like. Find their Statement of Cash Flow.docx
Pick a large company you like. Find their Statement of Cash Flow.docxssuser562afc1
 
Philosophy 7 Asian Philosophy (Fall 2019) Paper Guidelines .docx
Philosophy 7 Asian Philosophy (Fall 2019) Paper Guidelines .docxPhilosophy 7 Asian Philosophy (Fall 2019) Paper Guidelines .docx
Philosophy 7 Asian Philosophy (Fall 2019) Paper Guidelines .docxssuser562afc1
 
PIC.jpga.zipAPA.pptAPA Style--Review.docx
PIC.jpga.zipAPA.pptAPA Style--Review.docxPIC.jpga.zipAPA.pptAPA Style--Review.docx
PIC.jpga.zipAPA.pptAPA Style--Review.docxssuser562afc1
 
PHIL101 B008 Win 20 ! # AssignmentsAssignmentsAssignmen.docx
PHIL101 B008 Win 20  !  # AssignmentsAssignmentsAssignmen.docxPHIL101 B008 Win 20  !  # AssignmentsAssignmentsAssignmen.docx
PHIL101 B008 Win 20 ! # AssignmentsAssignmentsAssignmen.docxssuser562afc1
 
Phase 3 Structured Probl.docx
Phase 3 Structured Probl.docxPhase 3 Structured Probl.docx
Phase 3 Structured Probl.docxssuser562afc1
 
Phil 2101 Final PaperGuidelines Approximately 5 pages, doubl.docx
Phil 2101 Final PaperGuidelines Approximately 5 pages, doubl.docxPhil 2101 Final PaperGuidelines Approximately 5 pages, doubl.docx
Phil 2101 Final PaperGuidelines Approximately 5 pages, doubl.docxssuser562afc1
 
Perspectives on WarInstructionsAnalyze After watching .docx
Perspectives on WarInstructionsAnalyze After watching .docxPerspectives on WarInstructionsAnalyze After watching .docx
Perspectives on WarInstructionsAnalyze After watching .docxssuser562afc1
 
pestle research for chile bolivia paraguay uruguay .docx
pestle research for chile bolivia paraguay uruguay .docxpestle research for chile bolivia paraguay uruguay .docx
pestle research for chile bolivia paraguay uruguay .docxssuser562afc1
 
Pg. 04Question Four Assignment 2Deadline Saturd.docx
Pg. 04Question Four Assignment 2Deadline Saturd.docxPg. 04Question Four Assignment 2Deadline Saturd.docx
Pg. 04Question Four Assignment 2Deadline Saturd.docxssuser562afc1
 

More from ssuser562afc1 (20)

Pick an Apollo Mission that went to the Moon.  Some mission only orb.docx
Pick an Apollo Mission that went to the Moon.  Some mission only orb.docxPick an Apollo Mission that went to the Moon.  Some mission only orb.docx
Pick an Apollo Mission that went to the Moon.  Some mission only orb.docx
 
Pick a topic from data.gov that has large number of data sets on wid.docx
Pick a topic from data.gov that has large number of data sets on wid.docxPick a topic from data.gov that has large number of data sets on wid.docx
Pick a topic from data.gov that has large number of data sets on wid.docx
 
Pick an animal with sophisticated communication. Quickly find and re.docx
Pick an animal with sophisticated communication. Quickly find and re.docxPick an animal with sophisticated communication. Quickly find and re.docx
Pick an animal with sophisticated communication. Quickly find and re.docx
 
Pick a real healthcare organization or create your own. Think about .docx
Pick a real healthcare organization or create your own. Think about .docxPick a real healthcare organization or create your own. Think about .docx
Pick a real healthcare organization or create your own. Think about .docx
 
PHYS 102In the Real World” Discussion TopicsYou may choose yo.docx
PHYS 102In the Real World” Discussion TopicsYou may choose yo.docxPHYS 102In the Real World” Discussion TopicsYou may choose yo.docx
PHYS 102In the Real World” Discussion TopicsYou may choose yo.docx
 
Photosynthesis and Cellular RespirationCellular respiration .docx
Photosynthesis and Cellular RespirationCellular respiration .docxPhotosynthesis and Cellular RespirationCellular respiration .docx
Photosynthesis and Cellular RespirationCellular respiration .docx
 
Philosophy of Inclusion Research SupportIt is not enough to simp.docx
Philosophy of Inclusion Research SupportIt is not enough to simp.docxPhilosophy of Inclusion Research SupportIt is not enough to simp.docx
Philosophy of Inclusion Research SupportIt is not enough to simp.docx
 
PHYSICS DATA SHEET.docx
PHYSICS DATA SHEET.docxPHYSICS DATA SHEET.docx
PHYSICS DATA SHEET.docx
 
Physical Assessment Reflection Consider your learning and gr.docx
Physical Assessment Reflection Consider your learning and gr.docxPhysical Assessment Reflection Consider your learning and gr.docx
Physical Assessment Reflection Consider your learning and gr.docx
 
Phonemic Awareness TableTaskScriptingDescription and.docx
Phonemic Awareness TableTaskScriptingDescription and.docxPhonemic Awareness TableTaskScriptingDescription and.docx
Phonemic Awareness TableTaskScriptingDescription and.docx
 
Philosophy 2582 - Media Ethics Paper 1 (Noam Chomsky) 
.docx
Philosophy 2582 - Media Ethics Paper 1 (Noam Chomsky) 
.docxPhilosophy 2582 - Media Ethics Paper 1 (Noam Chomsky) 
.docx
Philosophy 2582 - Media Ethics Paper 1 (Noam Chomsky) 
.docx
 
Pick a large company you like. Find their Statement of Cash Flow.docx
Pick a large company you like. Find their Statement of Cash Flow.docxPick a large company you like. Find their Statement of Cash Flow.docx
Pick a large company you like. Find their Statement of Cash Flow.docx
 
Philosophy 7 Asian Philosophy (Fall 2019) Paper Guidelines .docx
Philosophy 7 Asian Philosophy (Fall 2019) Paper Guidelines .docxPhilosophy 7 Asian Philosophy (Fall 2019) Paper Guidelines .docx
Philosophy 7 Asian Philosophy (Fall 2019) Paper Guidelines .docx
 
PIC.jpga.zipAPA.pptAPA Style--Review.docx
PIC.jpga.zipAPA.pptAPA Style--Review.docxPIC.jpga.zipAPA.pptAPA Style--Review.docx
PIC.jpga.zipAPA.pptAPA Style--Review.docx
 
PHIL101 B008 Win 20 ! # AssignmentsAssignmentsAssignmen.docx
PHIL101 B008 Win 20  !  # AssignmentsAssignmentsAssignmen.docxPHIL101 B008 Win 20  !  # AssignmentsAssignmentsAssignmen.docx
PHIL101 B008 Win 20 ! # AssignmentsAssignmentsAssignmen.docx
 
Phase 3 Structured Probl.docx
Phase 3 Structured Probl.docxPhase 3 Structured Probl.docx
Phase 3 Structured Probl.docx
 
Phil 2101 Final PaperGuidelines Approximately 5 pages, doubl.docx
Phil 2101 Final PaperGuidelines Approximately 5 pages, doubl.docxPhil 2101 Final PaperGuidelines Approximately 5 pages, doubl.docx
Phil 2101 Final PaperGuidelines Approximately 5 pages, doubl.docx
 
Perspectives on WarInstructionsAnalyze After watching .docx
Perspectives on WarInstructionsAnalyze After watching .docxPerspectives on WarInstructionsAnalyze After watching .docx
Perspectives on WarInstructionsAnalyze After watching .docx
 
pestle research for chile bolivia paraguay uruguay .docx
pestle research for chile bolivia paraguay uruguay .docxpestle research for chile bolivia paraguay uruguay .docx
pestle research for chile bolivia paraguay uruguay .docx
 
Pg. 04Question Four Assignment 2Deadline Saturd.docx
Pg. 04Question Four Assignment 2Deadline Saturd.docxPg. 04Question Four Assignment 2Deadline Saturd.docx
Pg. 04Question Four Assignment 2Deadline Saturd.docx
 

Recently uploaded

ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayMakMakNepo
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........LeaCamillePacle
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up Friday
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 

assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx

  • 1. assignmentTwo/Car.javaassignmentTwo/Car.javapackage assign mentTwo; // incomplete starter code for assignment two programming 1, se m 2 2014 // author: Kathleen Keogh version 1, incomplete. September 20 14 publicclassCarextendsVehicle{ // instance variables privateint numSeats, numDoors; privateboolean hatch, tintedWindows; publicCar(){ } publicCar(int _numSeats,int _numDoors,boolean _hatch,boolean _tintedWindows){ // insert appropriate initialisation code here based on the parame ters provided } // get and set methods for each car instance variable publicint getNumSeats(){ return numSeats; } publicboolean setNumSeats(int _numSeats){ returntrue;// change this based on validation } publicint getNumDoors(){ return1;// change this to return appropriate value
  • 2. } publicvoid setNumDoors(){ } publicboolean getHatch(){ returntrue;// change this to return the appropriate value } publicvoid setHatch(boolean _hatch){ } publicboolean getTintedWindows(){ returntrue;// update this to return the appropriate value } publicvoid setTintedWindows(boolean _tintedWindows){ } // toString method publicString toString(){ // insert code here to appropriately return a string of data for thi s car, use superclass methods where appropriate return("Car. Make "+ getMake());// change this to return more t han just the make } } assignmentTwo/Garage.javaassignmentTwo/Garage.javapackage assignmentTwo; // Author, Version 1. Starter Code: Kathleen Keogh September 2
  • 3. 014 // Author, Version 2. : // Garage class is for a garage that contains a number of vehicle s publicclassGarage{ //instance variables Vehicle vehicleList[]; int maxVehicles=10;// default maximum number of vehicles is 1 0 int currsize; publicGarage(){// constructor with no parameters vehicleList =newVehicle[maxVehicles]; currsize=0; } publicGarage(int _numMaxVehicles){// constructor with one par ameter - maximum number of vehicles for garage maxVehicles = _numMaxVehicles; vehicleList =newVehicle[maxVehicles]; currsize =0; } // TODO: add get and set methods // TODO: add toString() method // TODO: add other methods including addVehicle, sortVehicles } assignmentTwo/Rectangle.javaassignmentTwo/Rectangle.javapa ckage assignmentTwo;
  • 4. publicclassRectangleextendsShapes{ double length, width;// extra instance variables associated with Rectangle particularly publicRectangle(){// constructor to create an 'empty' triangle super("","",0,0); length =0.0;//initialise length and width to zero for new re ctangle width =0.0; } publicRectangle(double initLength,double initWidth,String init Name,String initColour,double xCoord,double yCoord){ super(initName, initColour, xCoord, yCoord);// use constructor from super class: Shapes setLength(initLength);// initialise length to provided value setWidth(initWidth); } publicboolean setLength(double _length){// mutator method to s et length to new value if(_length >0.0){// validate length is positive value greater than zero length = _length; returntrue; } elsereturnfalse; } publicboolean setWidth(double _width){// mutator method to se t width to new value if(_width >0.0){// validate width is positive value greater than z ero width = _width; returntrue;
  • 5. } elsereturnfalse; } publicdouble getWidth(){ return width; } publicdouble getLength(){ return length; } publicdouble calcArea (){ return length * width; } publicdouble getArea(){ return calcArea(); } publicString toString(){ return("Rectangle "+ getName()+" Colour "+ getColour()+" Are a "+ getArea()+" located at "+ getXcoord()+" "+ getYcoord()); } } assignmentTwo/Shapes.javaassignmentTwo/Shapes.javapackage assignmentTwo; publicclassShapes{ privateString name; privateString colour; privatedoubleXcoord;
  • 6. privatedoubleYcoord; publicShapes(){ name =newString(""); colour =newString(""); Xcoord=0.0; Ycoord=0.0; } publicShapes(String initName,String initColour,double initXcoo rd,double initYcoord){ name =newString(initName); colour =newString(initColour); setXcoord(initXcoord); setYcoord(initYcoord); } publicvoid setName (String newName){ name =newString(newName); } publicboolean setXcoord(double newXcoord){ if(newXcoord >0.0){ Xcoord= newXcoord; returntrue; } elsereturnfalse; } publicboolean setYcoord(double newYcoord){ if(newYcoord >0.0){ Ycoord= newYcoord; returntrue; } elsereturnfalse; }
  • 7. publicvoid setColour (String newColour){ colour =newString(newColour); } publicdouble getXcoord (){ returnXcoord; } publicdouble getYcoord (){ returnYcoord; } publicString getName (){ return name; } publicString getColour (){ return colour; } publicdouble getArea (){ return0.0;//dummy method will be overridden in extended classe s } } assignmentTwo/ShapesList.javaassignmentTwo/ShapesList.java package assignmentTwo; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; publicclassShapesList{ staticfinalint MAXSIZE =10;
  • 8. Shapes myList[];// ShapesList contains multiple Shapes (up to MAXSIZE) int currsize =0; publicShapesList(){// default constructor create a shapes list of MAXSIZE size myList =newShapes[MAXSIZE]; currsize =0; } publicShapesList(int _maxsize){// constructor to create a shapes list of max size given myList =newShapes[_maxsize]; currsize =0; } publicvoid addShape(Shapes _newShape){ if(currsize < MAXSIZE){ myList[currsize++]= _newShape; } elseSystem.out.println("shape list is full"); } publicString toString(){ String result =""; for(int i =0; i < currsize; i++) result = result + myList[i].toString()+"; rn"; return(result); } publicvoid bubbleSort(){// sort shapes based on Area of shape Shapes tempShape; /* * pseudo code for bubble sort: * for index1 in range(len(sList) -1):
  • 9. * for index2 in range (len(sList) - (index1 + 1)): * if (sList[index2] > sList[index2 + 1]): * swapListPositions (sList, index2, index2 + 1) * */ for(int i =0; i <(currsize -1); i++) { for(int j =0; j <(currsize -(i +1)); j++) { if(((myList[j]).getArea())>((myList[j +1]).getArea())) { tempShape = myList [j +1]; myList [j +1]= myList [j]; myList [j]= tempShape; } } } } publicvoid exportToFile (String outputString){ System.out.println("about to open export file"); try{ BufferedWriter output; File file =newFile("export.txt"); System.out.println(file.getAbsolutePath()); output =newBufferedWriter(newFileWriter(file)); output.write(outputString); output.newLine(); System.out.println("just wrote to file"); output.close(); } catch(IOException e){ System.out.println("IO Error with file export"); e.printStackTrace();
  • 10. } } publicvoid readFromFile(){ int numAdded=0; File inputfile; inputfile =newFile("ShapesFile.txt"); try{ Scanner inputScanner =newScanner(inputfile); while(inputScanner.hasNextLine()){ //Read the shapes details from the file String type = inputScanner.next(); switch(type){ case"square":{ System.out.println("processing a square..."); Square newSq =newSquare(); newSq.setName(inputScanner.next()); newSq.setColour(inputScanner.next()); newSq.setSide(inputScanner.nextDouble()); newSq.setXcoord(inputScanner.nextDouble()); newSq.setYcoord(inputScanner.nextDouble()); addShape(newSq); break; } case"rectangle":{ System.out.println("processing a rectangle..."); Rectangle newRect =newRectangle(); newRect.setName(inputScanner.next()); newRect.setColour(inputScanner.next()); newRect.setLength(inputScanner.nextDouble()) ; newRect.setWidth(inputScanner.nextDouble()); newRect.setXcoord(inputScanner.nextDouble()) ;
  • 11. newRect.setYcoord(inputScanner.nextDouble()) ; addShape(newRect); } } } inputScanner.close(); } catch(IOException e){ System.out.println("IO Exception reading shapes from file"); e.printStackTrace(); } } } assignmentTwo/Square.javaassignmentTwo/Square.javapackage assignmentTwo; publicclassSquareextendsShapes{ double side; publicSquare(){//create 'empty' square object with zero coord va lues and "" for Strings name and colour super("","",0,0); side =0.0;//initialise side to zero for new square } publicSquare(double initside,String initName,String initColour, double xCoord,double yCoord){ super(initName, initColour, xCoord, yCoord);// use constructor from super class: Shapes setSide(initside);// initialise length to provided value }
  • 12. publicvoid setSide (double newSide){ side = newSide; } publicdouble calcArea (){ return side * side;// area of Square is side * side } publicdouble getArea (){ return calcArea(); } publicString toString(){ return("Square "+ getName()+" Colour "+ getColour()+" Area " + getArea()+" located at "+ getXcoord()+" "+ getYcoord()); } } assignmentTwo/TestClass.javaassignmentTwo/TestClass.javapa ckage assignmentTwo; // author, version 1: Kathleen Keogh September 2014. Version 1 is incomplete, provides stubs for some methods // This test class is used to test the Garage system for assignmen t 2, Programming 1, Sem 2 2014. // author, version 2: publicclassTestClass{ publicTestClass(){// constructor for TestClass }
  • 13. publicvoid runtest1(){ // first test case // create a car object and test that it is working Car myTestCar =newCar(); System.out.println(myTestCar.toString()); } publicvoid runtest2(){ // second test case // create another vehicle object and test that it is working } publicvoid runtest3(){ // third test case // create a garage object with a number of vehicles in the garage , then print it out to test it worked } publicstaticvoid main(String[] args){ // TODO write code here to invoke test methods to test the Gar age system TestClass mytest =newTestClass(); System.out.println("Running test1... "); mytest.runtest1(); System.out.println("Running test2... "); mytest.runtest2(); System.out.println("Running test3... "); mytest.runtest3(); } }
  • 14. assignmentTwo/TestingShapesListClass.javaassignmentTwo/Tes tingShapesListClass.javapackage assignmentTwo; // this testing class is used to test classes : ShapesList, Rectangl e, Square, Shapes. publicclassTestingShapesListClass{ //instance reference variable to point to a shapes list object used in testing ShapesList shList; publicTestingShapesListClass(){ shList =newShapesList();// create a shapes list object to us e in testing } publicSquare testrun1a (){ Square s =newSquare(4.0,"mySquare","Blue",3.0,10.0); System.out.println(s.toString()); return s; } publicSquare testrun1b (){ Square s1 =newSquare();// test empty constructor s1.setName("Anothersquare");// use set methods to set val ues for instance variables s1.setSide(5.0); s1.setColour("Red");// test set methods to change values of colour and coords s1.setXcoord(4.0); s1.setYcoord(20.0); System.out.println(s1.toString()); return s1; }
  • 15. publicRectangle testrun2 (){ // create a rectangle shape and print it out Rectangle r =newRectangle(2.0,6.0,"rectangle","Orange",5.0,10. 0); System.out.println(r.toString()); return r; } publicvoid testrun3(Square _s,Square _s1,Rectangle _r){ // test adding 3 shapes to the shapes list System.out.println("My list of Shapes"); shList.addShape(_s); shList.addShape(_s1); shList.addShape(_r); System.out.println(shList.toString()); } publicvoid testrun4(){ // test reading shapes from file and adding to shapes list shList.readFromFile(); } publicvoid testrun5(){ // test sorting list of shapes shList.bubbleSort(); System.out.println("My list of sorted Shapes"); System.out.println(shList.toString()); } publicvoid testrun6(){ // test exporting shapes list to a file shList.exportToFile(shList.toString()); } publicstaticvoid main (String[] args){
  • 16. TestingShapesListClass t =newTestingShapesListClass(); Square testSquare1 = t.testrun1a(); Square testSquare2 = t.testrun1b(); Rectangle testRectangle = t.testrun2(); t.testrun3(testSquare1, testSquare2, testRectangle); t.testrun4(); t.testrun5(); t.testrun6(); } } assignmentTwo/Vehicle.javaassignmentTwo/Vehicle.javapackag e assignmentTwo; publicclassVehicle{ //instance variables privateString make, model, registration, vinNum; privateint yearOfManufacture; publicVehicle(){// empty constructor // code to initialise values to "" and 0 goes here } // constructor with initialisation values publicVehicle(String _make,String _model,String _registration, String _vinNum,int _yearOfManufacture ){ } // get and set methods for instance variables publicvoid setMake(String _make){ }
  • 17. publicString getMake(){ return"";// change this to return appropriate value } publicvoid setModel(String _model){ } publicString getModel(){ return"";// change this to return appropriate value } publicvoid setRegistration(String _registration){ } publicString getRegistration(){ return"";// change this to return appropriate value } //vin num publicvoid setVinNum(String _vinNum){ } publicString getVinNum(){ return"";// change this to return appropriate value } // year of manufacture publicvoid setYearOfManufacture(int _year){ } publicint getYearOfManufacture(){
  • 18. return1;// change this to return appropriate value } } ITECH1000 5000 Programming 1_Assignment2Specification 2014-20.pdf 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 relate d 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:
  • 19. jects of these classes 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: electronic copy of this assignment specification sheet A sample program with similar features to the assignment requir ements involving multiple classes Starting (incomplete) code for four of the classes to be develope d 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 b ooks. 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 be fore loop execution.
  • 20. Use a for‐loop when the number of iterations is known before lo op execution. Indent your code correctly to aid readability and use a consisten t curly bracket placement scheme. white space to make your code as readable as possible. Validation of input should be limited to ensuring that the user h as entered values that are within correct bounds. You do not have to check that they have entered the co rrect data type. 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.
  • 21. Draw a UML diagram of each of the Shapes, Rectangle and Squ are classes using the code that has been provided. Complete this using the examples that have been pro vide in the lecture slides. 2. Draw a UML diagram of the ShapesList class using the code tha t 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 expl ain 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 read FromFile() 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 ho w it works, using an example. Why do we need to use two for loops? 6. Briefly name and describe one other sorting algorithm that coul
  • 22. d have been used. 7. Explain the use of the return value in the getArea() method in th e Rectangle class. What is it returning? Where does the value come from? 8. Examine the lines to open the output file and write the outputStr ing 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 Ja va API documentation and describe the use of this object. 9. Examine the code in the exportToFile method. What is the pur pose of the ‘rn’ 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. R e‐add the line and investigate what happens if the input file is not present.
  • 23. 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 to String() as indicated in the UML diagram. 4. Ensure that your Vehicle class includes the following validation within the mutator (set) methods: a.
  • 24. 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
  • 25. + 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
  • 26. 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 classe s 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 t he mutator (set) methods: a. numSeats cannot be less than two. If an attempt is made to set t he 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.
  • 27. 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 e quality 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 t he data attributes for each car. Write a class called TestClass (starter code is provided to copy from) and wit hin the main method write code that will : a. Instantiate an instance of the Car class for one of the Cars you s elected 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 yearOfManufactu re of the first Car by 5 years. d. Instantiates an instance of the Class Car for a second different C ar contained in the table below using
  • 28. the Car(make:String, model:String, registration: String, vinNum ber: String, yearOfManufacture: int, numSeats:int, numDoors: int, hatch: boolean, tintedWindows: b oolean,manual: boolean) constructor e. Display both of the Cars that you have created using the toStrin g() 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
  • 29. - 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
  • 30. 6. Now create a second class representing another vehicle (e.g. bik e, trailer, caravan, truck, or tractor etc.) in a similar fashion to the way you created the car class. (The car cla ss is similar to the square class in the sample code provided. The square class extends the Shapes class. The R ectangle 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 particul ar 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. Tr actor.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 usin g a set method then display the object CRICOS Provider No. 00103D ITECH 1000 Programming 1
  • 31. 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()
  • 32. + 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 Writ e get and set methods as well as an addVehicle method. 2. Create a method for sorting the Vehicles in the Garage (model t his 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 add Vehicle() method c. Add at least two other vehicles (e.g. Tractor or Bike) to the Gar age 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 tha t you have created
  • 33. 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 exampl es of similar code to the code you will need in your TestClass. In TestingShapesListClass, Shapes are added to a Sh apesList 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:
  • 34. 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 – 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 the data of all vehicles in the garage, using your toString() method on the Garage object. 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: – 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.
  • 35. – save the data to a new file ExportData.txt Assignment Submission The following criteria will be used when marking your assignme nt: completion of the required tasks quality of code that adheres to the programming standards for th e course; including: comments and documentation code layout meaningful variable names You are required to provide documentation, contained in an app ropriate file, which includes: a front page ‐ indicating your name, a statement of what has bee n 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 assist ed you with table of contents and page numbers 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 yo ur testing
  • 36. 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.p df 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
  • 37. CRICOS Provider No. 00103D Appendix gar vehi car D ITECH 100 x Figure 4. U rage icle 00 Programming 1 As co is
  • 38. UML Class Di ssignment 2 Specific ontains A iagram for th cation Semester 2, 20 he Garage sy 014 ystem Page 99 of 9 ShapesFile.txt square mybestsquare purple 6.0 1.0 5.0 square mylastsquare green 7.0 3.0 4.0 rectangle myfirstrectangle aqua 8.0 3.0 2.5 6.5