The Bashemin Parking Garage contains a single lane that can hold up to ten cars. Arriving cars enter the garage at the rear and are parked in the empty space nearest to the front. Departing cars exit only from the front.
If a customer needs to pick up a car that is not nearest to the exit, then all cars blocking its path are moved out temporarily, the customer's car is driven out, and the other cars are restored in the order they were in originally. Whenever a car departs, all cars behind it in the garage are moved up one space.
Write a Java program to operate the garage.
The program will read and process lines of input from a file until end-of-file. Each input line contains a license plate number and an operation (ARRIVE or DEPART), separated by spaces. Cars arrive and depart in the order specified by the input. Each input operation must be “echo printed” to an output file, along with an appropriate message showing the status of the operation.
The number of moves does not include the one where the car departs from the garage, or the number of times the car was moved within the garage. It is only the number of times it was moved out of the garage temporarily to allow a car behind it to depart.
If a DEPART operation calls for a car that is not in the garage, the message should so state.
II. Specifications
`Hey,
Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries
//Copyable Code:
Please create a text file and paste the above
content.
Change the location according to your needs in the tester
class.
=======================================================================================
Garage.java
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
public class Garage {
private Car[] garage;
//private int size=10;
private int count = 0;
private String plate;
private String action;
public Garage() {
garage = new Car[10];
}
public void readData(String fileName) throws
FileNotFoundException {
StringTokenizer st = new StringTokenizer(fileName);
plate = st.nextToken();
action = st.nextToken();
System.out.println("I just read " + plate + " " + action);
}
public void arrive() {
if (count == 0) {
garage[count] = new Car(plate);
System.out.println(plate + " has been parked.");
count++;
} else if (count < 10) {
garage[count] = new Car(plate);
System.out.println(plate + " has been parked.");
count++;
} else if(count==10) {
System.out.println("We're sorry " + plate + ", at the moment we are
full");
}
}
public void depart() {
boolean found = false;
int index;
index = 0;
for (int i = 0; i < garage.length; i++) {
if (garage[i].toString().equals(plate)) {
found = true;
index = i;
break; }
}
if (found) {
if (index == 0) {
Car[] temp = new Car[10];
System.arraycopy(garage, 1, temp, 0, 9);
garage = temp;
System.out.println("Car " + plate + " have been removed");
count--;
} else {
for (int a = 0; a < index; a++) {
garage[a].movedOutTemporarily();
}
Car[] temp = new Car[10];
System.arraycopy(garage, 0, temp, 0, index );
System.arraycopy(garage, index + 1, temp, index, (garage.length -
1) - index);
System.arraycopy(temp, 0, garage, 0, garage.length-1);
count--;
System.out.println("Car " + plate + " have been removed");
}
} else {
System.out.println("We're sorry " + plate + ", has not parked in
this garage");
}
}
}
=======================================================================================
Car.java
public class Car {
private String licensePlate;
private int numberOfMoves=0;
public Car(String licenseNum) {
this.licensePlate = licenseNum;
}
public int getNumberOfMoveS() {
return numberOfMoves;
}
public void movedOutTemporarily() {
numberOfMoves++;
}
@Override
public String toString()
{
// Do not modify this method
return licensePlate.toString() ; // note: calls inherited toString
method
}
}
=======================================================================================
Tester.java
public class Tester {
public static void main(String[] args) throws IOException
{
Garage javaGarage = new Garage();
//Address of the text file
File myFile = new
File("C:\\Users\\Documents\\NetBeansProjects\\HW2\\garage.txt");
FileReader fileReader = new FileReader(myFile);
BufferedReader reader = new BufferedReader(fileReader);
String line;
while ((line = reader.readLine()) != null) {
javaGarage.readData(line);
StringTokenizer st = new StringTokenizer(line);
String plate = st.nextToken();
String action = st.nextToken();
switch (action) {
case "ARRIVE":
javaGarage.arrive();
break;
case "DEPART":
javaGarage.depart();
break;
}
}
}
=======================================================================================
Sample Output:

Feel free to reach out if you have any doubts.
Rate if the answer was helpful.
Kindly revert for any queries
Thanks.
The Bashemin Parking Garage contains a single lane that can hold up to ten cars. Arriving...
The laughs parking garage contains a single lane that hold up to ten cars. Cars arrive at the south end of the garage and leave from the north end. If a customer arrives to pick up a car that is not northernmost, all the cars to the north of his car are moved out, his car is driven out, and the others cars are restored in the same order that they were in originally. Whenever a car leaves, all the...
The CSC326 parking garage contains 2 lanes, each capable of holding up to 10 cars. There is only a single entrace/exit to the garage at one end of the lanes. If a customer arrives to pick up a car which is not nearest the exit, all cars blocking the car's path are moved into the other lane. If more cars still must be moved out of the way, they go into the street. When the customer's car is driven out,...
PLease, I need help with this Code. PLease create correctly
documentations comments for better understanding.
This is the input:
JAV001 ARRIVE
JAV002 ARRIVE
JAV003 ARRIVE
JAV004 ARRIVE
JAV005 ARRIVE
JAV001 DEPART
JAV004 DEPART
JAV006 ARRIVE
JAV007 ARRIVE
JAV008 ARRIVE
JAV009 ARRIVE
JAV010 ARRIVE
JAV011 ARRIVE
JAV012 ARRIVE
JAV013 ARRIVE
JAV014 ARRIVE
JAV006 DEPART
JAV014 DEPART
JAV013 DEPART
JAV005 DEPART
JAV015 ARRIVE
JAV010 DEPART
JAV002 DEPART
JAV015 DEPART
JAV014 DEPART
JAV009 DEPART
JAV003 DEPART
JAV008 DEPART
JAV007 DEPART
JAV012 DEPART
JAV011...
The Scratchemup parking garage contains a single lane that holds up to 10 cars. Cars arrive at the south end of the garage and leave from the north end. If a customerarrives to pick up a car that is not the northernmost, all cars to the north of his car are moved out, her car is driven out, and the other cars are restored in thesame order that they were in originally. Whenever a car leaves, all cars to the...
A parking garage charges a $2.00 minimum fee to park for up to three hours. The garage charges an additional $0.50 per hour in excess of these initial three hours. The maximum charge for any given 24 hour period is $10.00. Assume no car parks for longer than 24 hours at a time. Write a program that calculates and prints the total parking charges for the customers who parked their cars in this garage (at least 4 cars) and the...
Programming Assignment #2 (Arrays) I. The Assignment This assignment is to take your Garage class from the previous assignment and modify it so that it uses an array of Car objects as the principal data structure instead of an ArrayList-of-Car. This is an example of the OOP principle of information hiding as your Car and test classes will not have to be modified at all. Unless you broke encapsulationon the previous assignment, that is II. Specifications Specifications for all 3...
/*hello everyone. my question is mostly related to the garagetest part of this assignment that i've been working on. i am not sure how to read the file's contents AND put them into variables/an array. should it be in an arraylist? or maybe a regular array? or no arrays at all? i am also not sure how to call the factory method from garagec. i'm thinking something along the lines of [Garage garage = new GarageC.getInstance("GarageC", numFloors, areaofEachFloor);] but i...
Overview For this assignment, we will practice using stacks and queues. In this exercise, you will create two stacks and a queue to keep track of cars using a parking lot. We will use the nature of the stacks and queues to solve the problem. Specifications Rules FIU has opened a new valet parking lot next to the PC building that requires a special decal to park. If the car does not have the correct parking decal, the driver should...
Overview For this assignment, we will practice using stacks and queues. In this exercise, you will create two stacks and a queue to keep track of cars using a parking lot. We will use the nature of the stacks and queues to solve the problem. Specifications Rules FIU has opened a new valet parking lot next to the PC building that requires a special decal to park. If the car does not have the correct parking decal, the driver should...
using java:
For this exercise, you will design a set of classes that work
together to simulate a parking officer checking a parked car
issuing a parking ticket if there is a parking violation. Here are
the classes that need to collaborate:
• The ParkedCar class: This class should
simulate a parked car. The car has a make, model, color, license
number. •The ParkingMeter class: This class should
simulate a parking meter. The class has three parameters:
− A 5-digit...