-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignment4b.java
More file actions
66 lines (55 loc) · 2.17 KB
/
assignment4b.java
File metadata and controls
66 lines (55 loc) · 2.17 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
import java.io.*;
import java.util.*;
public class assignment4b {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
String name;
int roll_no, choice = 0;
int subs[] = new int[5];
while (choice != 3) {
System.out.print("\n\n\t\t\t***Menu***\n1)Enter Record\n2)Show all records\n3)Exit\n-:");
choice=input.nextInt();
switch (choice) {
case 1:
System.out.print("Enter Name :");
name = input.next();
System.out.print("Enter Roll Number :");
roll_no = input.nextInt();
for (int i = 0; i < subs.length; i++) {
System.out.print("Enter Marks :");
subs[i] = input.nextInt();
}
try {
FileWriter fr = new FileWriter("data.txt",true);
BufferedWriter writer = new BufferedWriter(fr);
writer.write("\n"+name+" "+Integer.toString(roll_no)+" ");
for (int j = 0; j < subs.length; j++) {
writer.write(Integer.toString(subs[j]));
writer.write(" ");
}
writer.close();
} catch (IOException e) {
System.out.println(e);
}
break;
case 2:
try {
int temp;
System.out.println("Name RollNo Sub1 Sub2 Sub3 Sub4 Sub5");
FileReader fr = new FileReader("data.txt");
BufferedReader reader = new BufferedReader(fr);
while ((temp = reader.read()) != -1) {
System.out.print((char) temp);
}
reader.close();
} catch (IOException e) {
System.out.println(e);
}
break;
default:
break;
}
}
input.close();
}
}