-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckInEvent.java
More file actions
86 lines (68 loc) · 2.82 KB
/
Copy pathcheckInEvent.java
File metadata and controls
86 lines (68 loc) · 2.82 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
import java.io.*;
import java.util.Scanner;
import java.util.*;
public class checkInEvent {
public static void checkInEvent(ArrayList<Member> memberList) {
Scanner scanner = new Scanner(System.in);
Member member = null;
System.out.print("Enter the ID of the member to check in for: ");
String inputId = scanner.nextLine().strip();
for(Member mem : memberList) {
if(inputId.equals(mem.getMemberID())) {
member = mem;
}
}
if(member == null) {
System.out.println("There was no member found with member ID " + inputId);
} else {
System.out.print("Please enter the ID of the collection to be checked in: ");
String collectionId = scanner.nextLine();
File myFile = new File("CheckedOutItems.txt");
File tempFile = new File("tempCheckedIn.txt");
try {
BufferedReader reader = new BufferedReader(new FileReader(myFile));
BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
String lineToRemove = collectionId;
String currentLine;
boolean found = false;
while ((currentLine = reader.readLine()) != null) {
String[] currline = currentLine.split("\t");
String memID = currline[0];
String col1 = currline[1];
String col2 = currline[2];
String col3 = currline[3];
String col4 = currline[4];
String col5 = currline[5];
int i = 0;
for(String col : currline) {
if(col.equals(collectionId)) {
member.setCheckedOut(i, "0");
writer.write("0\t");
found = true;
} else {
writer.write(col + "\t");
}
i++;
}
writer.newLine();
}
if (!found) {
System.out.println("Book not found.");
} else {
System.out.println("Book returned successfully.");
}
reader.close();
writer.close();
scanner.close();
if (!myFile.delete()) {
System.out.println("Could not delete the original file.");
}
if (!tempFile.renameTo(myFile)) {
System.out.println("Could not rename the temporary file.");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}