Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How to do 8.4 and 8.5 To do in Java P8.4 Simulate a car sharing system in which car commuters pick up and drop off

How to do 8.4 and 8.5

image text in transcribed

To do in Java

image text in transcribed

image text in transcribed

image text in transcribed

P8.4 Simulate a car sharing system in which car commuters pick up and drop off passengers at designated stations. Assume that there are 30 such stations, one at every mile along a route. At each station, randomly generate a number of cars and passengers, each of them with a desired target station Each driver picks up three random passengers whose destination is on the way to the car's destination, drops them off where requested, and picks up more if possible. A driver gets paid per passenger per mile. Run the simulation 1,000 times and report the average revenue per mile. Use classes Car, Passenger, Station, and Simulation in your solution. P8.5 In Exercise .. P8.4, drivers picked up passengers at random. Try improving that scheme. Are drivers better off picking passengers that want to go as far as possible along their route? Is it worth looking at stations along the route to optimize the loading plan? Come up with a solution that increases average revenue per mile, Define a class Car that represents a car. This class is used for loading and unloading Passenger. In this class define a default constructor that initializes the instance members. Define a method pickPassenger that picks a Passenger if space is available. Define a method dropPassenger that drops all Passenger whose destination is reached and collects the revenue from the Passenger Define a method spaceAvailable that checks if the space is available in the Car. Define a method getRevenueCollected that returns the revenue collected by the Car till now. Define a method getRevenueCollected that returns the number of miles driven by the Car till now Define a method moveToNextStation that makes this car move to the next Station Define a method isDestination Reached that checks whether the destination is reached or not. Define a method toString to return the Car status in String form Define a method getCurrentPassengers that returns the number of Passenger present in the Car. Define a method getDestination that returns the destination of the Car - Define a method getPassengers that returns the ArrayList containing all the Passenger present in the Car Define a class Passenger that represents a Passenger. - In this class define a method getDestination that returns the destination of the Passenger - Define a method getStartStation that returns the start station of the Passenger - Define a method check Destination Reached that checks if the destination of the Passenger is reached or not Define a method payFare that computes and pays the fare for the journey. Override the toString method to return the String representing the Passenger - Define a class Station that represents a Station Define a method addCar that adds the Car to the Station Define a method addCars that adds all Car in the given ArrayList. - Define a method addPasssenger that adds a Passenger to the Station Define a method get TotalMiles that returns the total number of miles driven by the Car till this Station Define a method get Total RevenueGenerated that returns the total revenue collected by the Car till this Station Define a method collectRevenue that computes the total revenue generated by the Car till this station Define a method loadUnloadPassengers that unloads the Passenger whose destination is reached and loads more Passenger, Define a method moveCars that returns the list of Car that needs to move to the next Station Override the equals method that test whether two Station are equal or not. Define a method printAllCars that prints all Car present at the Station Override the toString method to print the Station number Define a class Simulation that simulates the whole Car sharing system, . In this class define a method addStation that adds a new Station Define a method getStation that returns the given Station. - Define a method generateCars that generates random number of Car with random destination Define a method getMiles that returns the number of miles for the complete simulation Define a method getRevenue that returns the revenue for the complete Simulation Define a method generatePassengers that generates random number of Passenger with random destination Define a method move ToNextStation that moves the simulation to the next Station. Define a main method In main create a for loop to run the simulation for 1000 times w e JUN TUNTUI. Define a class Simulation that simulates the whole Car sharing system. . In this class define a method addStation that adds a new Station, Define a method getStation that returns the given Station Define a method generate Cars that generates random number of Car with random de: Define a method getMiles that returns the number of miles for the complete simulation. Define a method getRevenue that returns the revenue for the complete Simulation, Define a method generatePassengers that generates random number of Passenger with random destination. Define a method move ToNextStation that moves the simulation to the next Station. Define a main method. In main create a for loop to run the simulation for 1000 times. . In this loop create a Simulation object. Add Stations to the simulation using the addStation method. Add Passenger and Car to each Simulation object using the generatePassengers and generate Cars methods respectively. - Move Car to next station using the move ToNextStation method. Find the revenue per mile for the complete simulation. After the main loop completes, display the average revenue per mile

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Theory Icdt 97 6th International Conference Delphi Greece January 8 10 1997 Proceedings Lncs 1186

Authors: Foto N. Afrati ,Phokion G. Kolaitis

1st Edition

3540622225, 978-3540622222

More Books

Students also viewed these Databases questions