Java: Create the vehicle class UI transformation for the parking garage project as shown below: // Make sure the code is running with no errors • The parking lot has multiple levels. Each level has multiple rows of spots. • The parking lot can park motorcycles, cars, and buses. • The parking lot has motorcycle spots, compact spots, and large spots. • A motorcycle can park in any spot. • A car can park in either a single compact spot or a single large spot. • A bus can park in five large spots that are consecutive and within the same row. It cannot park in small spots. public enum VehicleSize { Motorcycle, Compact, Large }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Java: Create the vehicle class UI transformation for the parking garage project as shown below:

// Make sure the code is running with no errors

• The parking lot has multiple levels. Each level has multiple rows of spots.

• The parking lot can park motorcycles, cars, and buses.

• The parking lot has motorcycle spots, compact spots, and large spots.

• A motorcycle can park in any spot.

• A car can park in either a single compact spot or a single large spot.

• A bus can park in five large spots that are consecutive and within the same row. It cannot park in small spots.

public enum VehicleSize { Motorcycle, Compact, Large }

public abstract class Vehicle {

protected ArrayList parkingSpots = new ArrayList();

protected String licensePlate;

protected int spotsNeeded;

protected VehicleSize size;

public int getSpotsNeeded() { return spotsNeeded; }

public VehicleSize getSize() { return size; }

/* Park vehicle in this spot (among others, potentially) */

public void parkInSpot(ParkingSpot s) { parkingSpots.add(s); }

/* Remove car from spot, and notify spot that it's gone */

public void clearSpots() { ... }

/* Checks if the spot is big enough for the vehicle (and is  available). This compares the SIZE only. It does not check if it  has enough spots. */

public abstract boolean canFitInSpot(ParkingSpot spot);

}

public class Bus extends Vehicle {

public Bus() {

spotsNeeded = 5;

size = VehicleSize.Large;

}

/* Checks if the spot is a Large. Doesn't check num of spots */

public boolean canFitInSpot(ParkingSpot spot) { ... }

}

public class Car extends Vehicle {

public Car() {

spotsNeeded = 1;

size = VehicleSize.Compact;

}

/* Checks if the spot is a Compact or a Large. */

public boolean canFitlnSpot(ParkingSpot spot) { ... }

}

public class Motorcycle extends Vehicle {

public Motorcycle() {

spotsNeeded = 1;

size = VehicleSize.Motorcycle;

}

public boolean canFitInSpot(ParkingSpot spot) { ... }

}

public class ParkingLot {

private Level[ ] levels;

private final int NUM_LEVELS = 5;

public ParkingLot() { ... }

/* Park the vehicle in a spot (or multiple spots). Return false if failed. */

public boolean parkVehicle(Vehicle vehicle) { ... }

}

/* Represents a level in a parking garage */

public class Level {

private int floor;

private ParkingSpot[ ] spots;

private int availableSpots = 0; // number of free spots

private static final int SPOTS_PER_ROW = 10;

public Level(int flr, int numberSpots) { ... }

public int availableSpots() { return availableSpots; }

/* Find a place to park this vehicle. Return false if failed. */

public boolean parkVehicle(Vehicle vehicle) { ... }

/* Park a vehicle starting at the spot spotNumber, and continuing until vehicle.spotsNeeded. */

private boolean parkStartingAtSpot(int num, Vehicle v) { ... }

/* Find a spot to park this vehicle. Return index of spot, or -1 on failure. */

private int findAvailableSpots(Vehicle vehicle) { ... }

/* When a car was removed from the spot, increment availableSpots */

public void spotFreed() { availableSpots++; }

}

/*The parkingSpot is implemented by having just a variable which represents the size of the spot. We could have implemented this by having classes for LargeSpot, CompactSpot, and MotorcycleSpot which inherit from ParkingSpot, but this is probably overkill. The spots probably do not have different behaviors, other than their sizes. */

Public class ParkingSpot {

private Vehicle vehicle;

private VehicleSize spotSize;

private int row;

private int spotNumber;

private Level level;

public ParkingSpot(Level Ivl, int r, int n, VehicleSize s) {...}

public boolean isAvailable() { return vehicle == null; }

/* Check if the spot is big enough and is available */

public boolean canFitVehicle(Vehicle vehicle) { ... }

/* Park vehicle in this spot. */

public boolean park(Vehicle v) { ... }

public int getRow() { return row; }

public int getSpotNumber() { return spotNumber; }

/* Remove vehicle from spot, and notify level that a new spot is available */

public void removeVehicle() { ... }

}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY