Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Finish the menu program ( in the photo ) connecting the methods in CarLot to the correct menu option. CartLot Program: import java.io . *
Finish the menu programin the photo connecting the methods in CarLot to the correct menu option.
CartLot Program:
import java.io;
import java.util.;
public class CarLot
private ArrayList inventory;
public CarLot
inventory new ArrayList;
public ArrayList getInventory
return inventory;
public void setInventoryArrayList inventory
this.inventory inventory;
public Car findCarByIdentifierString identifier
for Car car : inventory
if cargetIdequalsidentifier
return car;
return null;
public ArrayList getCarsInOrderOfEntry
return new ArrayListinventory;
public ArrayList getCarsSortedByMPG
ArrayList sortedByMPG new ArrayListinventory;
selectionSortsortedByMPG;
return sortedByMPG;
private void selectionSortArrayList sortedByMPG
for int i ; i sortedByMPG.size; i
int minIndex i;
for int j i ; j sortedByMPG.size; j
if sortedByMPGgetjgetMPG sortedByMPG.getminIndexgetMPG
minIndex j;
Car temp sortedByMPG.getminIndex;
sortedByMPG.setminIndex sortedByMPG.geti;
sortedByMPG.seti temp;
public Car getCarWithBestMPG
if inventoryisEmpty
return null;
Car bestMPGCar inventory.get;
for Car car : inventory
if cargetMPG bestMPGCar.getMPG
bestMPGCar car;
return bestMPGCar;
public Car getCarWithHighestMileage
if inventoryisEmpty
return null;
Car highestMileageCar inventory.get;
for Car car : inventory
if cargetMileage highestMileageCar.getMileage
highestMileageCar car;
return highestMileageCar;
public double getAverageMpg
if inventoryisEmpty
return ;
double totalMpg ;
for Car car : inventory
totalMpg car.getMPG;
return totalMpg inventory.size;
public double getTotalProfit
double totalProfit ;
for Car car : inventory
totalProfit car.getSalesPrice car.getCost;
return totalProfit;
public void addCarString id int mileage, int mpg double cost, double salesPrice
inventory.addnew Carid mileage, mpg cost salesPrice;
public void sellCarString identifier, double priceSold
Car car findCarByIdentifieridentifier;
if car null
car.setSalesPricepriceSold;
else
System.out.printlnCar with identifier identifier not found.";
public void saveToDisk throws IOException
try ObjectOutputStream out new ObjectOutputStreamnew FileOutputStreamcarlotdat"
out.writeObjectinventory;
@SuppressWarningsunchecked
public ArrayList loadFromDisk throws IOException, ClassNotFoundException
try ObjectInputStream in new ObjectInputStreamnew FileInputStreamcarlotdat"
inventory ArrayList inreadObject;
return inventory;
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