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

Write a program to maintain an inventory for a small used vehicle dealer. The pr

ID: 3662157 • Letter: W

Question

Write a program to maintain an inventory for a small used vehicle dealer. The program should maintain and display a list of vehicles,program should also calculate the sales price and monthly payments for a designated vehicle. You will use a class for Vehicle. (Please show proof of the working program. Thank you in advance!)

The class should have data elements for the following information: Lot #, make, model, color, mileage, fuel consumption and list price. You will have the following derived classes from Vehicle: Automobile, Motorcycle. Program will need to have a function to add miles to the mileage; from test drives, or employee use. You only need to update the mileage. You will also need a List class. The List class will use a dynamic array to store Vehicle objects. You will have one list for Automobiles and one for Motorcycles. You will NEVER have an object of class Vehicle.

As each vehicle is entered an object of the appropriate type must be created and added to the correct array. Remember you may need to increase the size of the array. Start each array with 2 elements so the grader can test your resizing. Double the size each time you increase capacity.

Program must perform the following activities: create a list, add items, search for a vehicle, calculate the price and payments for a vehicle, remove a vehicle, and display the inventory. The user should be able to search for any attribute (data member) of the Vehicle, Automobile, or Motorcycle classes. To add an item you should prompt the user to enter the required information. Check the input when adding a vehicle (input validation). This could be easy. Transmissions might be AT, CVT, and MT. The boss definitely doesn’t want negative prices, but also doesn’t want a vehicle sitting because and extra 0 got put in the price. So anything over $10,000 requires an acknowledgement. What else to check?

Program should calculate the final price of the vehicle. We’ll keep things simple. There is only 1 list price. When the user selects a vehicle to purchase you start with the list price, you can deduct any incentives (just entered by the user), add a $95 administrative fee, add any taxes*, deduct the amount of the trade-in (if any), enter an interest rate and loan period to calculate* the monthly payment. Display each of these values to the user. Give them the option to indicate the vehicle sold. If it is sold remove it from the inventory.

The display should show: Menu of choices (display all vehicles in the inventory, adjust mileage for a vehicle, search for a vehicle, add a vehicle, calculate purchase price for a vehicle, and exit. The calculate price option should remove the vehicle if it was sold. The search should display the information for each vehicle matching the criteria.

Explanation / Answer

Vehicle.java

/**
*
* @author prmsh
*/
public class Vehicle {
//class variables declared
String make;
String model;
String color;
double mileage;
double fuelConsumption;
double listPrice;
  
//constructor

public Vehicle(String make, String model, String color, double mileage, double fuelConsumption, double listPrice) {
this.make = make;
this.model = model;
this.color = color;
this.mileage = mileage;
this.fuelConsumption = fuelConsumption;
this.listPrice = listPrice;
}
  
//getter setter methods

public String getMake() {
return make;
}

public void setMake(String make) {
this.make = make;
}

public String getModel() {
return model;
}

public void setModel(String model) {
this.model = model;
}

public String getColor() {
return color;
}

public void setColor(String color) {
this.color = color;
}

public double getMileage() {
return mileage;
}

public void setMileage(double mileage) {
this.mileage = mileage;
}

public double getFuelConsumption() {
return fuelConsumption;
}

public void setFuelConsumption(double fuelConsumption) {
this.fuelConsumption = fuelConsumption;
}

public double getListPrice() {
return listPrice;
}

public void setListPrice(double listPrice) {
this.listPrice = listPrice;
}
  
//toString method

@Override
public String toString() {
return "Vehicle{" + "make=" + make + ", model=" + model + ", color=" + color + ", mileage=" + mileage + ", fuelConsumption=" + fuelConsumption + ", listPrice=" + listPrice + '}';
}
  
}

------------------------------------------------------------------------------------------------------------------------------

Automobile.java

public class Automobile extends Vehicle{

public Automobile(String make, String model, String color, double mileage, double fuelConsumption, double listPrice) {
super(make, model, color, mileage, fuelConsumption, listPrice);
}
  
}

-----------------------------------------------------------------------------------------------------------------------------------------

Motorcycles.java

public class Motorcycles extends Vehicle{

public Motorcycles(String make, String model, String color, double mileage, double fuelConsumption, double listPrice) {
super(make, model, color, mileage, fuelConsumption, listPrice);
}
  
}

----------------------------------------------------------------------------------------------------------------------------------

inventory.java

import java.util.ArrayList;
import java.util.Scanner;

/**
*
* @author prmsh
*/
public class Inventory {
public static void main(String args[]){
//arraylist declared for both automobiles and motorcycles
ArrayList<Automobile> automobiles = new ArrayList<Automobile>();
ArrayList<Motorcycles> motorcycles = new ArrayList<Motorcycles>();
  
Scanner sc = new Scanner(System.in);
double totalPrice = 0;
while(true){
//displaying menu
System.out.println("1. add item 2.search vehicle 3.calculate price 4.remove vehicle 5.display inventory 6.exit");
//reading choice from user
int choice = sc.nextInt();
if(choice == 1){
//adding vehicle
System.out.println("1.automobile 2.motorcycle");
int type = sc.nextInt();
System.out.println("Enter make: ");
String make = sc.nextLine();
System.out.println("Enter model: ");
String model = sc.nextLine();
System.out.println("Enter color: ");
String color = sc.nextLine();
System.out.println("Enter mileage: ");
double mileage = sc.nextDouble();
System.out.println("Enter fuelConsumption: ");
double consumption = sc.nextDouble();
System.out.println("Enter list price: ");
double price = sc.nextDouble();
//updating total price
totalPrice = totalPrice +price;
if(type == 1){
Automobile obj = new Automobile(make,model,color,mileage,consumption,price);
automobiles.add(obj);
}
else{
Motorcycles obj = new Motorcycles(make,model,color,mileage,consumption,price);
motorcycles.add(obj);
}
}
//search
else if(choice == 2){
//reading model name from user
System.out.println("Enter model: ");
String model = sc.nextLine();

//searching in automobiles
for(int i=0;i<automobiles.size();i++){
if(automobiles.get(i).model.equals(model)){
System.out.println(automobiles.get(i));
}
}
for(int i=0;i<motorcycles.size();i++){
if(motorcycles.get(i).model.equals(model)){
System.out.println(motorcycles.get(i));
}
}
}
else if(choice == 3){
System.out.println("Total Price: "+totalPrice);
}
//delete vehicle
else if(choice == 4){
//reading model name from user
System.out.println("Enter model to delete: ");
String model = sc.nextLine();

//searching in automobiles
for(int i=0;i<automobiles.size();i++){
if(automobiles.get(i).model.equals(model)){
automobiles.remove(i);
}
}
for(int i=0;i<motorcycles.size();i++){
if(motorcycles.get(i).model.equals(model)){
motorcycles.remove(i);
}
}
}
//disaply inventory
else if(choice == 4){   
//searching in automobiles
for(int i=0;i<automobiles.size();i++){
System.out.println(automobiles.get(i));
}
for(int i=0;i<motorcycles.size();i++){
System.out.println(motorcycles.get(i));
}
}else{
//exiting
break;
}
}
}
}

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