Answered step by step
Verified Expert Solution
Question
1 Approved Answer
2. [2.5 pts] Consider the class Car that implements Serializable. The Car class has three attributes plateNumber, make, and price. - Use the following code
2. [2.5 pts] Consider the class Car that implements Serializable. The Car class has three attributes plateNumber, make, and price. - Use the following code of the CarTester class and accordingly write the required code in class CarRep. - Compile and run the code. You should have this output: import java util_Arravlisti public class GarTester \{ public CarTesterf) \& Arraylist cars = new Arraylist(); cars.add(new Car("A123", "Toyota", 50000)); cars.add(new Car("B123", "Honda", 40000)); cars.add(new Car("C123", "Nissan", 60000)); cars.add(new Car("D123", "Ford", 30000)); //Write the objects of the list "theGars" to the file "Garsfile" as objects. CarRegow writeToQbiEile("carsfile", cars); // Read the cars objects from the file "carsfile" into the list "the Cars" Arraylisk theGars; theCars = CarRepo, read Erom QbiFile("carsfile"); for(Car c : theGars) \& Sxstem.out.print|n(c.tostring()); \} //modify some the second car object by adding 2000 to the price. the Cars.get(1). setprice(therars.get (1).getprice(1)+2000); //write the data of the cars objects of the list "thecars" to a text file "carsfile.txt" CarReporwriteteTextfile("carsfile.txt", theCars); //Read the data of the cars object from the text file "carsfile.txt" into the list theCars2. Arraylist theCars2 = CarReporvedd fromTextFile("carsfile.txt"); //Add the car objects of the list "theCars2" to the list "theGass" for(Car c : the Cars2) \& theCars.add(c); \} //Display the contents of the list "theCars". for(Car c : theCars) \& System.out.println(c.tostring()); \} 3 public static void main(String[] args) \{ new CarTester(); \}
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