-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNavigation.java
More file actions
73 lines (55 loc) · 1.9 KB
/
Navigation.java
File metadata and controls
73 lines (55 loc) · 1.9 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
package semesterProject;
import java.util.Scanner;
public class Navigation extends Thread{
Scanner sc = new Scanner(System.in);
Airplane plane;
private double latitude;
private double longitude;
private boolean running;
String current ;
String destination;
public Navigation() {
this.latitude = 0.0;
this.longitude = 0.0;
}
void setDestination(String current ,String destination) {
this.current = current;
this.destination =destination;
}
void input() {
System.out.print("Enter Current Place: ");
String current = sc.nextLine();
System.out.print("Enter Destination: ");
String destination = sc.nextLine();
setDestination(current ,destination);
}
public void setLocation(double lat, double lon) {
this.latitude = lat;
this.longitude = lon;
System.out.println("Current location: Latitude " + lat + ", Longitude " + lon);
}
void startNav() {
running = true;
}
void stopNav() {
running = false;
}
public void run() {
try {
while(true) {
if(plane.checkStatus() && running) {
latitude += Math.random() * 0.01;
longitude += Math.random() * 0.01;
System.out.println(" Navigating... Current position -> Lat: " + latitude + ", Lon: " + longitude);
System.out.println(" We are flying "+current+" to "+ destination);
Thread.sleep(4000);
}
else if(!running && !plane.checkStatus()) {
Thread.sleep(10000);
}
}
} catch (InterruptedException e) {
System.out.println(" Navigation system stopped.");
}
}
}