Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Vehicle part 4. its bulilding on part 3. Here are the UML diagram. Vehicle: Implement Fileable interface. Implement the writeData (PrintWriter out) method, it should

Vehicle part 4. its bulilding on part 3. Here are the UML diagram.

image text in transcribed

  • Vehicle:
    • Implement Fileable interface.
    • Implement the writeData (PrintWriter out) method, it should be used to write comma separated values in all class members to file.
    • Implement the readData (Scanner in) method, it should be used to read comma separated values from file and assign them to class members.
  • Car and Bicycle:
    • They will overwrite the two aforementioned methods and add functionality to write / read their own class members.
  • TestVehicles:
    • When the program starts, all vehicles that were stored should be read from file and added to the ArrayList object, when the program ends, all vehicles must be sorted and written to file.
    • When writing to file it must be taken care of whether it is a Car or Bicycle object being written, here you can use the object class method getClass (). GetName () - it will return the name of the class. When reading, this name must be read in and an object of this type must be created, here methods must be used in Class as shown below.

      Scanner in = new Scanner (file) .Local (Locale.US); in.useDelimiter ( ","); String vehClass = in.next (); // reads the class name from the class veh1 = Class.forName (vehClass) file ; // creates Class object for specified class name (String) Vehicle veh = (Vehicle) veh1.newInstance (); // creates new instance of Vehicle

    • Example of the application's print is:

      Vehicle read from file: Name: Monark 1 Color: yellow Price: 4000 Model: 1993 Serial #: BC100 Direction: 0 Speed: 0.00 Buying date: 1993-01-20 Gears: 10 Production date: 2017-12-29 Vehicle read from file: Name: DBS 2 Color: pink Price: 5000 Model: 1994 Serial #: 42 Direction: 0 Speed: 0.00 Buying date: 1995-07-24 Gears: 10 Production date: 2017-11-21 Vehicle read from file: Name : Volvo 740 Color: blue Price: 85000 Model: 1985 Serial #: 1010-11 Direction: 0 Speed: 0.00 Buying date: 1988-09-04 Power: 120 Production date: 2017-03-05 Vehicle read from file: Name: TestCar Color: Indigo Price: 123456 Model: 2018 Serial #: 69-420 Direction: 0 Speed: 0.00 Buying date: 2018-01-29 Power: 240 Production date: 2018-01-29 Vehicle read from file: Name: Testarossa Color: red Price: 1200000 Model: 1996 Serial #: A112 Direction: 0 Speed: 0.00 Buying date: 1997-05-15 Power: 350 Production date: 2018-01-12 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 .................. Test driveable interface 8 ................... ........... Exit program ............................. Your choice? 2 Input bicycle data: Name: TestBicycle Color: Maroon Price: 12345 Model: 1234 Serial #: 69-42 Gears: 12 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 .................. Test driveable interface 8 ...... ........................ Exit program ........................ ..... Your choice? 8 Vehicle written to file: Name: Monark 1 Color: yellow Price: 4000 Model: 1993 Serial #: BC100 Direction: 0 Speed: 0.00 Buying date: 1993-01-20 Gears: 10 Production date: 2017-12-29 Vehicle written to file: Name: DBS 2 Color: pink Price: 5000 Model: 1994 Serial #: 42 Direction: 0 Speed: 0.00 Buying date: 1995-07-24 Gears: 10 Production date: 2017-11-21 Vehicle written to file: Name: TestBicycle Color: Maroon Price: 12345 Model: 1234 Serial #: 69-42 Direction: 0 Speed: 0.00 Buying date: 2018-01-29 Gears: 12 Production date: 2018-01-29 Vehicle written to file: Name: Volvo 740 Color: blue Price: 85000 Model: 1985 Serial #: 1010-11 Direction: 0 Speed: 0.00 Buying date: 1988-09-04 Power: 120 Production date: 2017-03-05 Vehicle written to file: Name : TestCar Color: Indigo Price: 123456 Model: 2018 Serial #: 69-420 Direction: 0 Speed: 0.00 Buying date: 2018-01-29 Power: 240 Production date: 2018-01-29 Vehicle written to file: Name: Testarossa Color: red Price: 1200000 Model: 1996 Serial #: A112 Direction: 0 Speed: 0.00 Buying date: 1997-05-15 Power: 350 Production date: 2018-01-12
    • Fileable interface:
      import java.io.IOException ; import java.io.PrintWriter ; import java.util.Scanner ; public interface Fileable { void writeData ( PrintWriter out ) throws IOException ; void readData ( Scanner in ) throws IOException ; }
    • UML Chart for Class:
    • image text in transcribed
CVehicle Cloneable Driveable colour name serialNr model StringMAX SPEED_CAR double StringMAX SPEED_BIKE double vold void void Comparable compareTo(T) int accelerate(int) intbreaks(int) ce O direction double buyingDate Scanner G Bicycle & gears Vehicle) int 0b Vehicle(string, string, int, int, String, int) a productionDate Calendar Oa productionDate setAllFields() turnLeft(int) turnRight(int) stop) getName OBicycle Bicycle(String, String, int, int, String, int, int) setAllFields() turnRight(int Car() Car(String, String, int, int, String, int, int) setAlIFields0 vold vold turnRight(int) 0b turnLeft(int) turnLeft(int) accelerate(int) breaks(int) getPower() void vold accelerate(int) breaks(int) getGears) getProductionDate) setGears(int) setProductionDate(Calendar) OgetPrice) int int String getModel0) Int int Ob getSerialNr() Calendar b getProductionDate() Calendar getDirection) getSpeed) getBuyingDate(0 setName(String) setColour(String) setPrice(int) setPower(int) setProductionDate(Calendar) clone() toString double void mclone() Object irI vold void void toString) msetModel(int) setSerlalNr(String) setDirection(int) vold OsetSpeed(double) setBuyingDate(Calendar) compareTo(Vehicle) clone0 tostring() void void int Object Powered by yFiles Vehicle Driveable MAX_SPEED_CAR double MAX_SPEED BIKE double accelerate(int) breaks(int) Cloneable colour String StringM serlalNr model Stingaccelerateint) void Comparable compareTo(T) int Vo stopO O& direction IrIi O speed Oa buyingDate double Calendar Scanner G Bicycle Vehicle Vehicle(String, String, Int, Int, String, Int) SetAllFields) turnLeft(int) turnRight(int) int rs O productionDate Calendar productionDate Bicycle) Bicycle(String, String, int, int, String, int, int) setAllFields() turnRight(int) turnLeft(int) accelerate(int) breaks(int) writeData(PrintWriter) Calendar void void O Car(String, String, int, int, String, int, int) setAllFields() turnRight(Int) turnLeft(int) accelerate(int) breaks(Int) writeData(PrintWriter) void void void vold void Vo String void vold void writeData(PrintWriter) readData(Scanner) getName) getcolour getPrice) getModelo) getserlalNrO) getDirection) getspeed() getBuyingDate) setName(String) vold void String void iri O readData(Scanner) O readData(Scanner) O-getGears() DgetProductionDate() 0% setGears(int) setProductionDate(Calendar) mclone) int getPower) getProductionDate() setPower(int) setProductionDate(Calendar) String liti Calendar void vold String void Object String toString) toString0 setColour(String) setPrice(Int) setModel(int) setSerialNr(String) setDirection(int) setspeed(double) setBuyingDate(Calendar) compareTo(Vehicle vold void Vo vold void Fileable writeData(PrintWriter) vold C%readData(Scanner) vold ' clone) toString) Powered by yFiles CVehicle Cloneable Driveable colour name serialNr model StringMAX SPEED_CAR double StringMAX SPEED_BIKE double vold void void Comparable compareTo(T) int accelerate(int) intbreaks(int) ce O direction double buyingDate Scanner G Bicycle & gears Vehicle) int 0b Vehicle(string, string, int, int, String, int) a productionDate Calendar Oa productionDate setAllFields() turnLeft(int) turnRight(int) stop) getName OBicycle Bicycle(String, String, int, int, String, int, int) setAllFields() turnRight(int Car() Car(String, String, int, int, String, int, int) setAlIFields0 vold vold turnRight(int) 0b turnLeft(int) turnLeft(int) accelerate(int) breaks(int) getPower() void vold accelerate(int) breaks(int) getGears) getProductionDate) setGears(int) setProductionDate(Calendar) OgetPrice) int int String getModel0) Int int Ob getSerialNr() Calendar b getProductionDate() Calendar getDirection) getSpeed) getBuyingDate(0 setName(String) setColour(String) setPrice(int) setPower(int) setProductionDate(Calendar) clone() toString double void mclone() Object irI vold void void toString) msetModel(int) setSerlalNr(String) setDirection(int) vold OsetSpeed(double) setBuyingDate(Calendar) compareTo(Vehicle) clone0 tostring() void void int Object Powered by yFiles Vehicle Driveable MAX_SPEED_CAR double MAX_SPEED BIKE double accelerate(int) breaks(int) Cloneable colour String StringM serlalNr model Stingaccelerateint) void Comparable compareTo(T) int Vo stopO O& direction IrIi O speed Oa buyingDate double Calendar Scanner G Bicycle Vehicle Vehicle(String, String, Int, Int, String, Int) SetAllFields) turnLeft(int) turnRight(int) int rs O productionDate Calendar productionDate Bicycle) Bicycle(String, String, int, int, String, int, int) setAllFields() turnRight(int) turnLeft(int) accelerate(int) breaks(int) writeData(PrintWriter) Calendar void void O Car(String, String, int, int, String, int, int) setAllFields() turnRight(Int) turnLeft(int) accelerate(int) breaks(Int) writeData(PrintWriter) void void void vold void Vo String void vold void writeData(PrintWriter) readData(Scanner) getName) getcolour getPrice) getModelo) getserlalNrO) getDirection) getspeed() getBuyingDate) setName(String) vold void String void iri O readData(Scanner) O readData(Scanner) O-getGears() DgetProductionDate() 0% setGears(int) setProductionDate(Calendar) mclone) int getPower) getProductionDate() setPower(int) setProductionDate(Calendar) String liti Calendar void vold String void Object String toString) toString0 setColour(String) setPrice(Int) setModel(int) setSerialNr(String) setDirection(int) setspeed(double) setBuyingDate(Calendar) compareTo(Vehicle vold void Vo vold void Fileable writeData(PrintWriter) vold C%readData(Scanner) vold ' clone) toString) Powered by yFiles

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

More Books

Students also viewed these Databases questions

Question

What do you mean by dual mode operation?

Answered: 1 week ago

Question

Explain the difference between `==` and `===` in JavaScript.

Answered: 1 week ago