-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdd.java
More file actions
111 lines (80 loc) · 3.25 KB
/
Add.java
File metadata and controls
111 lines (80 loc) · 3.25 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import java.io.*;
import java.util.*;
class Add extends Headertop
{
public static void writerfile(String code)throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
BufferedWriter buf=new BufferedWriter(new FileWriter("Institutions.dat",true));
BufferedWriter buft=new BufferedWriter(new FileWriter("temp.dat",true));
PrintWriter prt=new PrintWriter(buft);
PrintWriter pr=new PrintWriter(buf);
Scanner sc=new Scanner(new File("code.dat"));
String record;
String name,address,contact,category,hostel;
int rec;
clearcls();
header();
head("ADD INSTITUTION");
/*To fetch number of record in code file which stores the code and numrec which is then incremented*/
String nrec="0",norec="0";
while(sc.hasNextLine())
{
record=sc.nextLine();
Scanner sc1=new Scanner(record).useDelimiter(";");
String c=sc1.next();
//Write non matching records to temp file
if(c.equals(code)==false)
{
nrec=sc1.next();
prt.println(c+";"+nrec);
}
else
{
norec=sc1.next();
}
sc1.close();
}
rec=Integer.parseInt(norec);
sc.close();
System.out.println("Enter the number of Institutions data u want to enter:\t");
int n=Integer.parseInt(br.readLine());
System.out.println();
for(int i=1;i<=n;i++)
{
System.out.println("--------------------------------------------------------------------------------------");
System.out.println("Enter the name of the Institute");
name=enterString();
System.out.println("--------------------------------------------------------------------------------------");
System.out.println("--------------------------------------------------------------------------------------");
System.out.println("Enter address");
address=enterString();
System.out.println("--------------------------------------------------------------------------------------");
System.out.println("--------------------------------------------------------------------------------------");
System.out.println("Enter contact number");
contact=enterContact();
System.out.println("--------------------------------------------------------------------------------------");
System.out.println("--------------------------------------------------------------------------------------");
System.out.println("Enter the Category(National/International)");
category=enterCategory();
System.out.println("--------------------------------------------------------------------------------------");
System.out.println("--------------------------------------------------------------------------------------");
System.out.println("Enter if the Institute provides hostel facility(Yes/No)");
hostel=enterHostel();
System.out.println("--------------------------------------------------------------------------------------");
rec++;
System.out.println();
pr.println(code+";"+rec+";"+name+";"+address+";"+contact+";"+category+";"+hostel);
}
prt.println(code+";"+rec);
rec=0;
pr.close();
prt.close();
sc.close();
File f=new File("code.dat");
File f1=new File("temp.dat");
f.delete();
f1.renameTo(f);
callagain(); //Goes to refer main menu
}
}