Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please I need help on this assignment. I would really appreciate your help. please provide comments so i know what your doing I. The Assignment

Please I need help on this assignment. I would really appreciate your help. please provide comments so i know what your doing

I. The Assignment

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.

When a car arrives, the message will include the license number and state whether the car is being parked or turned away because the garage is full. If the garage is full, the car leaves without ever having entered the garage.

When a car departs, the message will include the license number and the number of times the car was moved.

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

Create separate classes to implement a Car and a Garage

The Car class will have private instance variables that store the license number and number of times the car has been moved, and any methods you discover to be necessary

The Garage class must use an array (not an ArrayList) of Car objects to implement the garage

To handle the arrival and departure of each car, your Garage class must implement separate methods arrive() and depart(), each of which returns a String showing the result of the operation (see above).

Your garage class may contain other methods should you find them necessary or advisable.

Also write a test class that reads the operations from the input file, echoes each to the output file, calls the appropriate Garage class method, and writes the String returned to the output file.

As stated in 4. and 6. above, all output is to be done in the test class. None of the Garage or Car class methods do any output

Make sure your classes adhere to the style and documentation standards discussed in class and in online notes

Below is the .txt file

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 JAV013 DEPART JAV009 DEPART JAV003 DEPART JAV008 DEPART JAV007 DEPART JAV012 DEPART JAV011 DEPART 

Ive provided you with the code I made myself and what I have so far. The issue that Im having is how can I read and print the file to another text file with the assigned task given from the assignment

package garagetester;

public class Car { //instance variable that stores license numbers private String licenseNumber; //instance variable that stores number of times car moved private int moves; /** * Constructor to initialize the instance variable * @param licenseNumber */ public Car(String licenseNumber) { this.licenseNumber = licenseNumber; //initialize string variable this.moves = 0; //initialize number of moves to zero }//end of constructor /** * Method that returns the number of moves * @return moves */ public int getMoves() { return this.moves; }//end of method /** * Method that increments the number of moves */ public void setMoves() { this.moves ++; }//end of method /** * Method that returns the license Number as a string * @return licenseNumber */ public String getLicense() { return licenseNumber; }//end of method }//end class

package garagetester;

public class Garage { //instance variable of array of cars private Car [] car; //instance variable of number of cars parked private int carsParked; //instance variable setting array size to 10 private final int SIZE = 10; /** * Constructor that create an array of car objects of 10 elements * initialize the number of cars being parked. */ public Garage() { //array object of car holding 10 elements this.car = new Car [SIZE]; //initialize number of cars parked to zero this.carsParked = 0; }//end constructor /** * Method that returns the number of cars parked in the garage * @return carsParked */ public int getCarsParked() { return carsParked; }//end method /** * Method that checks to see if there's available spots to park the car * otherwise send the message that the parking garage is full * @param car * @return message */ public String arrive(Car car) { String arriveMessage = ""; if(getCarsParked() > this.car.length) { arriveMessage = "Sorry " + car.getLicense() + "Garage is full!!"; } else if(getCarsParked() < this.car.length) { parkCar(car); arriveMessage = "The car " + car.getLicense() + " is parked. "; } return arriveMessage; }//end method /** * Method that adds the car to the garage * @param car */ public void parkCar(Car car) { //adding the cars this.car[getCarsParked()] = car; //incrementing the number of cars parked this.carsParked ++; }//end method public String depart(Car car) { /* String variable that holds and prints out the license plate as well as the number of times it moved out of the garage. */ String departMessage = ""; /* For loop that goes through each parking spot */ for (int i = 0; i < this.car.length; i++) { /* finds the car in that specific parking spot */ if(this.car[i] == car) { /* Removes that car from that parking spot */ this.car[i] = null; /* Move the cars up one spot after previous car was removed */ for(int j = i + 1; j < this.car.length; j++) { /* if the parking spot is not empty it moves the car up one and sets the previous parking spot empty. */ if(this.car[j] != null) { this.car[j-1] = this.car[j];//moves car up one spot this.car[j-1].setMoves();//increment the number of time the car moved this.car[j] = null;//clears the previous parking spot } } this.carsParked --;//decreases the number of cars parked //prints out the message of departure departMessage = car.getLicense() + " just left. " + "It has been moved " + car.getMoves() + " times."; } } //returns the message printed return departMessage; }//end method }//end class

package garagetester; import java.io.File; import java.util.Scanner; import java.io.IOException; import java.io.PrintWriter;

public class GarageTester { static void main(String[] args) throws IOException { //Create a garage object name garage Garage garage = new Garage(); //Create a scanner object to read the text file Scanner in = new Scanner(new File("/Users/nelsonmontenegro/Downloads/garage.txt")); PrintWriter toFile = new PrintWriter("/Users/nelsonmontenegro/Downloads/output.txt"); while(in.hasNext()) { String license = in.next(); String action = in.next(); if(action.equalsIgnoreCase("Arrive")) { //dont know what to call here } else if(action.equalsIgnoreCase("Depart")) { //dont know what to call here } } toFile.close(); }//end main }//end class

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Systems A 360-degree Approach

Authors: Jawwad ShamsiMuhammad Khojaye

1st Edition

0429531575, 9780429531576

More Books

Students also viewed these Databases questions

Question

Outline Aquinass methodology.

Answered: 1 week ago