1- package report ;
2-
3- /**
4- *
5- * @author Student Lab
6- */
7- public class Transaction implements Report {
8- private BankAccount [] account ;
1+ import java .util .*;
2+ import java .text .*;
3+ import java .io .ObjectOutputStream ;
4+ import java .io .FileOutputStream ;
5+ import java .io .IOException ;
6+ import java .io .ObjectInputStream ;
7+ import java .io .FileInputStream ;
8+
9+ public class Transaction implements Report {
10+
11+ private BankAccount account [];
912 private String header ;
1013 private String body ;
1114 private String footer ;
1215
1316 public Transaction () {
14- }
1517
16- @ Override
17- public String toString () {
18- return "Transaction{" + "account=" + account + ", header=" + header + ", body=" + body + ", footer=" + footer + '}' ;
18+ account = new BankAccount [10 ];
19+ Address add1 = new Address ("111" , "Pracha-U-thid 45" , "Pracha-U-thid" , "Thung-Kru" , "Bangkok" , 10140 );
20+ Address add2 = new Address ("402" , "Pracha-U-thid 48" , "Pracha-U-thid" , "Thung-Kru" , "Bangkok" , 10140 );
21+ Address add3 = new Address ("100" , "Pracha-U-thid 44" , "Pracha-U-thid" , "Thung-Kru" , "Bangkok" , 10140 );
22+ Address add4 = new Address ("103" , "Pracha-U-thid 46" , "Pracha-U-thid" , "Thung-Kru" , "Bangkok" , 10140 );
23+ Address add5 = new Address ("205" , "Pracha-U-thid 55" , "Pracha-U-thid" , "Thung-Kru" , "Bangkok" , 10140 );
24+ Address add6 = new Address ("189" , "Pracha-U-thid 79" , "Pracha-U-thid" , "Thung-Kru" , "Bangkok" , 10140 );
25+ Address add7 = new Address ("199" , "Pracha-U-thid 80" , "Pracha-U-thid" , "Thung-Kru" , "Bangkok" , 10140 );
26+ Address add8 = new Address ("181" , "Pracha-U-thid 78" , "Pracha-U-thid" , "Thung-Kru" , "Bangkok" , 10140 );
27+ Address add9 = new Address ("134" , "Pracha-U-thid 90" , "Pracha-U-thid" , "Thung-Kru" , "Bangkok" , 10140 );
28+ Address add10 = new Address ("11" , "Pracha-U-thid 105" , "Pracha-U-thid" , "Thung-Kru" , "Bangkok" , 10140 );
29+
30+
31+ String ph0 [] = {"0-24709850" };
32+ String ph1 [] = {"081-123-4567" , "0-24709850" };
33+ String ph2 [] = {"0" + (int ) (Math .random () * 10000000 )};
34+ String ph3 [] = {"0" + (int ) (Math .random () * 10000000 )};
35+ String ph4 [] = {"0" + (int ) (Math .random () * 10000000 )};
36+ String ph5 [] = {"0" + (int ) (Math .random () * 10000000 )};
37+ String ph6 [] = {"0" + (int ) (Math .random () * 10000000 )};
38+ String ph7 [] = {"0" + (int ) (Math .random () * 10000000 )};
39+ String ph8 [] = {"0" + (int ) (Math .random () * 10000000 )};
40+ String ph9 [] = {"0" + (int ) (Math .random () * 10000000 ), "0" + (int ) (Math .random () * 10000000 )};
41+
42+ SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd" );
43+ String input = "1980-12-01" ;
44+ Date t = null ;
45+ try {
46+ t = sdf .parse (input );
47+ } catch (ParseException e ) {
48+ System .out .println ("Unparseable using " + sdf );
49+ }
50+
51+ Customer custs [] = new Customer [10 ];
52+ custs [0 ] = new Customer ("somkiat" , "kiatpisarn" , add1 , ph0 , "somkiat@gmail.com" , t );
53+ custs [1 ] = new Customer ("suttiporn" , "saisuwan" , add2 , ph1 , "suttiporn@gmail.com" , new Date (1999 -1900 ,04 ,01 ));
54+ custs [2 ] = new Customer ("vasinee" , "wattanawat" , add3 , ph2 , "vasinee@gmail.com" , new Date (1986 -1900 ,00 ,31 ));
55+ custs [3 ] = new Customer ("adisorn" , "meeboon" , add4 , ph3 , "adisorn@gmail.com" , new Date (1990 -1900 ,01 ,01 ));
56+ custs [4 ] = new Customer ("onkamon" , "wongwisa" , add5 , ph4 , "wongwisa@gmail.com" , new Date (1991 -1900 ,02 ,11 ));
57+ custs [5 ] = new Customer ("charoensri" , "kiatpisarn" , add6 , ph5 , "charoensri@gmail.com" , new Date (1980 -1900 ,03 ,03 ));
58+ custs [6 ] = new Customer ("paisarn" , "meeboon" , add7 , ph6 , "sathit@gmail.com" , new Date (1981 -1900 ,04 ,14 ));
59+ custs [7 ] = new Customer ("sathit" , "charoensri" , add8 , ph7 , "somkiat@gmail.com" , new Date (1992 -1900 ,05 ,24 ));
60+ custs [8 ] = new Customer ("somrak" , "wattanawat" , add9 , ph8 , "somrak@gmail.com" , new Date (1999 -1900 ,06 ,30 ));
61+ custs [9 ] = new Customer ("somkiat" , "parnpiti" , add10 , ph9 , "parnpiti@gmail.com" , new Date (1999 -1900 ,07 ,10 ));
62+
63+ for (int i = 0 ; i < custs .length ; i ++) {
64+ if (i % 2 == 0 ) {
65+ account [i ] = new SavingsAccount (custs [i ], 500 , 5 );
66+ } else {
67+ account [i ] = new CurrentDepositAccount (custs [i ], account [i - 1 ].getAccId (), 100000 );
68+ }
69+ }
70+
71+ }
72+
73+ public void writeAccountObject (){
74+ try {
75+ ObjectOutputStream oos =new ObjectOutputStream (new FileOutputStream ("account.dat" ));
76+ for (BankAccount e : this .account ){
77+ oos .writeObject (e );
78+ }
79+ oos .close ();
80+ }
81+ catch (IOException ioe ){
82+ ioe .printStackTrace ();
83+ }
84+ }
85+
86+ public void readAccountObject (){
87+ ObjectInputStream ois =null ;
88+ try {
89+ ois =new ObjectInputStream (new FileInputStream ("account.dat" ));
90+ while (true ){
91+ BankAccount ba =(BankAccount )(ois .readObject ());
92+ System .out .println (ba );
93+ }
94+ }
95+ catch (IOException | ClassNotFoundException eof ){
96+ try {
97+ ois .close ();
98+ }
99+ catch (IOException iof ){
100+ System .out .println ("IO Error" );
101+ }
102+ }
19103 }
20104
21105 @ Override
@@ -35,16 +119,24 @@ public String getFooter() {
35119
36120 @ Override
37121 public void setHeader (String header ) {
38- this .header = header ;
122+ this .header = header ;
39123 }
40124
41125 @ Override
42126 public void setBody (String body ) {
43- this .body = body ;
127+ this .body = body ;
44128 }
45129
46130 @ Override
47131 public void setFooter (String footer ) {
48- this .footer =footer ;
132+ this .footer = footer ;
133+ }
134+
135+ public String toString () {
136+ String result = "" ;
137+ for (int i = 0 ; i < account .length ; i ++) {
138+ result += account [i ] + "\n " + "------------------------------------------------------------------------------------------------------------------------------" + "\n " ;
139+ }
140+ return result ;
49141 }
50142}
0 commit comments