-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathManagerModel.java
More file actions
92 lines (73 loc) · 2.13 KB
/
ManagerModel.java
File metadata and controls
92 lines (73 loc) · 2.13 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
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.Scanner;
import javax.swing.event.ChangeListener;
public class ManagerModel {
private GregorianCalendar cal;
private ArrayList<ChangeListener> listeners;
private HotelReservationSystem s;
public ManagerModel(HotelReservationSystem s)
{
this.s=s;
cal = new GregorianCalendar();
listeners = new ArrayList<ChangeListener>();
}
public void load() throws FileNotFoundException
{
File file = new File ("src/reservations.txt");
Scanner scan = new Scanner(file);
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-LLLL-dd");
while (scan.hasNextLine())
{
//int roomNum = scan.nextInt();
String roomNum = scan.nextLine();
String roomType = scan.nextLine();
String eventInfo = scan.nextLine();
String[] split = eventInfo.split(" ");
LocalDate startDate = LocalDate.parse(split[0], dateFormat);
LocalDate endDate = LocalDate.parse(split[1], dateFormat);
//int userID = scan.nextInt();
String userID = scan.nextLine();
//int charges = scan.nextInt();
String charges = scan.nextLine();
Reservation r = new Reservation(startDate, endDate, Integer.parseInt(userID), Integer.parseInt(roomNum), Integer.parseInt(charges), roomType);
s.addReservation(r);
}
scan.close();
for(Reservation a: s.getReservations())
{
System.out.println(a.getRoomNumber());
}
}
public void save()
{
try {
FileWriter fw = new FileWriter("src/reservations.txt");
for (Reservation r : s.getReservations())
{
fw.write(r.getRoomNumber() + "\n");
fw.write(r.getRoomType() + "\n");
fw.write(r.getStartDate() + " " + r.getEndDate() + "\n");
fw.write(r.getUserId() + "\n");
fw.write(r.getCharges() + "\n");
}
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public void view()
{
new ManagerView(s);
}
public void attach (ChangeListener l)
{
listeners.add(l);
}
}