Você está na página 1de 8

Class Project 1/8

1 import java.util.*;
2 import java.io.*;
3 class Project
4 {
5 public static void main(String args[])throws IOException
6 {
7 Scanner sc=new Scanner(System.in);
8 System.out.println("1 - Create Data File");
9 System.out.println("2 - Addition of New Records");
10 System.out.println("3 - Report Generation");
11 System.out.println("4 - Deletion of an Account");
12 System.out.println("5 - Modification");
13 System.out.println("6 - Sorting");
14 System.out.println("7 - Exit");
15 int ch=sc.nextInt();
16 switch(ch)
17 {
18 case 1:
19 FileOutputStream foutn=new FileOutputStream("account.dat");
20 DataOutputStream doutn=new DataOutputStream(foutn);
21 doutn.close();
22 foutn.close();
23 break;
24 case 2:
25 FileOutputStream fout=new FileOutputStream("accounttemp.dat")
;
26 DataOutputStream dout=new DataOutputStream(fout);
27 FileInputStream finn=new FileInputStream("account.dat");
28 DataInputStream dinn=new DataInputStream(finn);
29 boolean eoft=false;
30 while(!eoft)
31 {
32 try
33 {
34 long a=dinn.readLong();
35 String n=dinn.readUTF();
36 int am=dinn.readInt();
37 String ad=dinn.readUTF();
38 String adp=dinn.readUTF();
39 dout.writeLong(a);
40 dout.writeUTF(n);
41 dout.writeInt(am);
42 dout.writeUTF(ad);
43 dout.writeUTF(adp);
44 }
45 catch(EOFException n)
46 {
47 eoft=true;
48 }

30 Jun, 2017 1:41:38 AM


Class Project (continued) 2/8

49 }
50 System.out.println("Enter Account Number");
51 long acc=sc.nextLong();
52 System.out.println("Enter Name");
53 String name=sc.next();
54 System.out.println("Enter Initial Amount To Deposit");
55 int amt=sc.nextInt();
56 System.out.println("Enter Bank Address");
57 String add=sc.next();
58 System.out.println("Enter personal Address");
59 String padd=sc.next();
60 dout.writeLong(acc);
61 dout.writeUTF(name);
62 dout.writeInt(amt);
63 dout.writeUTF(add);
64 dout.writeUTF(padd);
65 dinn.close();
66 finn.close();
67 dout.close();
68 fout.close();
69

70 File tn1=new File("accounttemp.dat");


71 File tn2=new File("account.dat");
72 tn2.delete();
73 tn1.renameTo(tn2);
74 break;
75 case 3:
76 System.out.println("1 - Specific Account");
77 System.out.println("2 - For All Accounts");
78 int ch2=sc.nextInt();
79 if(ch2==1)
80 {
81 System.out.println("Enter Account Number");
82 long ac=sc.nextLong();
83 FileInputStream fin=new FileInputStream("account.dat");
84 DataInputStream din=new DataInputStream(fin);
85 boolean eof=false;
86 while(!eof)
87 {
88 try
89 {
90 long a=din.readLong();
91 String n=din.readUTF();
92 int am=din.readInt();
93 String ad=din.readUTF();
94 String adp=din.readUTF();
95 if(a==ac)
96 {
97 System.out.println("Account Number - "+a);

30 Jun, 2017 1:41:38 AM


Class Project (continued) 3/8

98 System.out.println("Name - "+n);
99 System.out.println("Amount Deposited - "+am);
100 System.out.println("Bank Address - "+ad);
101 System.out.println("Personal Address - "+adp)
;
102 }
103

104 }
105 catch(EOFException n )
106 {
107 eof=true;
108 }
109 }
110

111 din.close();
112 fin.close();
113 }
114 else
115 {
116 boolean eof=false;
117 FileInputStream fin=new FileInputStream("account.dat");
118 DataInputStream din=new DataInputStream(fin);
119

120 while(!eof)
121 {
122 try
123 {
124 long a=din.readLong();
125 String n=din.readUTF();
126 int am=din.readInt();
127 String ad=din.readUTF();
128 String adp=din.readUTF();
129 System.out.println("Account Number - "+a);
130 System.out.println("Name - "+n);
131 System.out.println("Amount Deposited - "+am);
132 System.out.println("Bank Address - "+ad);
133 System.out.println("Personal Address - "+adp);
134 }
135 catch(EOFException n)
136 {
137 eof=true;
138 }
139

140 }
141 din.close();
142 fin.close();
143 }
144 break;
145 case 4:

30 Jun, 2017 1:41:38 AM


Class Project (continued) 4/8

146 System.out.println("Enter Account Number");


147 long ac1=sc.nextLong();
148 FileOutputStream fout1=new FileOutputStream("accounttemp.dat"
);
149 DataOutputStream dout1=new DataOutputStream(fout1);
150 FileInputStream fin=new FileInputStream("account.dat");
151 DataInputStream din=new DataInputStream(fin);
152 boolean eof=false;
153 while(!eof)
154 {
155 try
156 {
157 long a1=din.readLong();
158 String n1=din.readUTF();
159 int am1=din.readInt();
160 String ad1=din.readUTF();
161 String adp1=din.readUTF();
162 if(ac1!=a1)
163 {
164 dout1.writeLong(a1);
165 dout1.writeUTF(n1);
166 dout1.writeInt(am1);
167 dout1.writeUTF(ad1);
168 dout1.writeUTF(adp1);
169

170 }
171 }
172 catch(EOFException n)
173 {
174 eof=true;
175 }
176 }
177 din.close();
178 fin.close();
179 dout1.close();
180 fout1.close();
181 File t1=new File("accounttemp.dat");
182 File t2=new File("account.dat");
183 t2.delete();
184 t1.renameTo(t2);
185 break;
186 case 5:
187 System.out.println("Enter Account Number");
188 long ac2=sc.nextLong();
189 System.out.println("W - Withdrawal");
190 System.out.println("D - Deposit");
191 String ch3=sc.next();
192 FileOutputStream fout2=new FileOutputStream("accounttemp.dat"
);

30 Jun, 2017 1:41:38 AM


Class Project (continued) 5/8

193 DataOutputStream dout2=new DataOutputStream(fout2);


194 FileInputStream fin1=new FileInputStream("account.dat");
195 DataInputStream din1=new DataInputStream(fin1);
196 boolean eof1=false;
197 while(!eof1)
198 {
199 try
200 {
201 long a1=din1.readLong();
202 String n1=din1.readUTF();
203 int am1=din1.readInt();
204 String ad1=din1.readUTF();
205 String adp1=din1.readUTF();
206 if(ac2==a1)
207 {
208 if(ch3.equalsIgnoreCase("W"))
209 {
210 int wa=0;
211 do
212 {
213 System.out.println("Enter amount to withd
raw");
214 wa=sc.nextInt();
215 }while(wa<1000);
216 am1-=wa;
217 }
218 else if(ch3.equalsIgnoreCase("D"))
219 {
220 System.out.println("Enter amount to deposit")
;
221 int da=sc.nextInt();
222 am1+=da;
223 }
224 }
225 dout2.writeLong(a1);
226 dout2.writeUTF(n1);
227 dout2.writeInt(am1);
228 dout2.writeUTF(ad1);
229 dout2.writeUTF(adp1);
230 }
231 catch(EOFException n)
232 {
233 eof1=true;
234 }
235 }
236 din1.close();
237 fin1.close();
238 dout2.close();
239 fout2.close();

30 Jun, 2017 1:41:39 AM


Class Project (continued) 6/8

240 File t11=new File("accounttemp.dat");


241 File t21=new File("account.dat");
242 t21.delete();
243 t11.renameTo(t21);
244 break;
245 case 6:
246 FileInputStream fin2=new FileInputStream("account.dat");
247 DataInputStream din2=new DataInputStream(fin2);
248 boolean eof2=false;
249 int n2=0;
250 while(!eof2)
251 {
252 try
253 {
254 long a1=din2.readLong();
255 String n1=din2.readUTF();
256 int am1=din2.readInt();
257 String ad1=din2.readUTF();
258 String adp1=din2.readUTF();
259 n2++;
260 }
261 catch(EOFException n)
262 {
263 eof2=true;
264 }
265 }
266 din2.close();
267 fin2.close();
268 long aracc[]=new long[n2];
269 String arna[]=new String[n2];
270 int aram[]=new int[n2];
271 String aradd[]=new String[n2];
272 String aradp[]=new String[n2];
273 FileInputStream fin3=new FileInputStream("account.dat");
274 DataInputStream din3=new DataInputStream(fin3);
275 for(int x=0;x<n2;x++)
276 {
277 long a1=din3.readLong();
278 aracc[x]=a1;
279 String n1=din3.readUTF();
280 arna[x]=n1;
281 int am1=din3.readInt();
282 aram[x]=am1;
283 String ad1=din3.readUTF();
284 aradd[x]=ad1;
285 String adp1=din3.readUTF();
286 aradp[x]=adp1;
287 }
288 for(int x=0;x<n2;x++)

30 Jun, 2017 1:41:39 AM


Class Project (continued) 7/8

289 {
290 for(int y=0;y<n2-1;y++)
291 {
292 if(aracc[y]>aracc[y+1])
293 {
294 long ta=aracc[y];
295 aracc[y]=aracc[y+1];
296 aracc[y+1]=ta;
297

298 String tn=arna[y];


299 arna[y]=arna[y+1];
300 arna[y+1]=tn;
301

302 int tam=aram[y];


303 aram[y]=aram[y+1];
304 aram[y+1]=tam;
305

306 String tad=aradd[y];


307 aradd[y]=aradd[y+1];
308 aradd[y+1]=tad;
309

310 String tap=aradp[y];


311 aradp[y]=aradp[y+1];
312 aradp[y+1]=tap;
313 }
314 }
315 }
316 din3.close();
317 fin3.close();
318 FileOutputStream fout3=new FileOutputStream("accounttemp.dat"
);
319 DataOutputStream dout3=new DataOutputStream(fout3);
320 for(int x=0;x<n2;x++)
321 {
322 dout3.writeLong(aracc[x]);
323 dout3.writeUTF(arna[x]);
324 dout3.writeInt(aram[x]);
325 dout3.writeUTF(aradd[x]);
326 dout3.writeUTF(aradp[x]);
327 }
328 dout3.close();
329 fout3.close();
330 File ts1=new File("accounttemp.dat");
331 File ts2=new File("account.dat");
332 ts2.delete();
333 ts1.renameTo(ts2);
334 break;
335 case 7:
336 break;

30 Jun, 2017 1:41:39 AM


Class Project (continued) 8/8

337 default:
338 System.out.println("Invalid Input");
339 }
340 }
341 }

30 Jun, 2017 1:41:39 AM

Você também pode gostar