QuestionQuestion

Purpose: This problem emphasizes the design and coding of an object oriented application using multiple arrays, classes, and methods. Sequence, selection, and iteration logic are also used, as are logical program blocks, input / output dialogs, and the object-messaging model.

Problem: The CIS department plans to create a car dealership to address the needs of the department, faculty, and students. The application would keep the inventory of different cars and their attributes and allow customers to see them. Details are provided in the following sections.

General Discussion
The project is a composition of 7 classes: (1) Dealership is used to keep an inventory of different cars, (2) Car is responsible for providing the characteristics and behavior of each car, (3) option represents options installed on cars, (4) Engine class holds the details of engine, (5) Interior class keeps the details of the interior, (6) Trunk class is responsible for keeping track of the contents of the trunk, and (7) an application class for starting the program and handling user dialog.
In its initial configuration, the program begins by loading 10 cars and their options. 10 car objects are instantiated (along with their options) and saved in the inventory.

Input and Output
Your program must accept the input shown below using the system console. Note that all inputs are case sensitive. All output should be displayed to the console window. Be sure to clearly label each output.
Possible valid main menu options:
Commands: shows a list of all available commands List: lists the inventory of cars
Compare [n1] [n2]: compares two cars
Select [n]: selects car No. n and shows the details
Engine: shows the details of the engine of the selected car Interior: Show the details of the interior of the selected car Trunk: Show the items in the trunk of the selected car
Options: show the details of options installed on the selected car Quit: terminate the program

Response to invalid input: I don’t understand the word “[invalid input]” where the word entered is just repeated without quotation marks and braces.
Classes and Responsibilities:
Class name: CISCDApp
Responsibility: Contains application’s main method and handles user dialog

Class name: Dealership
Responsibility: hold the inventory of cars Instance variables: Car[] cars, Car selectedCar Method name: String ListAllCars() Responsibility: returns a description of all cars Method name: void SelectCar (int index)
Responsibility: selects the car at the selected index Method name: String OpenTrunk()
Responsibility: returns a description of the selected car’s trunk Method name: String CheckEngine()
Responsibility: returns a String describing the engine of the selected car Method name: String CheckInterior()
Responsibility: returns a String describing the interior of the selected car Method name: String Compare (int firstCarIndex, int secondCarIndex) Responsibility: Compares the two selected cars
Method name: String ShowOptions()
Responsibility: returns the options installed on the of the selected car

Enum CarType {Sedan, SUV, CrossOver, Truck}

Class name: Car
Instance variables: String make, int year, String model, int price, String color, CarType type, Engine engine, Interior interior, Trunk trunk, Option[] options

Method name: Car (String make, int year, String model, int price, String color, CarType type) Responsibility: constructor
Method name: Car (String make, int year, String model, int price, String color, CarType type, Engine engine, Interior interior, Trunk trunk)
Responsibility: constructor
Method name: void SetEngine(Engine engine) Responsibility: sets the engine to the provided object Method name: void SetInterior(Interior interior) Responsibility: sets the interior to the provided object Method name: void SetTrunk(Trunk trunk) Responsibility: sets the trunk to the provided object Method name: void AddOption(Option option) Responsibility: Adds an option to the list of options Method name: String OpenTrunk()
Responsibility: returns a description of the contents of trunk Method name: String CheckEngine()
Responsibility: returns a String describing the engine of the car Method name: String CheckInterior()
Responsibility: returns a String describing the interior Method name: String ShowOptions()
Responsibility: returns the options installed on the car. Each car should have at least 3 options Method name: String toString()
Responsibility: returns a description of the car (make, year, model, price, color) Method name: String CompareTo (Car otherCar)
Responsibility: Compares the current car with the other car (age (i.e., year), price, fuel type, power, mpg, number of options, number of cylinders)

Enum FuelType {Gas, Electric, Hybrid, Diesel}

Class name: Engine
Instance variables: FuelType fuelType, int noOfCylinders, int capacity, int horsePower, float mpg Method name: Engine (FuelType fuelType, int noOfCylinders, int capacity, int horsePower, float mpg) Responsibility: constructor
Method name: String toString()
Responsibility: returns a description of the engine (fuel type, number of cylinders, capacity, horse power, mpg)
Method name: int getHorsePower () Responsibility: returns horsepower Method name: float getMpg() Responsibility: returns mpg
Method name: FuelType getFuelType() Responsibility: returns fuelType Method name: int getCapacity() Responsibility: returns capacity Method name: int getNoOfCylinders() Responsibility: returns noOfCylinders

Class name: Interior
Instance variables: String color1, String color2, boolean hasSunRoof, boolean hasMoonRoof Method name: Interior (String color1, String color2, boolean hasSunRoof, boolean hasMoonRoof) Responsibility: constructor
Method name: String toString()
Responsibility: returns a description of the interior (i.e., color1, color2, hasSunRoof, hasMoonRoof)

Class name: Trunk
Instance variables: boolean hasSpareTire, boolean hasFirstAidKit, boolean hasCarpet, boolean hasJack, String carpetColor
Method name: Trunk (boolean hasSpareTire, boolean hasFirstAidKit, boolean hasCarpet, boolean hasJack, String carpetColor)

Responsibility: constructor
Method name: Trunk (boolean hasSpareTire, boolean hasFirstAidKit, boolean hasCarpet, boolean hasJack, String carpetColor)
Responsibility: constructor Method name: String toString()
Responsibility: returns a description of the trunk (spare tire, first aid kit, carpet (yes/no, color if yes), jack)

Class name: Option
Instance variables: String name, String descirption Method name: Option (String name, String descirption) Responsibility: constructor
Method name: String toString()
Responsibility: returns a description of the option (name, description)

Sample output for a partial session
Welcome to CIS department’s Car Dealership! To view a list of commands, enter Commands
>Commands
Commands: shows a list of all available commands List: lists the inventory of cars
Compare [n1] [n2]: compares two cars
Select [n]: selects car No. n and shows the details
Engine: shows the details of the engine of the selected car Interior: Show the details of the interior of the selected car Trunk: Show the items in the trunk of the selected car
Options: show the details of options installed on the selected car Quit: terminate the program
>Engine

You first need to select a car to view its engine details
>List
1 - White 2006 Hyundai Sonata for $2500 2 - Black 2016 Infiniti QX50 for $38000
3 - Red 2010 Toyota Corolla for $7845
>Select 2
This Black 2016 Infiniti QX50 is great! You can view engine, interior, and trunk of the car
>Engine
Uses gas, 6 cylinders, 3700 cc, 325 hp, 22 average mpg
>Compare 2 3
2010 Toyota Corolla has better MPG 2010 Toyota Corolla is less expensive 2016 Infiniti QX50 is newer
Both cars run on gas
2016 Infiniti QX50 has a more powerful engine
2016 Infiniti QX50 has 8 options while 2010 Toyota Corolla has 3 options
2016 Infiniti QX50 has 6 cylinders while 2010 Toyota Corolla has 4 cylinders
>List
1 - White 2006 Hyundai Sonata for $2500 2 - Black 2016 Infiniti QX50 for $38000
3 - Red 2010 Toyota Corolla for $7845
>Quit
Do you wish to leave the dealership (Y/N)?>Y
Thank you for using CIS department’s car dealership application!

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import java.util.ArrayList;
import java.util.List;

public class Car {
   
    String make;
    int year;
    String model;
    int price;
    String color;
    CarType type;
    Engine engine;
    Interior interior;
    Trunk trunk;
    List<Option> options = new ArrayList<>();
   
    public Car (String make, int year, String model, int price, String color, CarType type){
         this.make = make;
         this.year = year;
         this.model = model;
         this.price = price;
         this.color = color;
         this.type = type;
    }
   
    public Car (String make, int year, String model, int price, String color, CarType type, Engine engine, Interior interior, Trunk trunk){
         this.make = make;
         this.year = year;
         this.model = model;
         this.price = price;
         this.color = color;
         this.type = type;
         this.engine = engine;
         this.interior = interior;
         this.trunk = trunk;
    }
   
    public void SetEngine(Engine engine){
         this.engine = engine;
    }
   
    public void SetInterior(Interior interior){
         this.interior = interior;
    }
   
    public void SetTrunk(Trunk trunk){
       this.trunk = trunk;
    }
   
    public void AddOption(Option option){
         options.add(option);
    }
   
    public String OpenTrunk(){
         return trunk.toString();
    }
   
    public String CheckEngine(){
         return "uses "+engine.getFuelType()+", "+engine.getNoOfCylinders()+"cylinders "+engine.getHorsePower()+"hp "+engine.getMpg()+"mpg.";
    }
   
    public String CheckInterior(){
         return interior.toString();
    }
   
    public String ShowOptions(){
         StringBuilder sb = new StringBuilder();
         for(Option option: options){
             sb.append(option.toString());
         }
         return sb.toString();
    }
   
    public String toString(){
         return "make: "+make+" year: "+year+" model: "+model+" price: $"+price+" color: "+color;
    }
   
    public String CompareTo (Car otherCar){
         StringBuilder sb = new StringBuilder();
         if(otherCar.year > year){
             sb.append(otherCar.make).append(" ").append(otherCar.model+" is newer than "+make+" "+model);
         }
         else{
             sb.append(make).append(" ").append(model+" is newer than "+otherCar.make+" "+otherCar.model);
         }
         sb.append("\n");
         sb.append(this.toString()+"\n");
         sb.append(otherCar.toString());
               
         return sb.toString();
    }
         
}...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$42.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats