Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The file Dealership.java contains an incomplete definition for the dealership cl

ID: 3768112 • Letter: T

Question

The file Dealership.java contains an incomplete definition for the dealership class. Save it to your directory and complete the class definition as follows: • Declare the instance data (dealership name, dealership id, and average cost of cars sold) • Add the missing method headers (aka signatures) • Add the missing method bodies import java.text.NumberFormat; import java.util.ArrayList; import java.util.Random; public class Dealership { final int numModels = 5; int [] modelsCount = new int[numModels]; ArrayList carsSold = new ArrayList(); Random gen = new Random(System.currentTimeMillis()); //private variables //Constructor with a name as a parameter /* Sell Car - This method will create a random car object and * add it to the ArrayList using the add method. */ public void sellACar(){ int type = gen.nextInt(numModels);//0 to 5 carsSold.add(new Car(type)); modelsCount[type]++; } //Get the total cost of all the cars by add the cost of each car //Add code here public double getTotalSales(){ double total = 0.0; return total; } //Get the average cost of each car by getting the totalSales //and dividing by the size() of the arrayList carsSold //Add code here //Get the most common model //Add code here //Print all the sold cars public String toStringSoldCars(){ StringBuilder result = new StringBuilder(); for(int i = 0; i < this.carsSold.size(); i++){ result.append(this.carsSold.get(i)); } return result.toString(); } //override toString method //Add code here }

Explanation / Answer

Here is the solution for you. If you need any further refinements, just get back to me.

import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Random;
public class Dealership
{
final int numModels = 5;
int [] modelsCount = new int[numModels];
ArrayList carsSold = new ArrayList();
Random gen = new Random(System.currentTimeMillis());
//private variables
String dealershipName;
int dealershipID;
double averageCostOfCarsSold;
//Constructor with a name as a parameter
Dealership(String name)
{
dealershipName = name;
}
/* Sell Car - This method will create a random car object and * add it to the ArrayList using the add method. */
public void sellACar()
{
int type = gen.nextInt(numModels);//0 to 5
carsSold.add(new Car(type));
System.out.println("Check: "+carsSold.get(0));
modelsCount[type]++;
}
//Get the total cost of all the cars by add the cost of each car
public double getTotalSales()
{
Car c;
double total = 0.0;
for(int i = 0; i < carsSold.size(); i++)
{
c = (Car)carsSold.get(i);
total += c.getCost();
}
return total;
}
//Get the average cost of each car by getting the totalSales
//and dividing by the size() of the arrayList carsSold
public double getAverageCost()
{
return getTotalSales() / carsSold.size();
}
//Get the most common model
public int getCommonModel()
{
int common = 0;
for(int i = 0; i < numModels; i++)
if(modelsCount[i] > modelsCount[common])
common = i;
return common;
}
//Print all the sold cars
public String toStringSoldCars()
{
StringBuilder result = new StringBuilder();
for(int i = 0; i < this.carsSold.size(); i++)
{
result.append(this.carsSold.get(i));
}
return result.toString();
}
//override toString method
public String toString()
{
return String.format("Dealership Name: "+dealershipName+" Dealership ID: "+dealershipID);
}
//Add code here
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote