-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextCommunication.java
More file actions
85 lines (77 loc) · 2.58 KB
/
TextCommunication.java
File metadata and controls
85 lines (77 loc) · 2.58 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
import java.util.Date;
import java.util.*;
import java.io.BufferedWriter;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.FileReader;
import java.io.IOException;
import java.io.FileNotFoundException;
/**
* TextCommunicator that references the NearList.
*
* @author Christi Kazakov
* @author Shelley King
*/
public class TextCommunication {
BufferedReader inputStream = null;
BufferedWriter outputStream = null;
String warningAlert;
String fileName;
Aircraft plane, myPlane;
int warning;
public TextCommunication(Aircraft plane, Aircraft thisPlane, int warning){
this.plane = plane;
this.myPlane = thisPlane;
this.warning = warning;
fileName = myPlane.getId().toString();
}
public TextCommunication(){
}
public void listener() throws Exception {
try {
inputStream = new BufferedReader(new FileReader(fileName));
outputStream = new BufferedWriter(new FileWriter(fileName));
String line = inputStream.readLine();
while(line != null){
line = inputStream.readLine();
}
}
catch(FileNotFoundException error){
System.out.println("Error: File Not Found");
}
catch (IOException e) {
e.printStackTrace();
}
}
public String receiver(Object data){
return data.toString();
}
public void send(String message) throws Exception{
outputStream.write(message);
}
public void log(String log) throws Exception {
// Instantiate a Date Object for the date and time
Date date = new Date();
// display time and date using toString()
String str = String.format("Log : %tc", date );
//Different levels of Warning based on the data taken in.
String warningLevel1 = "YELLOW";
String warningLevel2 = "ORANGE";
String warningLevel3 = "RED";
//logs which warning came in and what time
// **Should show the plane ID and message **
if(warning == 1){
outputStream.write(str + " " + warningLevel1 + " " + plane.getId());
}
else if(warning == 2){
outputStream.write(str + " " + warningLevel2 + " " + plane.getId());
}
else if(warning == 3){
outputStream.write(str + " " + warningLevel3 + " " + plane.getId());
}
else{
outputStream.write("No plane warning level received");
}
}
}