Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

complete CarTester please ! 2. [2.5 pts] Consider the class Car that implements Serializable. The Car class has three attributes plateNumber, make, and price. -

complete CarTester please !

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.ArrayList;

public class CarTester {

public CarTester() {

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 "theCars" to the file "carsfile" as objects.

CarRepo.writeToObjFile("carsfile", cars); //Read the cars objects from the file "carsfile" into the list "theCars" ArrayList theCars; theCars = CarRepo.readFromObjFile("carsfile"); for(Car c : theCars) { System.out.println(c.toString()); } //modify some the second car object by adding 2000 to the price. theCars.get(1).setPrice(theCars.get(1).getPrice()+2000); //write the data of the cars objects of the list "theCars" to a text file "carsfile.txt"

CarRepo.writeToTextFile("carsfile.txt", theCars);

//Read the data of the cars object from the text file "carsfile.txt" into the list theCars2.

ArrayList theCars2 = CarRepo.readFromTextFile("carsfile.txt");

//Add the car objects of the list "theCars2" to the list "theCars"

for(Car c : theCars2) { theCars.add(c); } //Display the contents of the list "theCars". for(Car c : theCars) {

System.out.println(c.toString()); } }

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_2

Step: 3

blur-text-image_3

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2019 Wurzburg Germany September 16 20 2019 Proceedings Part 2 Lnai 11907

Authors: Ulf Brefeld ,Elisa Fromont ,Andreas Hotho ,Arno Knobbe ,Marloes Maathuis ,Celine Robardet

1st Edition

3030461467, 978-3030461461

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

Briefly describe vegetative reproduction in plants.

Answered: 1 week ago