The only part that i need answered is Q5, the BusRoute class in java please. In
ID: 3803901 • Letter: T
Question
The only part that i need answered is Q5, the BusRoute class in java please.
In this assignment you will practice creating classes and enumerations in the context of a larger system. Overall, we are building pieces of a bus route booking system that allows passengers to book travel buses that travel throughout the United States. The classes that we are constructing in this assignment will take care of representing the bus data in Java. The final booking system should be able to search for bus routes from a list of commercial bus types (e.g. BoltBus, Greyhound), and locate various routes between two bus stations. Q1: Create a BusType enumeration. This is a datatype that represents bus types in our system. Include three values: Greyhound, BoltBus, and Megabus. This should be a single file containing the enum declaration. [2 points] Q2: Create a smart BusStation enumeration. This is a datatype that represents bus stations in our system, and has the ability to change from bus station code and city name. Include five values: PHX, LAX, LVS, SAN, and SFO. Also add a static method called getBusStationCity. This should be a single file containing the enum declaration, with the method declaration nested inside. (Hint: The attached file, ExampleSmartEnum.java, contains an example of including a method into an enumeration.) [8 points] getBusStationCity(...) will take a BusStation enumeration value as a parameter, and return a String containing the city where that bus station is located (e.g., "Phoenix", "Las Vegas", "San Diego", "San Francisco"). Use a switch statement. Have a default case that returns "Unknown City". Q3: Create a Bus class. This class will represent a bus in our system. It should contain a constructor, an instance variable (a BusType enumeration) and two methods (getBusType, toString) [10 points] The constructor will take a BusType to set up the BusType enumeration. getBusType(): will return the BusType of the bus (e.g., BusType.Greyhound). toString(): will return the name of the bus's bus type (e.g., "Greyhound"), followed by a star (" * "). Q4: Create a Time class. This class will represent a point in time, such as a departure time. It should contain 2 constructors, 2 instance variables (hour and minute), and 10 methods (see below). All methods but toString should be in terms of the 24 hour format. [30 points] default constructor: Creates a Time object for 12:00AM. overloaded constructor: Creates a Time object at a specific hour and minute. getHour(): Returns an integer representing the hour of the Time object. getMinute(): Returns an integer representing the minute of the Time object. addHours(...): Updates the object by moving it forward a number of hours. addMinute(...): Updates the object by moving it forward a number of minutes. (Hint: Be careful that you don't allow minutes to be more than 59.) addTime(...): Updates the object by moving it forward by the hour and minute from another Time object. getCopy(): Returns a new Time object that has the same hour and minute of the existing Time object. isEarlierThan(...): Returns true if this Time object is earlier than another Time object. isSameTime(...): Returns true if this Time object is the same as another Time object. isLaterThan(...): Returns true if this Time object is later than another Time object. toString(): Returns a string representing the Time object. Uses 12 hour AM/PM format and pads minutes to be two digits. See the sample output for an example. Q5: Create a BusRoute class that uses the Bus and Time class. This class will represent a bus route between two bus stations, using a specific Bus, and departing at a specific Time. It should contain a constructor, 7 instance variables (bus, bus number, cost, departure, duration, source, destination), and 9 methods (see below). [25 points] overloaded constructor: Creates a BusRoute object that is setup up with a Bus, a bus number, a cost, a departure Time, a duration time, a source BusStation, and a destination BusStation. getBus(): Returns the Bus that operates this bn rusoute. getNumber(): Returns the bus number as a String. getCost(): Returns the bus route cost. getDestination(): Returns the destination BusStation. getDeparture(): Returns the departure Time. getArrival(): Returns a Time object with the arrival time (computed from the departure time and duration). getSource(): Returns a Bus Station object for the departure location. toOverviewString(): Returns a String representing an overview of the bus route. Use NumberFormat to display the price. See the sample output for an example. toDetailedString(): Returns a String representing the bus route's detailed information. See the sample output for an example.
Explanation / Answer
//BusRoute.java
public class BusRoute {
//Instance variables
private Bus bus;
private String bus_number;
private NumberFormat cost;
private Time departure;
private Time duration;
private BusStation source;
private BusStation destination;
public BusRoute(Bus bus, String num, NumberFormat cost, Time dep, Time dur, BusStation source,BusStation dest)
{
//Set all the variables in constructor
this.bus = new Bus(bus); //assuming copy constructor is implemented in Bus class
this.bus_number = num;
this.cost = cost;
this.departure = dep;
this.duration = dur;
this.source = source;
this.destination = dest;
}
//Return current bus instance
public Bus getBus()
{
return this.bus;
}
public String getNumber()
{
return this.bus_number;
}
public NumberFormat getCost()
{
return cost;
}
public BusStation getDestination()
{
return destination;
}
public Time getDeparture()
{
return departure;
}
public Time getArrival()
{
Time arrival = new Time(departure.addTime(duration));//overloaded constructor called
return arrival;
}
public BusStation getSource()
{
return source;
}
public String toOverviewString()
{
//example not provided so assuming it on my own. Please modify accodingly or comment the details
String overview;
overview = "Bus Number: "+bus.bus_number;
overview += " Bus Source: "+source.toString();
overview += " Bus Destination: "+destination.toString();
return overview;
}
public String toDetailedString()
{
//example not provided so assuming it on my own. Please modify accodingly or comment the details
String details;
details = "Bus Number: "+bus.bus_number;
details += " Bus Source: "+source.toString();
details += " Bus Destination: "+destination.toString();
details += " Bus Departure: "+departure.toString();
details += " Cost: "+cost.toString();
return details;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.