Question: Object - Oriented Approach Problem Part 2 I asked for part 1 and i am continue asking. The language is Java. Implement a Ticket class
ObjectOriented Approach Problem Part I asked for part and i am continue asking. The language is Java. Implement a Ticket class with the following UML diagram.
When a vehicle is parked, a Ticket object is created containing the vehicle itself and entry
date of the vehicle.
You have to use this keyword in the implementation of the constructor.
Consider the following example which demonstrates the creation of a Ticket object:
Ticket ticket new Ticket vehicle entryDate;
CalculatePrice method takes a double value of hourly price and exit date of the
vehicle, then calculates the price of parking service by considering how many hours the
vehicle is parked and the size of the vehicle. The totalPrice field of the Ticket
object should also be updated in this method.
You can calculate the parking cost with the following formula:
Parking cost vehicleSize hourlyPrice numberOfHours
It should be noted that the numberOfHours value should be rounded upExample: If a car
parked for hours and minutes, then you should charge the parking cost with hours.
The getTicketInfo method returns a string value based on two conditions.
If the vehicle does not exit from the car park up to now, then the string should
have the vehicle's plate number and entry date.
Example:
Ticket Info
Plate Number : CSE
Entry : Fri Dec :: EET
If the vehicle exited from the car park, then the string should have the vehicle's
plate number, entry date, exit date, and the total price for parking service.
Example:
Ticket Info
Plate Number : CSE
Entry : Fr Dec :: EET
Exit : Fri Dec :: EET
Hour :
Fee :
getVehicle method returns the Vehicle object of the Ticket object.
getPrice method returns the totalPrice field of the Ticket object.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
