Project 6_ Parking Lot with rubrics

docx

School

CUNY Queens College *

*We aren’t endorsed by this school

Course

11213

Subject

Computer Science

Date

Feb 20, 2024

Type

docx

Pages

4

Uploaded by SargentPuppyMaster2720

Report
Project 6: Parking Lot (This is a tough one, but you can do it) In this Java programming assignment, you will practice using classes and methods to manage a parking structure. I.Design a class called ParkingSpace in a file called ParkingSpace.java . This class will hold four instance variables, one constructor, and six methods. II.Create four instance variables for your class ( spaceNum, floor, isCompact, isOccupied ). The descriptions of these variables are provided below. a. The spaceNum variable is an integer(int). It holds the number associated with this parking space (i.e., the 7 in “A7”). b. The floor variable is a character(char). This holds a character associated with the floor the parking space appears on (i.e., the A in “A7”). c. The isCompact variable is a boolean. This is used to determine whether the parking space is designed for a compact car or not. d. The isOccupied variable is a boolean. This is used to determine whether a car is currently in this parking space. III.Write one constructor for this class, taking three arguments. The arguments should represent the space number, the floor, and whether the parking space is for compact cars (make sure the arguments are listed in this order so the tests pass). Set each of these fields to the input values, and then set the isOccupied variable to false. IV.Write the following methods for the ParkingSpace class: a. Write accessor methods for each of the instance variables (getSpaceNum, getFloor, getCompact, getOccupied). These should simply return the current value of the instance variable. b. Write a mutator method, setOccupied . This method should take one boolean argument, changing the value of isOccupied to this value. c. Write a toString method for the class that produces output as shown below. The legend for the parking lot is as follows: C – compact only; N – any car; X – occupied; O – not occupied. “A1 (C X)” (this space is for compact cars, and is occupied) “B9 (N O)” (this space is for any car, and is not occupied) V.Design a class called ParkingLot in a file called ParkingLot.java . This class will hold three instance variables, one constructor, and two methods.
VI. Create three instance variables for your class (parkingLot, numSpaces, numFloors). The descriptions of these variables are provided below. a. The parkingLot variable is an array of ParkingSpace objects. This holds information for all of the parking spaces in the ParkingLot. b. The numSpaces variable is an integer. This holds the number of spaces on each floor. c. The numFloors variable is an integer. This holds the total number of floors in the lot. VII. Write one constructor, taking two integer arguments. These represent the number of spaces per floor and number of floors in the lot respectively. Set the instance variables for each corresponding argument. Create a new ParkingSpace array with number of Spaces elements. Initialize each space in this array with a new ParkingSpace object following the pattern described below. a. Label the floors starting with “A” and continuing alphabetically (you are not responsible for parking lots with more than 26 floors). b. Each floor should have spaces labeled 0 to n, where n represents the total number of spaces per floor of the parking structure. c. The first four spaces per floor should be designated as being for compact cars only. Your parking lot is always guaranteed to be initiated with more than four spaces per floor, so don't worry about a case where you have less. VIII.Write the following methods for the ParkingLot class: a. The enterLot method should take one boolean argument that indicates whether or not the car is compact and return a ParkingSpace object. The space that should be returned is the first open space that works for the given car. If the car is a compact model, it can occupy any space in the lot. If it is not compact, then it can only take the first open space that is not compact. Once the appropriate space has been determined, set it as occupied and return the ParkingSpace object at that position. Do not worry about a case where the parking lot is full. b. The leaveLot method should take a ParkingSpace object and return no value. Given the input ParkingSpace object, determine the corresponding parking space to manipulate, and then set it as unoccupied. IX. Submit your ParkingSpace.java and ParkingLot.java files on BlackBoard. You will use my own main method to test your program. This means that your method signatures should be exactly as specified in this document and make sure ParkingSpace and ParkingLot are uploaded as two separate files.
You should write the main method to test your code but do not submit it. You should use the advanced java settings. Rubrics: Class ParkingSpace compiles: 4 spaceNum variable exist and is an integer(int). 2 floor variable exist and is a character(char). 2 isCompact variable exist andis a boolean. 2 isOccupied variable exist and is a boolean. 2 one constructor for this class, taking three arguments. Creates object as described. 4 IV.Write the following methods for the ParkingSpace class: accessor methods exist and return correct value for each of the instance variables 8 (2pts each) mutator method, setOccupied exist and set the proper value to correct location 2 a toString method for the class that produces the described output 4 Class ParkingLot compiles 4 parkingLot variable exists and is an array of ParkingSpace objects. 2 numSpaces variable exists and is an integer. 2 numFloors variable exists and is an integer. 2 one constructor for this class, taking two arguments. Creates an object as described. 9 The enterLot method exists and sets the proper value to the correct location. 4 The leaveLot method exists and sets the proper value to the correct location 4
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help