public class Trip
extends Object
Modifier and Type | Field and Description |
---|---|
private List<Flight> |
legs
The list of flights (legs) that comprise this trip
|
Constructor and Description |
---|
Trip()
Creates a trip with no legs, my solution does not have any code for this constructor.
|
Trip(List<Flight> legs)
Initializes a trip with a list of legs.
|
Modifier and Type | Method and Description |
---|---|
void |
addLeg(Flight leg)
Adds a leg to this trip.
|
private boolean |
doesDateMatch(Flight previousLeg,
Flight nextLeg)
Optional, this is a helper method I wrote.
|
private boolean |
doesDestinationOriginMatch(Flight previousLeg,
Flight nextLeg)
Optional, this is a helper method I wrote.
|
double |
getCost()
Returns the total cost of trip across all legs.
|
LocalDate |
getDate()
Returns the date of the trip.
|
Airport |
getDestination()
Returns the airport where trip ends.
|
double |
getDistance()
Returns the total distance of trip across all legs.
|
private String |
getHeader()
Optional, this is a helper method I wrote.
|
List<Flight> |
getLegs()
Returns the list of legs.
|
private String |
getLegsMsg()
Optional, this is a helper method I wrote.
|
int |
getNumLegs()
Returns the number of legs.
|
Airport |
getOrigin()
Returns the airport where trip begins.
|
private String |
location(Airport a)
Optional, this is a helper method I wrote.
|
String |
toString()
Returns a string exactly in the format show below (by example).
|
private List<Flight> legs
public Trip()
public Trip(List<Flight> legs)
legs
- public void addLeg(Flight leg)
leg
- Flight to be added to this trip.private boolean doesDateMatch(Flight previousLeg, Flight nextLeg)
private boolean doesDestinationOriginMatch(Flight previousLeg, Flight nextLeg)
public double getCost()
public LocalDate getDate()
public Airport getDestination()
public double getDistance()
private String getHeader()
public List<Flight> getLegs()
private String getLegsMsg()
public int getNumLegs()
public Airport getOrigin()
private String location(Airport a)
public String toString()
Trip Date: 2020-06-18 From: VLD-Valdosta, GA To: ANB-Anniston, AL Distance: 245 miles, Cost: $345.00 Leg 1 Flight: 1234, Date: 2020-06-18 From: VLD-Valdosta, GA To: CSG-Columbus, GA Distance: 154 miles, Cost: $144.50 Leg 2 Flight: 1235, Date: 2020-06-18 From: CSG-Columbus, GA To: ANB-Anniston, AL Distance: 91 miles, Cost: $200.50
toString
in class Object