Flight Class Implementation

Verified

Added on  2019/09/16

|2
|340
|471
Practical Assignment
AI Summary
This assignment involves implementing a `Flight` class in Java. The class includes attributes for plane details, flight number, cost, departure and arrival times, duration, and source and destination airports. Methods are provided to access these attributes and calculate the arrival time based on departure time and duration. Two additional methods, `toOverviewString()` and `toDetailedString()`, are implemented to provide formatted output of flight information. The `toOverviewString()` method provides a concise summary, while `toDetailedString()` offers more detailed information. The solution demonstrates object-oriented programming principles and utilizes helper classes like `Plane`, `Time`, and `Airport` (not included in the provided snippet). The code uses `NumberFormat` for currency formatting and handles time calculations effectively. This practical assignment helps students understand class design, method implementation, and string manipulation in Java.
Document Page
import java.text.NumberFormat;
public class Flight {
Plane plane;
String flightNumber;
double flightCost;
Time departureTime;
int durationTime;
Airport sourceAirport;
Airport destinationAirport;
public Flight(Plane plane, String flightNumber, double flightCost, Time departureTime, int
durationTime,
Airport sourceAirport, Airport destinationAirport) {
this.plane = plane;
this.flightNumber = flightNumber;
this.flightCost = flightCost;
this.departureTime = departureTime;
this.durationTime = durationTime;
this.sourceAirport = sourceAirport;
this.destinationAirport = destinationAirport;
}
public Plane getPlane() {
return plane;
}
public String getNumber() {
return flightNumber;
}
public double getCost() {
return flightCost;
}
public Airport getDestination() {
return destinationAirport;
}
public Time getDeparture() {
return departureTime;
}
public Time getArrival() {
Time arrivalTime = new Time(departureTime.getHour(), departureTime.getMinute());
arrivalTime.addMinutes(durationTime);
return arrivalTime;
}
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
public Airport getSource() {
return sourceAirport;
}
public String toOverviewString() {
NumberFormat nf = NumberFormat.getCurrencyInstance();
String output = nf.format(flightCost) + "\n" + getDeparture() + " - ";
output += getArrival() + "\t" + durationTime / 60 + "h:" + durationTime % 60 + "m";
output += "\n" + plane.getAirline() + "\t\t" + sourceAirport + "-" + destinationAirport;
return output;
}
public String toDetailedString() {
String output
= getDeparture() + " - " + getArrival() + "\n" + Airport.getAirportCity(sourceAirport)
+ " (" + sourceAirport + ") - " + Airport.getAirportCity(destinationAirport) + " ("
+ destinationAirport + ")" + "\n" + plane.getAirline() + " " + flightNumber + " * "
+ plane.getModel();
return output;
}
}
chevron_up_icon
1 out of 2
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]