-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAircraft.java
More file actions
86 lines (73 loc) · 2.31 KB
/
Aircraft.java
File metadata and controls
86 lines (73 loc) · 2.31 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
80
81
82
83
84
85
86
//Sina Pahlavan
//501 034 271
/*
*
* This class models an aircraft type with a model name, a maximum number of economy seats, and a max number of first class seats
*
* Add code such that class Aircraft implements the Comparable interface
* Compare two Aircraft objects by first comparing the number of economy seats. If the number is equal, then compare the
* number of first class seats
*/
public class Aircraft //implements the comparable interface
{
int numEconomySeats;
int numFirstClassSeats;
String model;
String[][] seatLayout;
public Aircraft(int economy, int firstClass,String aModel)
{
String[] letters = {"A","B","C","D"};//these letters will be used to write the seat number and letters
this.numEconomySeats = economy;
this.numFirstClassSeats = firstClass;
this.model = model;
int totSeat = economy + firstClass;
if (totSeat<=16){//if we have less than or equal to 16 seats, we will only have two rows
seatLayout = new String[2][totSeat/2];
}
else{//if we have more than 16 seats, we will have four rows.
seatLayout = new String[4][totSeat/4];
}
for (int i=0;i<seatLayout.length;i++){
for (int j=0;j<seatLayout[i].length;j++){
seatLayout[i][j] = Integer.toString(j+1) + letters[i] ;
}
}
if (firstClass>0){//theonly flight that has first class seats is the one going to Tokyo and it has 12 of them.
/**
* this method will be used to create 12 first class seats on the flight going to Tokyo
*/
for (int i=0;i<4;i++){
for (int j=0;j<3;j++){
seatLayout[i][j]+="+";
}
}
}
}
public int getNumSeats()
{
return numEconomySeats;
}// returns num of economy seats
public int getTotalSeats()
{
return numEconomySeats + numFirstClassSeats;
}// returns num of total seats
public int getNumFirstClassSeats()
{
return numFirstClassSeats;
}//returns num of first class seats
public String getModel()
{
return model;
}//returns aircraft model
public void setModel(String model)
{
this.model = model;
}// you can set the model of the aircraft using this method
public void print()//prints some information about the aircraft
{
System.out.println("Model: " + model + "\t Economy Seats: " + numEconomySeats + "\t First Class Seats: " + numFirstClassSeats);
}
/*
* Write a compareTo method that is part of the Comparable interface
*/
}