public class Flight
extends Object
Modifier and Type | Field and Description |
---|---|
private double |
cost
The cost of the flight
|
private LocalDate |
date
The date of the flight.
|
private Airport |
destination
The destination Airport
|
private double |
distance
The distance of the flight which must be calculated in the
constructor using the DistanceCalculator class.
|
private String |
number
Represents the flight number as a string composed of 4 digits.
|
private Airport |
origin
The origin Airport.
|
Constructor and Description |
---|
Flight(String number,
LocalDate date,
Airport origin,
Airport destination,
double cost)
Creates a Flight object if the flight number is valid
number , otherwise throws
an InvalidArgumentException. |
Flight(String number,
String date,
Airport origin,
Airport destination,
double cost)
Creates a Flight object if the flight number is valid
number , otherwise throws
an InvalidArgumentException. |
Modifier and Type | Method and Description |
---|---|
String |
flightString()
Returns a string in the format: flightNumber-date-originCode-destinationCode
|
double |
getCost() |
LocalDate |
getDate() |
Airport |
getDestination() |
double |
getDistance() |
private double |
getDistanceBetween()
Optional, a helper method I used in my solution.
|
String |
getNumber() |
Airport |
getOrigin() |
private boolean |
isFlightNumValid(String number)
Optional, a helper method I used in my solution.
|
(package 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 double cost
private LocalDate date
private Airport destination
private double distance
private String number
private Airport origin
public Flight(String number, LocalDate date, Airport origin, Airport destination, double cost)
number
, otherwise throws
an InvalidArgumentException. Note that the distance
instance variable must be
calculated here.number
- date
- origin
- destination
- cost
- public Flight(String number, String date, Airport origin, Airport destination, double cost)
number
, otherwise throws
an InvalidArgumentException. This overload accepts a String date as opposed to a
LocalDate.number
- date
- origin
- destination
- cost
- public String flightString()
public double getCost()
public LocalDate getDate()
public Airport getDestination()
public double getDistance()
private double getDistanceBetween()
public String getNumber()
public Airport getOrigin()
private boolean isFlightNumValid(String number)
String location(Airport a)
public String toString()
Flight: 1234, Date: 2020-06-18 From: VLD-Valdosta, GA To: CSG-Columbus, GA Distance: 154 miles, Cost: $144.50
toString
in class Object