Question

Activity 3. In the previous lab you created a Car class and a Dealership class. Now, in this activity change the design of th

Below are the Car class and Dealership class that I created In the previous lab

import java.util.ArrayList;

class Car
{
    private String make;
    private String model;
    private int year;
    private double transmission;
    private int seats;
    private int maxSpeed;
    private int wheels;
    private String type;

    public Car()
    {

    }

    public Car(String make, String model, int year, double transmission, int seats, int maxSpeed, int wheels, String type) {
        this.make = make;
        this.model = model;
        this.year = year;
        this.transmission = transmission;
        this.seats = seats;
        this.maxSpeed = maxSpeed;
        this.wheels = wheels;
        this.type = type;
    }

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

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

    public void setYear(int year) {
        
        this.year = year;
    }

    public void setTransmission(double transmission) {
        
        this.transmission = transmission;
    }

    public void setSeats(int seats) {
        
        this.seats = seats;
    }

    public void setMaxSpeed(int maxSpeed) {
        
        this.maxSpeed = maxSpeed;
    }

    public void setWheels(int wheels) {
        
        this.wheels = wheels;
    }

    public void setType(String type) {
        
        this.type = type;
    }

    public String getMake() {
        
        return make;
    }

    public String getModel() {
        
        return model;
    }

    public int getYear() {
        
        return year;
    }

    public double getTransmission() {
        
        return transmission;
    }

    public int getSeats() {
        
        return seats;
    }

    public int getMaxSpeed() {
        
        return maxSpeed;
    }

    public int getWheels() {
        
        return wheels;
    }

    public String getType() {
        
        return type;
    }

    public String toString() {
        return "Car{" + "make='" + make + '\'' + ", model='" + model + '\'' + ", year=" + year + ", transmissi =" + transmission + ", seats=" + seats + ", maxSpeed=" + maxSpeed + ", wheels=" + wheels + ", typ ='" + type + '\'' + '}';
    }
}

class Dealership
{
    private String name;
    private String location;

    ArrayList<String> managers = new ArrayList<>();
    ArrayList<String> employees = new ArrayList<>();
    ArrayList<Car> cars = new ArrayList<>();

    public Dealership(String name, String location)
    {
        this.name = name;
        this.location = location;
    }


    public void setName(String name)
    {
        
        this.name = name;
    }

    public void setLocation(String location)
    {
        
        this.location = location;
    }

    public void setManagers(ArrayList<String> managers)
    {
        
        this.managers = managers;
    }

    public void setEmployees(ArrayList<String> employees)
    {
        
        this.employees = employees;
    }

    public void setCars(ArrayList<Car> cars)
    {
        
        this.cars = cars;
    }

    public String getName()
    {
        
        return name;
    }

    public String getLocation()
    {
        
        return location;
    }

    public ArrayList<String> getManagers()
    {
        
        return managers;
    }

    public ArrayList<String> getEmployees()
    {
        
        return employees;
    }

    public ArrayList<Car> getCars()
    {
        
        return cars;
    }

    public void addCar(Car c)
    {
        
        this.cars.add(c);
    }

    public void addEmployee(String e)
    {
        
        this.employees.add(e);
    }

    public void addManager(String m)
    {
        
        this.managers.add(m);
    }
}


public class TestDealer
{
    public static void main(String[] args)
    {
        //setting Car1
        Car car1 = new Car("BMW", "120i", 2020, 9.4, 4, 212, 4, "sedan");
        Car car2 = new Car();
        //setting Car2
        car2.setMake("Ford");
        car2.setModel("Escape SE");
        car2.setMaxSpeed(280);
        car2.setSeats(5);
        car2.setYear(2020);
        car2.setTransmission(10.5);
        car2.setType("suv");
        car2.setWheels(4);

        // Creating dealership class object
        Dealership d1 = new Dealership("Tonny", "Toronto");
        // creating list of employees
        ArrayList<String> e = new ArrayList<>();
        e.add("Employee1");
        e.add("Employee2");

        // creating list of managers
        ArrayList<String> m = new ArrayList<>();
        m.add("Manager1");
        m.add("Manager2");


        d1.setEmployees(e);
        d1.setManagers(m);
        d1.addCar(car1);
        d1.addCar(car2);

        System.out.println("Dealership Information");
        System.out.println("Name: "+d1.getName());
        System.out.println("Location: "+d1.getLocation());
        System.out.println("Employees: "+d1.getEmployees());
        System.out.println("Managers: "+d1.getManagers());
        System.out.println("Cars: "+d1.getCars());

    }
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Output for the java code (TestDealer.java) given below. Please refer to the screenshot of the code to understand the indentation of the code.

--Dealership Information-- Name: John Location: Chicago Managers: Berny Sandy Employees: Paul Peter Cars: Car { Make = Audi

import java.util.ArrayList;
import java.util.Arrays;

class Car {
    private String make;
    private String model;
    private int year;
    private double transmission;
    private int seats;
    private int maxSpeed;
    private int wheels;
    private String type;
    
    public Car()
    {
    }
    
    public Car(String make, String model, int year, double transmission, int seats, int maxSpeed, int wheels, String type) {
        this.make = make;
        this.model = model;
        this.year = year;
        this.transmission = transmission;
        this.seats = seats;
        this.maxSpeed = maxSpeed;
        this.wheels = wheels;
        this.type = type;
    }
    //getters
    public String getMake() {
        return this.make;
    }
    public String getModel() {
        return this.model;
    }
    public int getYear() {
        return this.year;
    }
    public double getTransmission() {
        return this.transmission;
    }
    public int getSeats() {
        return this.seats;
    }
    public int getMaxSpeed() {
        return this.maxSpeed;
    }
    public int getWheels() {
        return this.wheels;
    }
    public String getType() {
        return this.type;
    }
    //setters
    public void setMake(String make) {
        this.make=make;
    }
    public void setModel(String model) {
        this.model=model;
    }
    public void setYear(int year) {
        this.year=year;
    }
    public void setTransmission(double transmission) {
        this.transmission=transmission;
    }
    public void setSeats(int seats) {
        this.seats=seats;
    }
    public void setMaxSpeed(int maxSpeed) {
        this.maxSpeed=maxSpeed;
    }
    public void setWheels(int wheels) {
        this.wheels=wheels;
    }
    public void setType(String type) {
        this.type=type;
    }
    
    @Override
    public String toString() {
        return "Car {\n" + "\tMake = '" + this.make + '\'' + ",\n\tModel = '" + this.model + '\'' + ",\n\tYear = " + this.year + 
        ",\n\tTransmission = " + this.transmission + ",\n\tSeats = " + this.seats + ",\n\tMax Speed = " + this.maxSpeed + 
        ",\n\tWheels = " + this.wheels + ",\n\tType = '" + this.type + '\'' + "\n}";
    }
}

class Dealership {
    private String name;
    private String location;
    private ArrayList<String> managers = new ArrayList<String>();
    private ArrayList<String> employees = new ArrayList<String>();
    private ArrayList<Car> cars = new ArrayList<Car>();
    
    public Dealership(String name, String location)
    {
        this.name = name;
        this.location = location;
    }
    
    //getters
    public String getName() {
        return this.name;
    }
    public String getLocation() {
        return this.location;
    }
    public ArrayList<String> getManagers() {
        return this.managers;
    }
    public ArrayList<String> getEmployees() {
        return this.employees;
    }
    public ArrayList<Car> getCars() {
        return this.cars;
    }
    //setters
    public void setName(String name) {
        this.name=name;
    }
    public void setLocation(String location) {
        this.location=location;
    }
    public void setManagers(ArrayList<String> managers) {
        this.managers=managers;
    }
    public void setEmployees(ArrayList<String> employees) {
        this.employees=employees;
    }
    public void setCars(ArrayList<Car> cars) {
        this.cars=cars;
    }
    
    //add to arraylist.
    public void addManager(String manager) {
        this.managers.add(manager);
    }
    
    public void addEmployee(String employee) {
        this.employees.add(employee);
    }
    
    public void addCar(Car car) {
        this.cars.add(car);
    }
}



public class TestDealer
{
        public static void main(String[] args) {
                // initializing new Dealership using constructor.
        Dealership d = new Dealership("John", "Chicago");
        
        ArrayList<String> employees = new ArrayList<String>(
            Arrays.asList("Paul", "Peter"));
        d.setEmployees(employees); // added employees to dealership object.
        
        ArrayList<String> managers = new ArrayList<String>(
            Arrays.asList("Berny", "Sandy"));
        d.setManagers(managers); // added managers to dealership object.
        
        // initializing new Car using constructor.
        Car car1 = new Car("Audi", "RS Q8", 2021, 9.4, 4, 280, 4, "Coupe");
        // initialization another Car using setters.
        Car car2 = new Car();
        car2.setMake("Ford");
        car2.setModel("Escape SE");
        car2.setMaxSpeed(190);
        car2.setSeats(5);
        car2.setYear(2020);
        car2.setTransmission(10.5);
        car2.setType("SUV");
        car2.setWheels(4);
        
        d.addCar(car1);
        d.addCar(car2); // added cars to dealership object.
        
        //Printing all details about dealership
        System.out.println("--Dealership Information--\n");
        System.out.println("Name: " + d.getName());
        System.out.println("\nLocation: "+d.getLocation());
        System.out.println("\nManagers:");
        for (String m: d.getManagers()) {
            System.out.println(m);
        }
        System.out.println("\nEmployees:");
        for (String e: d.getEmployees()) {
            System.out.println(e);
        }
        System.out.println("\nCars:");
        for (Car c: d.getCars()) {
            System.out.println(c.toString());
        }
        }
}

1 import java.util.ArrayList; 2 import java.util.Arrays; 3 4- class Cari 5 private String make; 6 private String model; 7 pri
41 - 42 43 44 - 45 46 47 48 49 50 - 51 52 53 54 - 55 56 57 58 59 60 61 62 63 - 64 65 66- 67 68 69 - 70 71 72 - 73 74 75 76 77
79 @Override 80 public String toString() { 81 - return Car {\n + \tMake = + this.make + \ + ,\n\tModel = + this.m
public void setLocation(String location) { this.location=location; } public void setManagers (ArrayList<String> managers) { t
// initializing new Car using constructor. Car car1 = new Car (Audi, RS Q8, 2021, 9.4, 4, 280, 4, Coupe); // initializa

Add a comment
Know the answer?
Add Answer to:
Below are the Car class and Dealership class that I created In the previous lab import...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java - Car Dealership Hey, so i am having a little trouble with my code, so...

    Java - Car Dealership Hey, so i am having a little trouble with my code, so in my dealer class each of the setName for the salesman have errors and im not sure why. Any and all help is greatly appreciated. package app5; import java.util.Scanner; class Salesman { private int ID; private String name; private double commRate; private double totalComm; private int numberOfSales; } class Car { static int count = 0; public String year; public String model; public String...

  • Can someone help me with my Java code error! Domain package challenge5race; import java.util.Random; public class...

    Can someone help me with my Java code error! Domain package challenge5race; import java.util.Random; public class Car {    private int year; private String model; private String make; int speed; public Car(int year, String model, String make, int speed) { this.year = year; this.model = model; this.make = make; this.speed = speed; } public Car() { } public int getYear() { return year; } public void setYear(int year) { this.year = year; } public String getModel() { return model; }...

  • In java 8. Modify the averageTopSpeed() method (in the class FormulaOne) using only lambdas and streams...

    In java 8. Modify the averageTopSpeed() method (in the class FormulaOne) using only lambdas and streams and print it to the terminal via the driver class: import java.util.*; public class Racer implements Comparable { private final String name; private final int year; private final int topSpeed;    public Racer(String name, int year, int topSpeed){    this.name = name; this.year = year; this.topSpeed = topSpeed;    }    public String toString(){    return name + "-" + year + ", Top...

  • Use an accessor and mutator as follows: Remove the addFuel method from class Car Replace the...

    Use an accessor and mutator as follows: Remove the addFuel method from class Car Replace the call to addFuel in the main program with a call to the accessor and mutator for the fuel amount to achieve the same effect (add 5 gallons of fuel to the existing fuel in the Toyota Camry). Test your program again to make sure it works and produces the same output. Part 2: Add functions to remove duplicate code * In the main program,...

  • How to build Java test class? I am supposed to create both a recipe class, and...

    How to build Java test class? I am supposed to create both a recipe class, and then a class tester to test the recipe class. Below is what I have for the recipe class, but I have no idea what/or how I am supposed to go about creating the test class. Am I supposed to somehow call the recipe class within the test class? if so, how? Thanks in advance! This is my recipe class: package steppingstone5_recipe; /** * *...

  • java programming how would i modify the code below to add a GUI (with a main menu with graphics and buttons, etc...) and include an option to print a list of all students added in a grid format and sh...

    java programming how would i modify the code below to add a GUI (with a main menu with graphics and buttons, etc...) and include an option to print a list of all students added in a grid format and short by name, course, instructor, and location. ///main public static void main(String[] args) { Scanner in = new Scanner(System.in); ArrayList<Student>students = new ArrayList<>(); int choice; while(true) { displayMenu(); choice = in.nextInt(); switch(choice) { case 1: in.nextLine(); System.out.println("Enter Student Name"); String name...

  • please help me add on this java code to run public class CarHwMain public static void...

    please help me add on this java code to run public class CarHwMain public static void main(String args 1/ Construct two new cars and one used car for the simulation Cari carl = new Car W"My New Mazda", 24.5, 16.0); Car car2 = new Cart My New Ford" 20.5, 15.0) Cari car) - new Cari ("My Used Caddie", 15.5, 16.5, 5.5, 1/ ADD CODE to completely fill the tanks in the new cars and off the used cars ton //...

  • I need an OUTLINE ONLY (pseudocode/comments). DO NOT DO THE PROGRAMMING ASSIGNMENT. Part I: PA3 Outline...

    I need an OUTLINE ONLY (pseudocode/comments). DO NOT DO THE PROGRAMMING ASSIGNMENT. Part I: PA3 Outline (10 points). Create an outline in comments/psuedocode for the programming assignment below. Place your comments in the appropriate files: main.cpp, functions.h, dealer.cpp, dealer.h, dealer.cpp (as noted below). Place into a file folder named LastnamePA3, the zip the content and hand in a zip file to Canvas. Part II: PA3: Car Dealership (40 points) For Programming Assignment 3 you will be creating a program to...

  • Consider the Automobile class: public class Automobile {    private String model;    private int rating;...

    Consider the Automobile class: public class Automobile {    private String model;    private int rating; // a number 1, 2, 3, 4, 5    private boolean isTruck;    public Automobile(String model, boolean isTruck) {       this.model = model;       this.rating = 0; // unrated       this.isTruck = isTruck;    }        public Automobile(String model, int rating, boolean isTruck) {       this.model = model;       this.rating = rating;       this.isTruck = isTruck;    }                public String getModel()...

  • Hi! I'm working on building a GUI that makes cars race across the screen. So far...

    Hi! I'm working on building a GUI that makes cars race across the screen. So far my code produces three cars, and they each show up without error, but do not move across the screen. Can someone point me in the right direction? Thank you! CarComponent.java package p5; import java.awt.*; import java.util.*; import javax.swing.*; @SuppressWarnings("serial") public class CarComponent extends JComponent { private ArrayList<Car> cars; public CarComponent() { cars = new ArrayList<Car>(); } public void add(Car car) { cars.add(car); } public...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT