-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlight.java
More file actions
79 lines (56 loc) · 2.22 KB
/
Flight.java
File metadata and controls
79 lines (56 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import java.util.ArrayList;
class Flight{
private double price;
private String id;
private String from;
private String to;
private int numAdults;
private int numKids;
private ArrayList<Passenger> passengerList;
public Flight(String _id, String _from, String _to, double _price){
this.id = _id;
this.from = _from;
this.to = _to;
this.price = _price;
this.numKids = 0;
this.numAdults = 0;
this.passengerList = new ArrayList<Passenger>();
}
public String getFlightId(){
return this.id;
}
public void addPassenger(Passenger p){
this.passengerList.add(p);
if(p instanceof Adults){
this.numAdults = this.numAdults + 1;
}
if(p instanceof Kids){
this.numKids = this.numKids + 1;
}
}
public void displayInfoFlight(){
System.out.println(String.format("%-10s %s" , "Flight Id", " : " + this.id));
System.out.println(String.format("%-10s %s" , "From", " : " + this.from));
System.out.println(String.format("%-10s %s" , "To", " : " + this.to));
}
public void displayInfoPassengers(){
System.out.println(String.format("%-10s %s%.2f%s" , "Price", " : RM",this.price,"\n"));
if(passengerList.size() > 1){
System.out.println(String.format("%-25s %s" , "Number of Passengers", " : " + Integer.toString(this.numKids + this.numAdults)));
System.out.println(String.format("%-25s %s" , "Number of Adults", " : " + Integer.toString(this.numAdults)));
System.out.println(String.format("%-25s %s" , "Number of Kids", " : " + Integer.toString(this.numKids) + "\n"));
System.out.println(String.format("%-4s%-25s%-5s%-20s%-15s","No","Name","Age","Parent Name","Ticket (RM)"));
double totalTicketPrice = 0;
for (int i=0;i<this.passengerList.size();i++){
System.out.print(String.format("%-4s",Integer.toString(i+1) + ". "));
this.passengerList.get(i).displayDetails();
totalTicketPrice = totalTicketPrice + this.price - (this.price * (this.passengerList.get(i).calcDisc() / 100));
System.out.println(String.format("%-15.2f",this.price - (this.price * (this.passengerList.get(i).calcDisc() / 100))));
}
System.out.println(String.format("%s%.2f%s","\nTotal Ticket Price: ",totalTicketPrice,"\n"));
}else{
System.out.println("\nNo passenger!\n");
}
//// total price
}
}