Question: Need help with the following assignment. Please try to use my code and figure out where I went wrong, and what I have to do
Need help with the following assignment. Please try to use my code and figure out where I went wrong, and what I have to do to fix it. Please don't use any imports and stick to basic java. I'd love to see some code example. We are beginning our dive into multi-object Java programs with a simple demonstration of a parking lot. For this programming problem, submit your work to the Homework #1 link on Brightspace (and remember to ensure the .java files are included and not .class files!). There are four .java files expected (one for each class, defined below). We will look at homework submission again soon. This assignment will likely be review from COS125, but be careful to not underestimate it! Write a small program that implements a parking lot manager. Your program should implement the following classes: Car:
Contains two strings for manufacturer and color. It also contains a boolean representing whether this car has handicap-accessible parking.
Implements a constructor that takes the aforementioned five instance variables.
ParkingSpot:
Contains an instance of Car describing the car currently parked in this spot.
Contains a boolean variable handicap, set to true if the spot is handicap accessible.
Implements a constructor that takes the aforementioned boolean.
ParkingLot:
Contains an array of twenty ParkingSpots, four of which must be handicap accessible.
Implements a constructor that creates the aforementioned array.
Implements a method that takes a Car and parks it in an appropriate available parking spot. This method should return an int representing the chosen index of the chosen parking spot in the array.
Implements a method that takes an int and removes and returns the specified Car from the given Parking Spot.
Implement and override toString() to return a string containing the number of handicap accessible and standard parking spots available separated by a single space (X Y)
ParkingTester:
Contains only a main class that performs the following operations:
Instantiate a ParkingLot
Print the ParkingLot by calling its ToString() method
Instantiate a Car that represents a Red Infiniti, with handicap accessible tags
Park this Car in the ParkingLot Print the ParkingLot by calling its ToString() method
Instantiate a Car entirely that represents a Gray Cadiliac, non-handicap Park this Car in the ParkingLot Print the ParkingLot by calling its ToString() method
Remove the first Car (the Red Infiniti) from the ParkingLot
Print the ParkingLot by calling its ToString() method Your output should appear in the console, and look like the following:
4 16
3 16
3 15
4 15 Current Code:
Car.java --
public class Car {
String manufacturer;
String color;
boolean handicap;
public Car(String manufacturer, String color, boolean handicap) {
this.manufacturer = manufacturer;
this.color = color;
this.handicap = handicap;
}
}
ParkingLot.java--
public class ParkingLot {
ParkingSpot[] spots;
public ParkingLot() {
spots = new ParkingSpot[20];
for (int i = 0; i < 20; i++) {
if (i < 4) {
spots[i] = new ParkingSpot(true);
} else {
spots[i] = new ParkingSpot(false);
}
}
}
public String toString() {
int handicapCount = 0;
int standardParkingSpots = 0;
for (int i = 0; i < 4; i++) {
if (spots[i] == null) {
handicapCount++;
}
}
for (int i = 4; i < 20; i++)
if (spots[i] == null) {
standardParkingSpots++;
}
return (handicapCount + " " + standardParkingSpots);
}
}
ParkingSpot.java--
public class ParkingSpot { Car parkedCar; boolean handicap;
public ParkingSpot(boolean handicap) { this.handicap = handicap; } }
ParkingTester.java--
public class ParkingTester {
public static void main(String[] args) {
ParkingLot Parking = new ParkingLot();
Parking.toString();
System.out.println(Parking);
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
