64 638
Assignments Done
99,2%
Successfully Done
In September 2018

Answer to Question #8612 in Java | JSP | JSF for Jessica

Question #8612
You are a manager of a parking lot and decide to keep track all the cars parked in your lot. You want to know the maker, model, color, and license plate of the cars. Since you learned about ArrayList and you like to use an ArrayList to keep track of cars entered the lot. Each time a car left the lot, the remove method of ArrayList class can be used. Each time a car entered, add method can be used. To keep track how many cars in the lot, the size method can be used.
But before you write your application to create a class called MyParkingLot, you have to write a class call Car which contains all the information you need as describe in the previous paragraph. Also develop constructor(s) and getters or setters as needed so that you can retrieve (get) and record (set) information such as maker, model, color, and license plate number.
For MyParkingLot class, it shall consist of an ArrayList which will be used to maintain the information of all the cars in and out of this parking lot.
Expert's answer
public class Car {
private String model;
private String maker;
private String color;
private String lisencePlate;
public Car(String model, String maker){
this.maker = maker;
this.model = model;
}
public Car(){
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getMaker() {
return maker;
}
public void setMaker(String maker) {
this.maker = maker;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String getLisencePlate() {
return lisencePlate;
}
public void setLisencePlate(String lisencePlate) {
this.lisencePlate = lisencePlate;
}
}
----------------------------------------
import java.util.ArrayList;
import java.util.Iterator;
public class MyParkingLot {
private ArrayList carList = new ArrayList<>();
// add car
public void addCar(Car car){
carList.add(car);
}
// get all cars
public void getAllCars(){
Iterator it = carList.iterator();
Car currCar = new Car();
while(it.hasNext()){
currCar = (Car)it.next();
System.out.println("Current car: ");
System.out.println("Model: "+currCar.getModel());
System.out.println("Maker: "+currCar.getMaker());
System.out.println("Color: "+currCar.getColor());
System.out.println("Lisence Plate Number: "+currCar.getLisencePlate());
}
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions