Question: ( follow the comments ) here is the code that you should use and fix it to get the output in the picture import java.util.ArrayList;
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 Car Tester class and accordingly write the required code in class CarRep. Compile and run the code. You should have this output: inport java.util. Arraylist; public class Cartester \{ public CartesterO \{ Arraylist cars = nen Arraylist clar>O; cars. add(new Car("A123", "Toyota", 5eeee)); cars, add(new Car ("B123", "Hondo", 40000)); cars, add(new Car("C123", "Nissan", 6e000)); cars, add(nen Car("D123", "Ford", 3ese0)); I/Write the objects of the list "theCars" to the file. "carsfile" as objects. Carkepo, writeToobjfiled"carsfile", cars): //Read the cars objects from the file "corsfile" into the list "theCars" Arraylist theCars; theCars = CarRepo, readfranobjFile("carsfile"); for(Car c : the Cars) \{ 3 System, aut, println(c.toString O) ): 1/ modify some the second car object by adding 2000 to the price. theCars, get(1), setPrice(theCars, get(1).getPriceO+20ee): //write the data of the cars objects of the list "theCars" to a text file "carsfile.txt" CarRepo, writeTofextfile "carsfile. tat", thetars); //Read the dota of the cars object from the text file "corsfile. txt" into the list theCarsz. ArrayListeCars theCars2 - Carkepo. readfronfextfile("carsfile. txt"): //Add the cor objects of the list "theCars2" to the list "theCars" for(Car-c : the Cars2) f the Cars.add(c): 3 /roisplay the contents of the list "theCars". for(Car c : the(ars) \{ System, out, println(c,tostring ()) : 3 3 public static void main(String args) \& new CarTester(); 3
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
