Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Problem people who are waiting at the station 4 String toString() that prints the people on a station 4. Each driver picks up a

Java Problem

image text in transcribed

image text in transcribedpeople who are waiting at the station 4 String toString() that prints the people on a station

4. Each driver picks up a maximum of three passengers (whose destination is either the same as car's destination or on the way to the car's destination), and drops them off where requested, and picks up more if possible. A driver gets paid per passenger per mile. Complete classes Car, Passenger, Station, Simulation in your solution. Create a class Passenger with attributes String name and int destination. Create a custom constructor public Passenger (String name, int dest). - Write down the getter method getDestination () to determine the destination of the passenger - Write a toString () method to print the name and destination of the passenger. Create a class Car, which has attributes int idNo, int destination, int location, ArrayList passengers, double faresCollected, int milesDriven, double FAREPERMILE = 1.0, and int MAXPASSENGERS = 3. - Create a custom constructor to initialize idNo, location, and destination. Create getter methods getIdNo, get Location, getDestination, getFares, getMilesDriven and getPassengers. - Write getter methods public boolean hasArrived() to know whether the car has arrived its destination and public boolean hasRoom () to know whether the number of passengers in a car is within its maximum capacity. - Write mutator method public void drive (), which drives to the next station. If the car is already at its destination, nothing happens. Note that you should also collect fares. Also print out Car X drives to station Y, as shown in sample output (see Appendix B). - Write method public boolean dropoff(). This method drops off any pas- sengers who have arrived, and return true or false depending on if someone is dropped. If someone is dropped, also prints Car X drops off Y at station Z. Now has W passengers, as shown in the sample output (see Appendix B). - Write method public boolean add (Passenger p). This method adds a passenger if there is a room and return true or false depending on the passenger can be added or not. - Write the toString() method to print the car id number, location, destination, and passengers. Create a class Station with attributes int station Number and an array list people of type Passenger. Create a custom constructor Station (int number) and getter method get Number (). Also create the following methods: - void add (Passenger p) that adds a passenger on the station - Passenger get (int index) that returns the index of a passenger - Passenger remove (int index) that removes a passenger from the station ArrayList peopleWaitingList () that returns the list of 4. Each driver picks up a maximum of three passengers (whose destination is either the same as car's destination or on the way to the car's destination), and drops them off where requested, and picks up more if possible. A driver gets paid per passenger per mile. Complete classes Car, Passenger, Station, Simulation in your solution. Create a class Passenger with attributes String name and int destination. Create a custom constructor public Passenger (String name, int dest). - Write down the getter method getDestination () to determine the destination of the passenger - Write a toString () method to print the name and destination of the passenger. Create a class Car, which has attributes int idNo, int destination, int location, ArrayList passengers, double faresCollected, int milesDriven, double FAREPERMILE = 1.0, and int MAXPASSENGERS = 3. - Create a custom constructor to initialize idNo, location, and destination. Create getter methods getIdNo, get Location, getDestination, getFares, getMilesDriven and getPassengers. - Write getter methods public boolean hasArrived() to know whether the car has arrived its destination and public boolean hasRoom () to know whether the number of passengers in a car is within its maximum capacity. - Write mutator method public void drive (), which drives to the next station. If the car is already at its destination, nothing happens. Note that you should also collect fares. Also print out Car X drives to station Y, as shown in sample output (see Appendix B). - Write method public boolean dropoff(). This method drops off any pas- sengers who have arrived, and return true or false depending on if someone is dropped. If someone is dropped, also prints Car X drops off Y at station Z. Now has W passengers, as shown in the sample output (see Appendix B). - Write method public boolean add (Passenger p). This method adds a passenger if there is a room and return true or false depending on the passenger can be added or not. - Write the toString() method to print the car id number, location, destination, and passengers. Create a class Station with attributes int station Number and an array list people of type Passenger. Create a custom constructor Station (int number) and getter method get Number (). Also create the following methods: - void add (Passenger p) that adds a passenger on the station - Passenger get (int index) that returns the index of a passenger - Passenger remove (int index) that removes a passenger from the station ArrayList peopleWaitingList () that returns the list of

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

More Books

Students also viewed these Databases questions