Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a BusRoute class that uses the Bus and Time class. This class will repres

ID: 3802984 • Letter: C

Question

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).

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.

SAMPLE OUTPUT txt _____

==testBusType()==
t1: Greyhound
t2 == t3: false
t2 == t4: true
==testBusStation()==
s1: PHX
s2 == s3: false
s2 == s4: false
s1: Phoenix
s3: Las Vegas
s5: San Francisco
==testBus()==
BoltBus
BoltBus *
Megabus *
==testTime()==
12:05AM
1:15AM
2:45AM
10:05AM
11:15AM
12:45PM
1:05PM
10:15PM
11:45PM
t1: 12:00AM
t2: 9:00AM
t2: 10:15AM
t2: 1:16PM
t2: 3:16PM
t3: 1:15AM
t4: 2:15AM
t3 < t4: true
t4 < t3: false
t2 < t4: false
t4 < t2: true
t2 < t2: false
t2 > t4: true
t4 > t2: false
t4 > t4: false
t2 = t4: false
t4 = t4: true
t4 = 2:15AM: true
==testBusRoute()==
10:50AM - 2:40PM
Phoenix (PHX) - Unknown City (YUM)
Greyhound 594

$45.00
10:50AM - 2:40PM   3h:50m
Greyhound       PHX-YUM


5:50PM - 6:16AM
San Diego (SAN) - San Francisco (SFO)
BoltBus 201

$65.00
5:50PM - 6:16AM   12h:26m
BoltBus       SAN-SFO

DRIVER FILE_____

/**
*
* @author (Spencer Greer), Barnai
*/
public class Driver {
    public static void main(String[] args) {
      
        //Please note that these tests are not comprehensive.
        testBusType();
        testBusStation();
        testBus();
        testTime();
        //testBusRoute();
    }
  
    public static void testBusType() {
        System.out.println("==testBusType()==");
      
        //Test 1: create enum variables
        BusType t1 = BusType.Greyhound;
        BusType t2 = BusType.BoltBus;
        BusType t3 = BusType.Megabus;
        BusType t4 = BusType.BoltBus;
      
        //Test 2: display and compare variables
        System.out.println("t1: " + t1);
        System.out.println("t2 == t3: " + (t1 == t2));
        System.out.println("t2 == t4: " + (t2 == t4));
      
    }
  
    public static void testBusStation() {
        System.out.println("==testBusStation()==");
      
      
        //Test 1: create enum variables
        BusStation s1 = BusStation.PHX;
        BusStation s2 = BusStation.LAX;
        BusStation s3 = BusStation.LVS;
        BusStation s4 = BusStation.SAN;
        BusStation s5 = BusStation.SFO;
      
        //Test 2: display and compare variables
        System.out.println("s1: " + s1);
        System.out.println("s2 == s3: " + (s1 == s2));
        System.out.println("s2 == s4: " + (s2 == s4));
        System.out.println("s1: " + BusStation.getBusStationCity(s1));
        System.out.println("s3: " + BusStation.getBusStationCity(s3));
        System.out.println("s5: " + BusStation.getBusStationCity(s5));
      
    }
  
    public static void testBus() {
        System.out.println("==testBus()==");
      
      
        //Test 1: create bus objects
        Bus b1 = new Bus(BusType.BoltBus);
        Bus b2 = new Bus(BusType.Megabus);
      
        //Test 2: display bus information.
        System.out.println(b1.getBusType());
        System.out.println(b1);
        System.out.println(b2);
      
    }
  
    public static void testTime() {
        System.out.println("==testTime()==");
      
      
        //Test 1: use default constructor.
        Time t1 = new Time();
      
        //Test 2: use overloaded constructor.
        Time t2 = new Time(9, 0);
        Time t3 = new Time(1, 15);
      
        //Test 3: use clone operation.
        Time t4 = t3.getCopy();
      
        //Test 4: run toString on AM times.
        System.out.println(new Time(0, 5));
        System.out.println(new Time(1, 15));
        System.out.println(new Time(2, 45));
        System.out.println(new Time(10, 5));
        System.out.println(new Time(11, 15));
        //Test 5: run toString on PM times.
        System.out.println(new Time(12, 45));
        System.out.println(new Time(13, 5));
        System.out.println(new Time(22, 15));
        System.out.println(new Time(23, 45));
      
        //Test 6: run toString on object from default constructor.
        System.out.println("t1: " + t1);
      
        //Test 7: testing addTime operation
        System.out.println("t2: " + t2);
        t2.addTime(t3);
        System.out.println("t2: " + t2);
        //Test 8: testing addMinutes operation
        t2.addMinute(181);
        System.out.println("t2: " + t2);
        //Test 9: testing8 addHours operation
        t2.addHours(2);
        System.out.println("t2: " + t2);
      
        //Test 10: testing cloned copy.
        t4.addHours(1);
        System.out.println("t3: " + t3);//original
        System.out.println("t4: " + t4);//clone
      
        //Test 11: testing isEarlierThan.
        System.out.println("t3 < t4: " + t3.isEarlierThan(t4));
        System.out.println("t4 < t3: " + t4.isEarlierThan(t3));
        System.out.println("t2 < t4: " + t2.isEarlierThan(t4));
        System.out.println("t4 < t2: " + t4.isEarlierThan(t2));
        System.out.println("t2 < t2: " + t2.isEarlierThan(t2));
      
        //Test 12: testing isLaterThan.
        System.out.println("t2 > t4: " + t2.isLaterThan(t4));
        System.out.println("t4 > t2: " + t4.isLaterThan(t2));
        System.out.println("t4 > t4: " + t4.isLaterThan(t4));
      
        //Test 13: testing isSameTime.
        System.out.println("t2 = t4: " + t2.isSameTime(t4));
        System.out.println("t4 = t4: " + t4.isSameTime(t4));
        System.out.println("t4 = 2:15AM: " + t4.isSameTime(new Time(2, 15)));
      
    }
  
    public static void testBusRoute() {
        System.out.println("==testBusRoute()=="); // SEE BusRouteManager.java!!!

         /*
        //Test 1: create bus routes using different settings
        BusRoute r1 = new BusRoute(new Bus(BusType.Greyhound),
                "594", 45,
                new Time(10, 50), 230,
                BusStation.PHX, BusStation.YUM);
      
        BusRoute r2 = new BusRoute(new Bus(BusType.Megabus),
                "205", 46,
                new Time(11, 5),
                360,
                BusStation.LAX,
                BusStation.LVS);
      
        BusRoute r3 = new BusRoute(new Bus(BusType.Greyhound),
                "135", 75,
                new Time(8, 20),
                440,
                BusStation.PHX,
                BusStation.SAN);
      
        BusRoute r4 =new BusRoute(new Bus(BusType.BoltBus),
                "228", 50,
                new Time(7, 10),
                192,
                BusStation.SAN,
                BusStation.LAX);
      
        BusRoute r5 = new BusRoute(new Bus(BusType.BoltBus),
                "201", 65,
                new Time(17, 50),
                746,
                BusStation.SAN,
                BusStation.SFO);
      
      
        System.out.println(r1.toDetailedString());
        System.out.println();
        System.out.println(r1.toOverviewString());
      
        System.out.println();
        System.out.println();
      
        System.out.println(r5.toDetailedString());
        System.out.println();
        System.out.println(r5.toOverviewString());
        */

    }
}

BUS_____

public class Bus{
private BusType bustype;
public Bus(BusType bustype){
this.bustype=bustype;
}
public BusType getBusType(){
   return bustype;
   }

public String toString(){
   return bustype + "*";
   }

}

TIME______

class Time{
int timeMinute;
int timeHour;

public Time()
{
timeMinute=0;
timeHour=0;
}

public Time (int hh, int mm){
timeMinute = mm;
timeHour = hh;
}

public int getHour()
   {
   return timeHour;
   }

public int getMinute()
   {
   return timeMinute;
   }
  
public void addHours(int aHrs)
   {
   timeHour = timeHour+aHrs;
   }
  
public void addMinute(int aMts)
   {
   timeMinute=timeMinute+aMts;
   if (timeMinute>59)
   {
   addHours(1);
   timeMinute= timeMinute-60;
   }
}
public void addTime(Time t2)
   {
   addHours(t2.getHour());
   addMinute(t2.getMinute());
   }

public Time getCopy()
   {
   return new Time(this.getMinute(), this.getHour());
   }
  
public boolean isEarlierThan(Time t2)
   {
   if(this.getHour()>t2.getHour())
   return true;
   return false;
   }

public boolean isSameTime(Time t2)
   {
   if((this.getHour()==t2.getHour())&&(this.getMinute()==t2.getMinute()))
   return true;
   return false;
   }
  
public boolean isLaterThan(Time t2)
   {
   if(this.getHour()<t2.getHour())
   return true;
   return false;
   }

public String toString()
{
String tt="";
if(timeMinute<10)
tt="0";
if(timeHour==0)
return "12: " + tt + timeMinute+ "AM";
else if(timeHour<12)
return timeHour+ ":" + tt + timeMinute + "AM";
else if(timeHour ==12)
return timeHour+ ":" + tt + timeMinute + "PM";
return(timeHour-12)+ ":" + tt + timeMinute + "PM";
}
}

Only stuck on the busroute file. Thank you!

Explanation / Answer

//Please create this class in the same packege

//============================= BusRoute.java ===========================//

public class BusRoute{
   private Bus bus;
   private String number;
   private int cost;
   private Time departure;
   private int duration;
   private BusStation source;
   private BusStation destination;
  
   public BusRoute(Bus bus,String busNumber, int cost, Time time, int duration,BusStation source, BusStation destination){
       this.setBus(bus);
       this.setNumber(busNumber);
       this.setCost(cost);
       this.setDeparture(time);
       this.setDuration(duration);
       this.setSource(source);
       this.setDestination(destination);
   }

   public Bus getBus() {
       return bus;
   }

   public void setBus(Bus bus) {
       this.bus = bus;
   }

   public String getNumber() {
       return number;
   }

   public void setNumber(String number) {
       this.number = number;
   }

   public int getCost() {
       return cost;
   }

   public void setCost(int cost) {
       this.cost = cost;
   }

   public Time getDeparture() {
       return departure;
   }

   public void setDeparture(Time departure) {
       this.departure = departure;
   }

   public Time getArrival() {
       int time = departure.getHour()*60 + departure.getMinute();
       time = time + duration;
       return new Time(time/60,time%60);
   }
  
   public int getDuration() {
       return duration;
   }

   public void setDuration(int duration) {
       this.duration = duration;
   }

   public BusStation getSource() {
       return source;
   }

   public void setSource(BusStation source) {
       this.source = source;
   }

   public BusStation getDestination() {
       return destination;
   }

   public void setDestination(BusStation destination) {
       this.destination = destination;
   }
  
   public String toDetailedString(){
       String str = "";
       str += getDeparture()+" - "+getArrival()+" "+getSource()+" - "+getDestination()+" "+getBus().getBusType()+" "+getNumber()+" ";
       return str;
   }
   public String toOverviewString(){
       String str = "";
       str += "$"+getCost()+" "+getDeparture()+" - "+getArrival()+" "+getBus().getBusType()+" "+getSource()+" - "+getDestination()+" ";
       return str;
   }
}