add more comments
[IRC.git] / Robust / src / Benchmarks / BankApp / BankDatabase.java
1 public class BankDatabase\r
2 {\r
3         flag DatabaseInit;\r
4 \r
5         BankAccount[] database;\r
6         int numOfAccounts;\r
7         \r
8         public BankDatabase()\r
9         {\r
10                 //6 pre-created accounts\r
11                 numOfAccounts = 6;\r
12                 \r
13                 //10 account limit\r
14                 database = new BankAccount[10];\r
15                 \r
16                 for(int i = 0; i < 10; i++)\r
17                 {\r
18                         database[i] = new BankAccount();\r
19                 }\r
20                 \r
21                 //some hardcoded values\r
22                 database[0].modifyAccount("123456789", "John@@@@@@", "Q@@@@@@@@@", "Public@@@@", "1", "256000001@", "2007");\r
23                 database[1].modifyAccount("987654321", "Nancy@@@@@", "H@@@@@@@@@", "Private@@@", "2", "166@@@@@@@", "1234");\r
24                 database[2].modifyAccount("000111000", "Paul@@@@@@", "Wellington", "Franks@@@@", "1", "454225@@@@", "0000");\r
25                 database[3].modifyAccount("211411911", "Felix@@@@@", "the@@@@@@@", "Cat@@@@@@@", "3", "0@@@@@@@@@", "9999");\r
26                 database[4].modifyAccount("111000111", "Paul@@@@@@", "Wellington", "Franks@@@@", "2", "1128989@@@", "0000");\r
27                 //empty\r
28                 database[5].modifyAccount("@@@@@@@@@", "@@@@@@@@@@", "@@@@@@@@@@", "@@@@@@@@@@", "@", "@@@@@@@@@@", "@@@@");\r
29                 database[6].modifyAccount("@@@@@@@@@", "@@@@@@@@@@", "@@@@@@@@@@", "@@@@@@@@@@", "@", "@@@@@@@@@@", "@@@@");\r
30                 database[7].modifyAccount("@@@@@@@@@", "@@@@@@@@@@", "@@@@@@@@@@", "@@@@@@@@@@", "@", "@@@@@@@@@@", "@@@@");\r
31                 database[8].modifyAccount("@@@@@@@@@", "@@@@@@@@@@", "@@@@@@@@@@", "@@@@@@@@@@", "@", "@@@@@@@@@@", "@@@@");\r
32                 database[9].modifyAccount("@@@@@@@@@", "@@@@@@@@@@", "@@@@@@@@@@", "@@@@@@@@@@", "@", "@@@@@@@@@@", "@@@@");\r
33                 \r
34                 //test read into database[5]\r
35                 ReadFile(5);\r
36                 \r
37                 //test write from database[5]\r
38                 WriteFile(database[5].AccountNumber, database[5].FirstName, database[5].MiddleName, database[5].LastName, database[5].AccountType, database[5].Balance, database[5].PIN);\r
39         }\r
40         \r
41         /* what, no destructor?\r
42         public ~BankDatabase()\r
43         {\r
44                 //test write from database[5]           \r
45         }*/\r
46         \r
47         public void ReadFile(int index) \r
48         {\r
49                 //need to check if read/write works the way I think it does\r
50                 String filename="BankAppRead.dat";\r
51                 FileInputStream fis = new FileInputStream(filename);\r
52                 \r
53                 byte account[] = new byte[9];\r
54                 byte first[] = new byte[10];\r
55                 byte middle[] = new byte[10];\r
56                 byte last[] = new byte[10];\r
57                 byte type[] = new byte[1];\r
58                 byte balance[] = new byte[10];\r
59                 byte pin[] = new byte[4];\r
60                 \r
61                 //read one account for now\r
62                 fis.read(account);\r
63                 fis.read(first);\r
64                 fis.read(middle);\r
65                 fis.read(last);\r
66                 fis.read(type);\r
67                 fis.read(balance);\r
68                 fis.read(pin);\r
69                 \r
70                 fis.close();\r
71                 \r
72                 String S1 = new String(account);\r
73                 //System.printString(S1);\r
74                 String S2 = new String(first);\r
75                 //System.printString(S2);\r
76                 String S3 = new String(middle);\r
77                 //System.printString(S3);\r
78                 String S4 = new String(last);\r
79                 //System.printString(S4);\r
80                 String S5 = new String(type);\r
81                 //System.printString(S5);\r
82                 String S6 = new String(balance);\r
83                 //System.printString(S6);\r
84                 String S7 = new String(pin);\r
85                 //System.printString(S7);\r
86                 \r
87                 //read into one account for now\r
88                 database[index].modifyAccount(S1, S2, S3, S4, S5, S6, S7);\r
89     }\r
90         \r
91         public void WriteFile(String account, String first, String middle, String last, String type, String balance, String pin) \r
92         {\r
93                 String filename="BankAppWrite.dat";\r
94                 FileOutputStream fos = new FileOutputStream(filename);\r
95                 \r
96                 //write one account for now\r
97                 fos.write(account.getBytes());\r
98                 fos.write(first.getBytes());\r
99                 fos.write(middle.getBytes());\r
100                 fos.write(last.getBytes());\r
101                 fos.write(type.getBytes());\r
102                 fos.write(balance.getBytes());\r
103                 fos.write(pin.getBytes());\r
104                         \r
105                 fos.close();\r
106     }\r
107 }\r