Repository navigation
Expand file tree
/
Copy pathAssignment2.java
More file actions
executable file
·118 lines (90 loc) · 5.12 KB
/
Copy pathAssignment2.java
File metadata and controls
executable file
·118 lines (90 loc) · 5.12 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* Assignment 2 - Control Tower */
/* Class name - must be "Assignment2" in order to run */
import java.util.Scanner;
import assignment2.Airplane;
public class Assignment2
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
/* Write your code here */
/* You will first write code to create a plane, "Airplane 1",
with the default callsign of AAA01, starting in the default
position of 1 mile due north (0°) of the tower at an altitude of 0 feet. */
Airplane Airplane1 = new Airplane();
// System.out.println(Airplane1.toString());
// System.out.println(Airplane1);
/* Your program will then create a second plane, “Airplane 2”,
with the callsign of AAA02, starting at a position of 15.8 miles
with a bearing of 128° at an altitude of 30,000 feet. */
Airplane Airplane2 = new Airplane("AAA02", 15.8, 128, 30000);
// System.out.println(Airplane2);
/* Next, your program should ask the user to input the details
of a third airplane, "Airplane 3", detected by the tower. This
will consist of the call-sign, distance, direction and altitude.
Once these inputs have been entered, your program should convert
the callsign to use uppercase letters, then create Airplane 3
using these details. */
System.out.println("Enter the details of the third airplane (call-sign, distance, bearing and altitude): ");
String cs = scan.nextLine();
double dist = scan.nextDouble();
int dir = scan.nextInt();
int alt = scan.nextInt();
Airplane Airplane3 = new Airplane(cs, dist, dir, alt);
// System.out.println(Airplane3);
/* Print Initial Positions */
System.out.println("\nInitial Positions:");
System.out.println("\"Airplane 1\": " + Airplane1);
System.out.println("\"Airplane 2\": " + Airplane2);
System.out.println("\"Airplane 3\": " + Airplane3);
/* Print Initial Distances */
System.out.println("\nInitial Distances:");
System.out.println("The distance between Airplane 1 and Airplane 2 is " + Airplane1.distTo(Airplane2) + " miles.");
System.out.println("The distance between Airplane 1 and Airplane 3 is " + Airplane1.distTo(Airplane3) + " miles.");
System.out.println("The distance between Airplane 2 and Airplane 3 is " + Airplane2.distTo(Airplane3) + " miles.");
/* Print Initial Height Differences */
System.out.println("\nInitial Height Differences:");
System.out.println("The difference in height between Airplane 1 and Airplane 2 is " + Math.abs(Airplane1.getAlt() - Airplane2.getAlt()) + " feet.");
System.out.println("The difference in height between Airplane 1 and Airplane 3 is " + Math.abs(Airplane1.getAlt() - Airplane3.getAlt()) + " feet.");
System.out.println("The difference in height between Airplane 2 and Airplane 3 is " + Math.abs(Airplane2.getAlt() - Airplane3.getAlt()) + " feet.");
/* Move Airplane 1 a distance that is equal to the initial distance
between Airplane 2 and Airplane 3 on a heading of 65°. In other words,
if the distance between Airplane 2 and Airplane 3 is 4.6 miles, then
we should move Airplane 4.6 miles on a heading of 65°. */
double distance = Airplane2.distTo(Airplane3);
// System.out.println(distance);
Airplane1.move(distance, 65);
// System.out.println(Airplane1);
/* Move Airplane 2 a distance of 8.0 miles on a heading of 135°. */
Airplane2.move(8.0, 135);
/* Move Airplane 3 a distance of 5.0 miles on a heading 55°. */
Airplane3.move(5.0, 55);
/* Increase the altitude of Airplane 1 by 3,000 feet. */
Airplane1.gainAlt();
Airplane1.gainAlt();
Airplane1.gainAlt();
/* Decrease the altitude of Airplane 2 by 2,000 feet. */
Airplane2.loseAlt();
Airplane2.loseAlt();
/* Decrease the altitude of Airplane 3 by 4,000 feet. */
Airplane3.loseAlt();
Airplane3.loseAlt();
Airplane3.loseAlt();
Airplane3.loseAlt();
/* Print New Positions */
System.out.println("\nNew Positions:");
System.out.println("\"Airplane 1\": " + Airplane1);
System.out.println("\"Airplane 2\": " + Airplane2);
System.out.println("\"Airplane 3\": " + Airplane3);
/* Print New Distances */
System.out.println("\nNew Distances:");
System.out.println("The distance between Airplane 1 and Airplane 2 is " + Airplane1.distTo(Airplane2) + " miles.");
System.out.println("The distance between Airplane 1 and Airplane 3 is " + Airplane1.distTo(Airplane3) + " miles.");
System.out.println("The distance between Airplane 2 and Airplane 3 is " + Airplane2.distTo(Airplane3) + " miles.");
/* Print New Height Differences */
System.out.println("\nNew Height Differences:");
System.out.println("The difference in height between Airplane 1 and Airplane 2 is " + Math.abs(Airplane1.getAlt() - Airplane2.getAlt()) + " feet.");
System.out.println("The difference in height between Airplane 1 and Airplane 3 is " + Math.abs(Airplane1.getAlt() - Airplane3.getAlt()) + " feet.");
System.out.println("The difference in height between Airplane 2 and Airplane 3 is " + Math.abs(Airplane2.getAlt() - Airplane3.getAlt()) + " feet.");
}
}