Question
Vehicle part 2. I have done part 1, but are struggling with part 2. This task has the following elements that are relevant to the
Vehicle part 2.
I have done part 1, but are struggling with part 2.
This task has the following elements that are relevant to the learning outcomes of this module:
- be able to create and use abstract classes - be able to use the classes Calendar and GregorianCalendar - be able to define common behavior for objects using interface - be able to define interfaces and classes that implement these - be able to use the Comparable and Cloneable interfaces - have knowledge of version control systems with special focus on GIT - could use the most common GIT methods in connection with program development
You will continue to develop a console-based system that records vehicle information. Now add functionality to sort vehicles by price and to clone them. This task constitutes the second part of the GIT task and will be developed in branch "part2" remember to push it to your repository and then merge the master with it before continuing with the next task.
The program should be developed gradually and in the second part you will:
- Vehicle:
- Add new data member, Calendar buyingDate, who states when the vehicle was purchased (set it to the current date in the designer for simplicity).
- Implement Comparable
and Cloneable Interfaces in the Vehicle Class. - Comparable should compare vehicles by price.
- Cloneable should call super.clone () to get a shallow copy of the object and then it must clone all "mutable" objects the class contains to get a deep copy. Mutable objects are objects that can be changed without creating a new copy of them, String is immutable, while Calendar is mutable.
- TestVehicles:
- Must get an additional choice "Test clone method" to test the clone method. This test can be hard-coded, it must create a new car, make a copy of it and then change the date on one car object without changing the date in the other object. Print both car items with date fields as verification.
Example of the application's print is:
1 ................................... New car 2 ........... .................... New bicycle 3 ...................... Find vehicle by name 4 .............. Show data about all vehicles 5 ....... Change direction of a given vehicle 6 ................ ......... Test clone method 7 .............................. Exit program ..... ........................ Your choice? 6 Date objects are separate, deep copy. 2018-01-29 2018-02-10
UML Chart for Class:
GVehicle 0 colour Cloneable String String String int int int double Calendar O Comparable serialNr O& model compareTo(T) Int & price O a direction speed o buyingDate Or input @ Vehicle() o - Vehicle(String. String, int, int, String, int Scanner e Bicycle G Car gears int Calendar O& productionDate SetAlIFlelds() Oa productionDate Calendar vold void void String String Bicycle) Bicycle(String, String, int, int, String, int, int) SetAlIFields( turnRight(int) turnLeft(int) getGears) getProductionDate) setGears(int) setProductionDate(Calendar) clone() toString) b turnLeft(int) Car(String, String, int, int, String, int, int) setAllFields(0 turnRight(int) turnLeftint getPower) getProductionDate() setPower(int) setProductionDate(Calendar) clone) turnRight(int) getName() void void void int Calendar vold void Object String void m getPrice) int vold getModel() getSerialNr() getDirectiono String Irvi double String Calendar vold vold Object String O getspeedo getBuyingDate) setName(String) void OtoStringo OsetColourtString setPrice(int) setModel(int) setSerialNr(String) setDirection(int) void vold vold int o setspeed double) setBuyingDate(Calendar) compareTo(Vehicle) clone) Object O toStringo String Powered by yFiles
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started