Answered step by step
Verified Expert Solution
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.
- 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:
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