-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppointmentFile.java
More file actions
78 lines (61 loc) · 2.59 KB
/
AppointmentFile.java
File metadata and controls
78 lines (61 loc) · 2.59 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
import java.io.BufferedReader; // these are all the imports needed
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.Buffer;
import java.util.Scanner;
public class AppointmentFile {
// static String allAppointnemts="";
static Scanner scan = new Scanner(System.in);
static int option;
static FileWriter fw;
public static void main(String[]args) throws IOException{
fw = new FileWriter("NewAppointments.txt", true);
// fw.write("Appointment ID | Date | Time | Purpose | Status\n");
do{
System.out.println("[1] Add Appointment\n[2] View All Appointments\n[3] Exit\nEnter Option\n");
option = scan.nextInt();
switch (option) {
case 1:
addAppointment(); //this is an appointement method
break;
case 2:
viewAllAppointments();
break;
default:
break;
}
}while(option!=3);
fw.close();
}
public static void viewAllAppointments(){
try{
BufferedReader br = new BufferedReader(new FileReader("NewAppointments.txt"));
String line;
while((line = br.readLine()) != null){
System.out.println(line);
if(br.readLine().equals("2")){
line = br.readLine();
System.out.println(line);
}
}
br.close(); //this code will close the buffered reader
}catch(IOException e){
System.out.println("An error occurred: " + e.getMessage());
}
}
public static void addAppointment() throws IOException{
System.out.println("Add Appointment");
System.out.println("Enter Appoinment ID");
int id = scan.nextInt();
System.out.println("Enter Date");
String date = scan.next();
System.out.println("Enter Time");
String time = scan.next();
System.out.println("Purpose");
String purpose = scan.next();
System.out.println("Enter Status");
String status = scan.next();
fw.write(id + " | " + date + " | " + time + " | " + purpose + " | " + status + "\n");
}
}