Question

In: Computer Science

In the previous lab you created a Car class and a Dealership class. Now, in this...

In the previous lab you created a Car class and a Dealership class. Now, in this activity change the
design of the Dealership class, in which the list of the cars inside a dealership will be stored in an ArrayList.
Then, provide required getter and setter methods to keep the records of all its cars. In your tester class, test
your class and also printout the list of all cars of a given dealership object.

// Java program

import java.util.ArrayList;

class Car {
String make;
String model;
int year;
double transmission;
int seats;
int maxSpeed;
int wheels;
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 '\n' + "Make: " + make + '\n' +
"Model: " + model + '\n' +
"Year: " + year + '\n' +
"Transmission: " + transmission + '\n' +
"Seats: " + seats + '\n' +
"Maximum Speed: " + maxSpeed + '\n' +
"Wheels: " + wheels + '\n' +
"Type: " + type;
}
}

class Dealership {
String name;
String location;
ArrayList managers = new ArrayList<>();
ArrayList employees = new ArrayList<>();
ArrayList 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 managers) {
this.managers = managers;
}

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

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

public String getName() {
return name;
}

public String getLocation() {
return location;
}

public ArrayList getManagers() {
return managers;
}

public ArrayList getEmployees() {
return employees;
}

public ArrayList 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) {
Car car1 = new Car("Toyota", "Camry", 2019, 18.25, 5, 250, 4, "SUV");
Car car2 = new Car();
car2.setMake("Nissan");
car2.setModel("Altima");
car2.setMaxSpeed(275);
car2.setSeats(5);
car2.setYear(2018);
car2.setTransmission(16.25);
car2.setType("Sedan");
car2.setWheels(4);

Dealership d1 = new Dealership("Auto Dealer", "Woodland");
ArrayList<String> e = new ArrayList<>();
e.add("John");
e.add("Sam");

ArrayList<String> m = new ArrayList<>();
m.add("Adam");
m.add("Bob");

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());
}
}

// Need to change the design of the Dealership class, in which the list of the cars inside a dealership will be stored in an ArrayList.
Then, provide required getter and setter methods to keep the records of all its cars.

Solutions

Expert Solution

/**********************************
File Name : - Testdealer.java
***********************************/
import java.util.ArrayList;
import java.util.*;
class Car {
String make;
String model;
int year;
double transmission;
int seats;
int maxSpeed;
int wheels;
String type;
Car()
{
;
}
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;
}
}
class Dealership {
String name;
String location;
ArrayList<String> Manager = new ArrayList<String>();
 ArrayList<String> Employees = new ArrayList<String>();
ArrayList<String> Cars = new ArrayList<String>();
Dealership()
{;}
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 setManager(ArrayList<String> mng)
{
for(int i = 0; i < mng.size(); i++) {   
    Manager.add(mng.get(i));
}
}
public ArrayList<String> getmanagers()
{
return (Manager);
}
public void setEmployees(ArrayList<String> employees)
{
for(int i = 0; i < employees.size(); i++) {   
    Employees.add(employees.get(i));
}
}
public void setCars(ArrayList<String> cars)
{
for(int i = 0; i < cars.size(); i++) {   
    Cars.add(cars.get(i));
}
}
public String getName()
{
return name;
}
public String getLocation() 
{
return location;
}
public ArrayList<String> getCars()
{
return (Cars);
}
public ArrayList<String> getemployees()
{
return (Employees);
}
}
public class Testdealer {
public static void main(String[] args) {
Car car1 = new Car("Toyota", "Camry", 2019, 18.25, 5, 250, 4, "SUV");
Car car2 = new Car();
car2.setMake("Nissan");
car2.setModel("Altima");
car2.setMaxSpeed(275);
car2.setSeats(5);
car2.setYear(2018);
car2.setTransmission(16.25);
car2.setType("Sedan");
car2.setWheels(4);
System.out.println("--------------------");
System.out.println("Getting Car1 Details : ");
System.out.println("--------------------");
System.out.println(car1.getMake());
System.out.println(car1.getModel());
System.out.println(car1.getMaxSpeed());
System.out.println(car1.getSeats());
System.out.println(car1.getYear());
System.out.println(car1.getTransmission());
System.out.println(car1.getType());
System.out.println(car1.getWheels());
System.out.println("--------------------");
System.out.println("Getting Car2 Details : ");
System.out.println("--------------------");
System.out.println(car2.getMake());
System.out.println(car2.getModel());
System.out.println(car2.getMaxSpeed());
System.out.println(car2.getSeats());
System.out.println(car2.getYear());
System.out.println(car2.getTransmission());
System.out.println(car2.getType());
System.out.println(car2.getWheels());
Dealership d1=new Dealership("Dadda","Newyork");
 ArrayList<String> manager = new ArrayList<String>();
 ArrayList<String> employees = new ArrayList<String>();
ArrayList<String> cars = new ArrayList<String>();
 manager.add("John");
 manager.add("Smith");
 manager.add("Devd");
 employees.add("Gayle");
 employees.add("Holder");
 employees.add("Jason");
 cars.add("BMW");
 cars.add("Toyota");
 cars.add("Ferrari");
  d1.setManager(manager);
  d1.setCars(cars);
  d1.setEmployees(employees);
System.out.println("--------------------");
System.out.println("Getting Dealership Details : ");
System.out.println("--------------------");  
System.out.println(d1.getName());
System.out.println(d1.getLocation());
System.out.println(d1.getmanagers());
System.out.println(d1.getemployees());
System.out.println(d1.getCars());
}}

some modification has been done on the return type of arraylist in get and set method go throuh it and check the details .

output_screen


Related Solutions

In Java in previous question #1, you created a method called isDNAvalid() in the DNA class....
In Java in previous question #1, you created a method called isDNAvalid() in the DNA class. You probably looped through the entire sequence one character at a time (using charAt() method of the String class), and check if the character is 'A', 'T', 'G', or 'C'. If it is not one of these four characters, the sequence contains an invalid base. Please re-create the isDNAvalid() method using a character pattern and the regular expression to validate the DNA sequence. previous...
A car dealership offers you no money down on a new car. You may pay for...
A car dealership offers you no money down on a new car. You may pay for the car for 5 years by equal monthly end-of-the-month payments of $407 each, with the first payment to be made one month from today. If the discount annual rate is 4.52 percent compounded monthly, what is the present value of the car payments? Round the answer to two decimal places.
For today's lab we will be using the Car Object Class which we built in Lab...
For today's lab we will be using the Car Object Class which we built in Lab 1. I have attached my solution if you would prefer to use my solution instead of your own solution. We will working on remembering how to build sub-classes and user interfaces. So we will be creating new Java files for: An Interface called GreenHouseGasser Requires a method called CO2() which returns how much carbon dioxide the Object produces. Make sure to update Car so...
Calvin borrows $20,000 from a car dealership to purchase a vehicle. The car dealership charges 12%...
Calvin borrows $20,000 from a car dealership to purchase a vehicle. The car dealership charges 12% interest, compounded monthly. Calvin is expected to pay off the loan principal and all interest charged with equal monthly payments over a 3-year period. a. What will Calvin’s monthly payment need to be? (4 points) b. With the first monthly payment, how much of this payment will be “interest”, and how much of this payment will be “principal”? (4 points) c. Once the loan...
Calvin borrows $20,000 from a car dealership to purchase a vehicle. The car dealership charges 12%...
Calvin borrows $20,000 from a car dealership to purchase a vehicle. The car dealership charges 12% interest, compounded monthly. Calvin is expected to pay off the loan principal and all interest charged with equal monthly payments over a 3-year period. a. What will Calvin’s monthly payment need to be? (4 points) b. With the first monthly payment, how much of this payment will be “interest”, and how much of this payment will be “principal”? (4 points) c. Once the loan...
In 6A, you created an object class encapsulating a Trivia Game which INHERITS from Game. Now...
In 6A, you created an object class encapsulating a Trivia Game which INHERITS from Game. Now that you have successfully created Trivia objects, you will continue 6B by creating a linked list of trivia objects. Add the linked list code to the Trivia class. Your linked list code should include the following: a TriviaNode class with the attributes: 1. trivia game - Trivia object 2. next- TriviaNode 3. write the constructor, accessor, mutator and toString methods. A TriviaLinkedList Class which...
In this assignment you are to make an inventory management system for a car dealership. The...
In this assignment you are to make an inventory management system for a car dealership. The dealerships current method of tracking inventory is using a list which has the color and name of each car they have in inventory. There current inventory list will look like the example below. RED TOYOTAWHITE HONDA...BLACK BMW The types of cars that they order are as follows: TOYOTA, HONDA, BMW, NISSAN, TESLA, DODGE The colors they purchase are as follows: RED, WHITE, BLUE, BLACK,...
1/ Assume you purchased a car that costs $14,000. The car dealership is offering financing at...
1/ Assume you purchased a car that costs $14,000. The car dealership is offering financing at 5% per year. How much is your annual payment assuming you financed the car for 5 years? How much did the car actually cost? 2/ At the beginning of the season on April 1, Green Acres Golf Course completed a physical inventory count and found that $3,000 of inventory was still on hand. Throughout the month of April, Green Acres had the following purchase...
We started creating a Java class for Car. In this lab we are going to complete...
We started creating a Java class for Car. In this lab we are going to complete it in the following steps: 1- First create the Car class with some required instance variables, such make, model, year, price, speed, maxSpeed, isOn, isMoving, and any other properties you like to add. 2- Provide couple of constructors for initializing different set of important properties, such as make, model, year, and price. Make sure that you do not repeat initialization of instance variables in...
The following classes along with the driver has been created and compiled. public class Car {...
The following classes along with the driver has been created and compiled. public class Car { public void method1() { System.out.println("I am a car object"); } } class Point { public void method2() { System.out.println("I am a Point object"); } } class Animal { public void method3() { System.out.println("I am an animal object"); } } The following driver class has been created and all the lines of code inside the for loop is not compiling. Modify the code and write...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT