Write a CarParking class to model a multistory car parking building. This class should contain a 3- dimensional array of type Vehicle. The third dimension of the array simply represents the number of floors of the building while the first and second dimensions are the number of rows and columns in every floor. By default, there are 3 floors, 7 rows and 7 columns in a building. However, the user should be able to specify the maximum number of floors, rows and columns at the time of creating a CarParking object. In addition to the constructors, this class should provide the following methods: o public boolean isOccupied (int floor, int row, int col) this method returns true if the location specified by the floor, row and column is already occupied by a vehicle. o public void add (Vehicle v) this method will add the vehicle at the next empty slot. Slots are field row by row (from left to right) starting from the ground floor. o public Vehicle remove (int floor, int row, int col, double rate) this method to removes the vehicle at the specified location and returns the parking fee. The fee is calculated by multiplying the rate by the duration (in minutes). Drivers will receive 5% discount per floor other than the ground floor. If the location is not occupied, the method returns zero. public double getTotalExpectedRevenue(double[] rates, Date exitTime) this method calculates the total expected revenue if all cars exit the building at the given exitTime. The rates array will contain an element for every vehicle type (Sedan, SUV, Truck). public int getVehicleCount(String type, int floor) this method finds and returns the total number of cars for a given type in a given floor. o public double getRevenue (String type, int floor, double rate) this method finds and returns the total revenue of a given car type in a given floor for a given rate. o public boolean canOrganizeByType ( this method should return true if it is possible to accommodate all cars of the same type in separate floors.

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
2- Write a CarParking class to model a multistory car parking building. This class should contain a 3-
dimensional array of type Vehicle. The third dimension of the array simply represents the number of
floors of the building while the first and second dimensions are the number of rows and columns in every
floor. By default, there are 3 floors, 7 rows and 7 columns in a building. However, the user should be able
to specify the maximum number of floors, rows and columns at the time of creating a CarParking object.
In addition to the constructors, this class should provide the following methods:
O
public boolean isOccupied (int floor, int row, int col) this method returns true if the location
specified by the floor, row and column is already occupied by a vehicle.
public void add (Vehicle v) this method will add the vehicle at the next empty slot. Slots are field
row by row (from left to right) starting from the ground floor.
public Vehicle remove (int floor, int row, int col, double rate) this method to removes the
vehicle at the specified location and returns the parking fee. The fee is calculated by multiplying
the rate by the duration (in minutes). Drivers will receive 5% discount per floor other than the
ground floor. If the location is not occupied, the method returns zero.
O
O
public double getTotalExpectedRevenue(double[] rates, Date exitTime) this method
calculates the total expected revenue if all cars exit the building at the given exitTime. The rates
array will contain an element for every vehicle type (Sedan, SUV, Truck).
o public int getVehicle Count(String type, int floor) this method finds and returns the total number
of cars for a given type in a given floor.
public double get Revenue (String type, int floor, double rate) this method finds and returns
the total revenue of a given car type in a given floor for a given rate.
public boolean canOrganizeByType ( this method should return true if it is possible to
accommodate all cars of the same type in separate floors.
O
O
O
3- Write a Java program that uses the CarParking class and the Vehicle class to simulate a car parking
building. The program should start by constructing a CarParking object. The user should then be presented
with a menu to select one of the following actions:
●
●
Add a vehicle: This option constructs a vehicle object and adds it to the parking. The user should
be required to enter the vehicle type.
Remove a vehicle: This option removes a vehicle from the building and display its the parking
fees. The user should be prompted to enter the location and the rate.
Display statistics: this option will show a summary including:
i. Total expected revenue
ii. Number of sedans, SUVs and trucks per floor
iii. Revenue of sedans, SUVs and trucks per floor
iv. Number of empty slots per floor
Check arrangement: as a result of this selection the program should display one of the following
messages :
i. Cars can be arranged based on their type
ii. Not possible to rearrange cars based on their type.
Exit the program: This option will terminate the program
- Hints:
1- Use the java.util.Date class to represent the time. This class contain several methods that allow you to
find for example the time difference in minutes between any two times.
Transcribed Image Text:2- Write a CarParking class to model a multistory car parking building. This class should contain a 3- dimensional array of type Vehicle. The third dimension of the array simply represents the number of floors of the building while the first and second dimensions are the number of rows and columns in every floor. By default, there are 3 floors, 7 rows and 7 columns in a building. However, the user should be able to specify the maximum number of floors, rows and columns at the time of creating a CarParking object. In addition to the constructors, this class should provide the following methods: O public boolean isOccupied (int floor, int row, int col) this method returns true if the location specified by the floor, row and column is already occupied by a vehicle. public void add (Vehicle v) this method will add the vehicle at the next empty slot. Slots are field row by row (from left to right) starting from the ground floor. public Vehicle remove (int floor, int row, int col, double rate) this method to removes the vehicle at the specified location and returns the parking fee. The fee is calculated by multiplying the rate by the duration (in minutes). Drivers will receive 5% discount per floor other than the ground floor. If the location is not occupied, the method returns zero. O O public double getTotalExpectedRevenue(double[] rates, Date exitTime) this method calculates the total expected revenue if all cars exit the building at the given exitTime. The rates array will contain an element for every vehicle type (Sedan, SUV, Truck). o public int getVehicle Count(String type, int floor) this method finds and returns the total number of cars for a given type in a given floor. public double get Revenue (String type, int floor, double rate) this method finds and returns the total revenue of a given car type in a given floor for a given rate. public boolean canOrganizeByType ( this method should return true if it is possible to accommodate all cars of the same type in separate floors. O O O 3- Write a Java program that uses the CarParking class and the Vehicle class to simulate a car parking building. The program should start by constructing a CarParking object. The user should then be presented with a menu to select one of the following actions: ● ● Add a vehicle: This option constructs a vehicle object and adds it to the parking. The user should be required to enter the vehicle type. Remove a vehicle: This option removes a vehicle from the building and display its the parking fees. The user should be prompted to enter the location and the rate. Display statistics: this option will show a summary including: i. Total expected revenue ii. Number of sedans, SUVs and trucks per floor iii. Revenue of sedans, SUVs and trucks per floor iv. Number of empty slots per floor Check arrangement: as a result of this selection the program should display one of the following messages : i. Cars can be arranged based on their type ii. Not possible to rearrange cars based on their type. Exit the program: This option will terminate the program - Hints: 1- Use the java.util.Date class to represent the time. This class contain several methods that allow you to find for example the time difference in minutes between any two times.
1. Introduction:
In crowded cities, it's very crucial to provide enough parking spaces for vehicles. These are usually multistory
buildings where each floor is divided into rows and columns. Drivers can park their cars in exchange for some
fees. A single floor can be modeled as a two-dimensional array of rows and columns. A building consists of
several floors. See Figure 1 for an illustration.
Figure 1: A Multistory car parking
2. To Do:
1- Write a Java class that models a Vehicle. There are three types of vehicles (Sedan, SUV, Truck). Every
vehicle object should also contain an instance variable that can be used to store the time at which the
vehicle has entered the car parking building (Hint: use the java.util.Date class to represent the time). In
addition to the constructors, you should provide the following methods:
public double getDuration(Date exitTime) this method will return the duration (in minutes) from
the time the vehicle entered the parking until the given exitTime.
public String getType() this method will return either Sedan or SUV or Truck based on the vehicle
type.
-
public void setType(String type) this method will set the type of the vehicle to either Sedan or SUV
or Truck.
public void setEntryTime(Date entry Time) this method will set the time at which the vehicle has
entered the parking.
Transcribed Image Text:1. Introduction: In crowded cities, it's very crucial to provide enough parking spaces for vehicles. These are usually multistory buildings where each floor is divided into rows and columns. Drivers can park their cars in exchange for some fees. A single floor can be modeled as a two-dimensional array of rows and columns. A building consists of several floors. See Figure 1 for an illustration. Figure 1: A Multistory car parking 2. To Do: 1- Write a Java class that models a Vehicle. There are three types of vehicles (Sedan, SUV, Truck). Every vehicle object should also contain an instance variable that can be used to store the time at which the vehicle has entered the car parking building (Hint: use the java.util.Date class to represent the time). In addition to the constructors, you should provide the following methods: public double getDuration(Date exitTime) this method will return the duration (in minutes) from the time the vehicle entered the parking until the given exitTime. public String getType() this method will return either Sedan or SUV or Truck based on the vehicle type. - public void setType(String type) this method will set the type of the vehicle to either Sedan or SUV or Truck. public void setEntryTime(Date entry Time) this method will set the time at which the vehicle has entered the parking.
Expert Solution
steps

Step by step

Solved in 4 steps with 11 images

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