Question: This program provides a simplified example for an AmusementPark with multiple Attractions and two types of riders, normal and fast that measures wait times. In

This program provides a simplified example for an AmusementPark with multiple Attractions and two types of riders, normal and fast that measures wait times. In order to better reflect Object-Oriented principles, much of the actual work takes place inside of the AmusementPark class. Follow the instructions below to implement the required code. In some cases I state how to explicitly create and classify store certain objects. There is a sample of the input, as well as the output file at the end of this problem. You will need to import classes where appropriate. There are a few variables which are included only to check that you fully understand abstract classes and methods, even though they have no other purpose.

Note: Simulated time simply means the minute starting from zero in the simulation.

Draw the UML diagram for the Rider, NormalRider and FastRider classes, and the TicketPrice interface as described in the program below. Be sure to use the correct connector types. (10)

interface TicketPrice (5)

This interface includes;

A BASEPRICE of type double set to 15.75

A setTicketPrice method with no parameters and a void return value.

A getTicketPrice method with no parameters and a double return value.

Neither method is implemented as a default method in this interface.

class Rider (10)

Rider is an abstract class.

It has three int instance variables:

startOnlineTime the simulated time the rider gets on a line

endOnlineTime the simulated time the rider gets on the ride

timeOnLine the amount of simulated time the rider waits on a line

It has two constructors:

There is a default constructor that does nothing.

There is a constructor with a single parameter that indicates the minute the Rider gets on a line.

This constructor calls the mutator to setStartOnlineTime.

There are the following methods:

There are accessors for all three values.

There is a setStartOnlineTime mutator that accepts a simulated time and sets startOnlineTime.

There is a method setEndOnLineTime that accepts the end of the time on the line. It sets the endOnlineTime and then calculates and sets the timeOnLine.

There are two abstract methods.

setType has no parameters and returns nothing.

getType has no parameters but returns an int.

class NormalRider (10) - Someone who pays a little less but may have to wait longer.

NormalRider is a non-abstract class that extends Rider and implements TicketPrice

It has two additional instance variables:

ticketPrice which is of type double

type which is an int.

There are two constructors:

There is a default constructor that does nothing.

There is a constructor with a single parameter that indicates the simulated minute the Rider gets on a line. This constructor uses super and then also call setType with no parameters.

There are the following methods:

There are accessors for both additional instance values that implement the abstract methods:

getTicketPrice implements the abstract method from TicketPrice

getType implements the abstract method in Rider and returns the value of type

setTicketPrice implements the abstract method in TicketPrice and sets the ticketPrice to the BASEPRICE.

setType implements the abstract method from Rider. It creates a Random object and then uses it to set the type variable to a value of between 1 and 5.

class FastRider (10) Someone who pays extra to wait less time

FastRider is a non-abstract class that extends Rider and implements TicketPrice

It has two additional instance variables:

ticketPrice which is a double

type which is an int.

There are two constructors:

There is a default constructor that does nothing.

There is a constructor with a single parameter that indicates the minute the Rider gets on a line. This constructor uses super and then also call setType with no parameters.

There are the following methods:

There are accessors for both additional instance values:

getTicketPrice implements the abstract method from TicketPrice

getType implements the abstract method in Rider and returns the value of type

setTicketPrice implements the abstract method in TicketPrice and sets the ticketPrice to 20% more than the BASEPRICE

setType implements the abstract method from Rider. It creates a Random object and then uses it to set the type variable to a value of between 1 and 10.

class Attraction (25)

Attraction is a class which simulates the queues with various riders waiting to get on an Attraction, as well as keeping track of who got on the ride.

The instance variables are:

A static int attractionCounter initially set to zero

A String attractionID

An int ratePerMinute for the Attraction

An ArrayList called alNormalLine of type NormalRider that can hold references to NormalRider objects

An ArrayList called alFastLine of type FastRider that can hold references to FastRider objects

An ArrayList called alGotOnRide of type Rider that can hold references to Rider objects and objects NormalRider and FastRider objects

It contains the following constructors:

A default constructor that sets attraction ID to the empty String

A constructor with a single parameter for the ratePerMinute that:

Calls the mutator setRatePerMinute with the ratePerMinute parameter

Calls mutator setAttractionID with no parameters.

Has the following methods:

Mutator setRatePerMinute accepts an int value and sets the ratePerMinute

Mutator setAttractionID has no parameters. It

Increments attractionCounter by 1

Sets the variable attractionID to the concatenation of RIDE and the attractionCounter value

Accessor methods for both of the above values.

For ArrayLists alNormalLine and alFastLine provides methods that add a NormalRider or a FastRider object, respectively, to the ArrayList. The NormalRider or FastRider is the parameter. (Can call the methods addRiderNormalLine and addRiderFastLine)

For ArrayLists alNormalLine and alFastLine provides methods that removes a NormalRider or FastRider object respectively from the ArrayList. The removal should be from the front of the ArrayList, that is the 0TH position. (Can call the methods removeRiderNormalLine and removeRiderFastLine). These methods return references to the NormalRider or FastRider respectively

There should be for each of the two ArrayLists above a method that can return as an int the size of the array. They can be called getAlNormalLineSize and getAlFastLineSize

There should also be a method addGotOnRide that adds a Rider of any type to the ArrayList alGotOnRide.

There should also be a method getGotOnRide with an int parameter that returns a Rider of any type from the ArrayList alGotOnRide at index i but doesnt remove it.

There should also be a method getAlGotOnRideSize that returns the size of alGotOnRide.

class AmusementPark (50) The class that simulates the AmusementPark model

This class creates riders, manages the queues for the attractions and prints out statistics in the end. Remember to import proper classes, including necessary IO classes

There are 3 instance variables;

A String with the parkName

An int numAttractions with the number of Attractions in the park

An ArrayList alAttraction of type Attraction containing references to the Attractions in the AmusementPark.

There are two constructors:

The default constructor calls:

setParkName with the empty String as the parameter which will set the parkName

setNumAttractions with a value of 0 as the parameter (sets numAttractions to 0)

createAttractions with a value of 0 as the parameter

The second constructor has parameters for the name (String) and numAttractions (int) and calls:

setParkName with the parkName as the parameter which will set the parkName

setNumAttractions with a value of equal to the second parameter that sets the numAttractions

createAttractions with a value of numAttractions

The following methods are provided:

The obvious accessor and mutator methods are provided to set and get the parkName and numAttractions.

The createAttractions method accepts the number of attractions

It creates a Random object with a seed of 2

For each attraction

Calculate the ratePerMinute for the attraction as between 10 and 15 riders per minute

Create an Attraction object using this ratePerMinute

Add the Attraction to the ArrayList alAttraction

The runThePark method accepts a duration in minutes as the input parameter and does the following:

Note: create temporary local variables as necessary.

Calculate the initialRiders as 23*numAttractions

for each initialRider (j=0; j < initialRiders; j++)

Select the Attraction for the rider in a round robin fashion

if j is divisible by 3 or 7

Create a new FastRider with startOnlineTime equal to 0

Add the Rider to the ArrayList alFastLine for the Attraction just selected

else

Create a new NormalRider with startOnlineTime equal to 0

Add the Rider to the ArrayList alNormalLine for the Attraction just selected

for each minute simulated starting at 1 minute through duration minutes:

Calculate the newRiders as 23*numAttractions

for each newRider (j=0; j < newRiders; j++)

Select the Attraction for the rider in a round robin fashion

if j is divisible by 3 or 7

Create a new FastRider with startOnlineTime equal to current minute

Add the Rider to the ArrayList alFastLine for the Attraction just selected

else

Create a new NormalRider with startOnlineTime equal to current minute

Add the Rider to the ArrayList alNormalLine for the Attraction just selected

Now process the riders for this minute

for each Attraction at the park

get the ratePerMinute (an int) for this Attraction and call it toBeProcessed

while toBeProcessed > 0

if the alFastLine for the Attraction is not empty and toBeProcessed is not divisible by 3

Remove a FastRider from alFastLine of the Attraction

Call setEndOnLineTime for the FastRider removed with the current time

Call addGotOnRide for the Attraction with a reference to the FastRider

Decrement toBeProcessed by one

else if the alNormalLine for the Attraction is not empty

Remove a NormalRider from alNormaLine of the Attraction

Call setEndOnLineTime for the NormalRider removed with the current time

Call addGotOnRide for the Attraction with a reference to the FastRider

Decrement toBeProcessed by one

else

set toBeProcessed equal to 0

The printParkStatistics method accepts a reference to a PrintWriter (Note must also throw an IOException)

Look at the sample out below:

Print out a Header Line: The Statistics for parkName

Print out the statistics for each Attraction as shown in the sample output amusestats.txt found in Programs/Lesson3/Homework tab.

class SimulatePark (10)

This class which includes main does the following:

Creates a Scanner to read from the terminal.

Read in the name of the AmusementPark.

Read in a number of attractions between 3 and 10 inclusively, excluding 7. (loop if value incorrect)

Create a single AmusementPark with the name and number of rides you have read in.

Read in a duration for the simulation of at least 60 minutes. (loop if value incorrect)

Call runThePark for the created AmusementPark with the parameter value of the duration of the simulation.

Create a PrintWriter object (remember to import correct classes and that you need to throw an IOException). You must request the name of the file to write to.

Call printParkStatistics with a reference to the PrintWriter object.

Close the PrintWriter object.

Sample Input/Output From The Terminal

Please enter the name of Amusement Park: Behesti JavaLand

Please enter the number of attractions

Number must be between 3 and 10 inclusively, excluding 7: 5

Please enter the duration of the simulation in minutes

Must enter 60 minutes or greater: 60

Please enter the name of the output file:

amusestats.txt

A Sample Output File

The Statistics for BEHESHTI JAVALAND

Statistics for Attraction RIDE1

The total number that got onto the ride is 840

There were 600 Fast Riders who got on waiting an average of 1.00 minutes

There were 240 Normal Riders who got on waiting an average of 21.76 minutes

There were 840 Total Riders who got on waiting an average of 6.93 minutes

Statistics for Attraction RIDE2

The total number that got onto the ride is 600

There were 420 Fast Riders who got on waiting an average of 10.00 minutes

There were 180 Normal Riders who got on waiting an average of 24.07 minutes

There were 600 Total Riders who got on waiting an average of 14.22 minutes

Statistics for Attraction RIDE3

The total number that got onto the ride is 720

There were 480 Fast Riders who got on waiting an average of 7.00 minutes

There were 240 Normal Riders who got on waiting an average of 21.76 minutes

There were 720 Total Riders who got on waiting an average of 11.92 minutes

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!