Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

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 Systems For Advanced Applications 18th International Conference Dasfaa 2013 Wuhan China April 22 25 2013 Proceedings Part 2 Lncs 7826

Authors: Weiyi Meng ,Ling Feng ,Stephane Bressan ,Werner Winiwarter ,Wei Song

2013th Edition

3642374492, 978-3642374494

More Books

Students also viewed these Databases questions

Question

Write the difference between sexual and asexual reproduction.

Answered: 1 week ago

Question

What your favourite topic in mathematics?

Answered: 1 week ago

Question

1. Identify six different types of history.

Answered: 1 week ago

Question

2. Define the grand narrative.

Answered: 1 week ago

Question

4. Describe the role of narratives in constructing history.

Answered: 1 week ago