-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgatorLibrary.java
More file actions
82 lines (78 loc) · 3.97 KB
/
gatorLibrary.java
File metadata and controls
82 lines (78 loc) · 3.97 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
import java.io.*;
public class gatorLibrary {
public static void main (String[] args) {
GatorLibraryMain library = new GatorLibraryMain();
// File name will be read
String inputFileName = args[0];
// Read input file and execute corresponding functions
try (BufferedReader reader = new BufferedReader(new FileReader(inputFileName))) {
// Define output format
BufferedWriter writer = new BufferedWriter(new FileWriter(inputFileName.substring(0,inputFileName.length()-4) + "_output_file.txt"));
String line;
outer:
while ((line = reader.readLine()) != null) {
// Split by '('
String[] tokens = line.split("\\(");
// Get operation name
String command = tokens[0].trim();
// Get operation parameters
String[] arguments = tokens[1].substring(0, tokens[1].length() - 1).split(",");
switch (command) {
case "InsertBook":
int bookIDInsert = Integer.parseInt(arguments[0].trim());
String bookNameInsert = arguments[1].trim();
String authorNameInsert = arguments[2].trim();
String availabilityStatusInsert = arguments[3].trim();
library.insertBook(bookIDInsert, bookNameInsert, authorNameInsert, availabilityStatusInsert);
break;
case "PrintBook":
int bookID = Integer.parseInt(arguments[0].trim());
writer.write(library.printBook(bookID));
break;
case "PrintBooks":
int bookID1 = Integer.parseInt(arguments[0].trim());
int bookID2 = Integer.parseInt(arguments[1].trim());
writer.write(library.printBooks(bookID1, bookID2));
break;
case "BorrowBook":
int patronIDBorrow = Integer.parseInt(arguments[0].trim());
int bookIDBorrow = Integer.parseInt(arguments[1].trim());
int patronPriorityBorrow = Integer.parseInt(arguments[2].trim());
writer.write(library.borrowBook(patronIDBorrow, bookIDBorrow, patronPriorityBorrow));
writer.newLine();
break;
case "ReturnBook":
int patronIDReturn = Integer.parseInt(arguments[0].trim());
int bookIDReturn = Integer.parseInt(arguments[1].trim());
writer.write(library.returnBook(patronIDReturn, bookIDReturn));
writer.newLine();
break;
case "DeleteBook":
int bookIDDelete = Integer.parseInt(arguments[0].trim());
writer.write(library.deleteBook(bookIDDelete));
writer.newLine();
break;
case "FindClosestBook":
int bookIDClosest = Integer.parseInt(arguments[0].trim());
writer.write(library.findClosestBook(bookIDClosest));
writer.newLine();
break;
case "ColorFlipCount":
writer.write("Colour Flip Count: " + library.colorFlip());
writer.newLine();
writer.newLine();
break;
case "Quit":
writer.write("Program Terminated!!");
break outer;
default:
System.out.println("Unknown command: " + command);
break;
}
}
writer.close();
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}