-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREPORT.java
198 lines (189 loc) · 5.93 KB
/
REPORT.java
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
Implementation of super and this
1. use of this keyword to initialize data members - 1 mark
2. use of this keyword in constructor chaining - 1 mark
3. use of super keyword to call parent class methods - 1 marks
4. Use of super keyword to pass parameters to parent class constructor - 1 mark"
*/
import java.io.*; //Basic IO Class
import java.sql.Time; //Class for Time
import java.util.Scanner; //IO using scanner
//Parent Class
class SCHOOL
{
//Variable declaration
private int schNo;
private String schName;
private String schCity;
private String schHead;
SCHOOL(int schNo,String schName,String schHead)
{
this.schNo = schNo;
this.schName = schName;
this.schHead = schHead;
}
SCHOOL(int schNo,String schName,String schHead,String schCity)
{
//Constructor Chaining
this(schNo,schName,schHead);
this.schCity = schCity;
}
SCHOOL()
{
schNo = 0;
}
public void schDisplay()
{
System.out.println("\n\t\t*SCHOOL INFORMATION*\n");
System.out.println("School's No is:\t\t\t"+schNo);
System.out.println("School's Name is:\t\t"+schName);
System.out.println("School is in:\t\t\t"+schCity);
System.out.println("School's Head is:\t\t"+schHead);
}
}
// Child Class for SCHOOL
class CLASS extends SCHOOL
{
//Variable decalration
private String cLocation;
private String cName;
private String cSection;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
CLASS(String cLocation)
{
this.cLocation = cLocation;
}
CLASS()
{
//Passing parameter to parent class constructor
super(17822,"Mordern Public School","Mr. Augusti","Delhi");
}
public void cRead() throws IOException
{
System.out.print("Enter Location of the class:\t");
cLocation = br.readLine();
System.out.print("Enter Name of the class:\t");
cName = br.readLine();
System.out.print("Enter Section of the class:\t");
cSection = br.readLine();
}
public void schDisp()
{
super.schDisplay();
System.out.println("\n\t\t*CLASS INFORMATION*\n");
System.out.println("Location of the class is:\t" + cLocation);
System.out.println("Name of the class is:\t\t"+cName);
System.out.println("Section of the class is:\t"+cSection);
}
}
//Child class to CLASS
class STUDENT extends CLASS
{
private int sRollNo;
private String sName;
private short sAge;
public void sRead() throws IOException
{
super.cRead();
System.out.print("Enter Student's Roll No.:\t");
sRollNo = Integer.parseInt(super.br.readLine());
System.out.print("Enter Student's Name:\t\t");
sName = super.br.readLine();
System.out.print("Enter Student's Age:\t\t");
sAge = Short.parseShort(super.br.readLine());
}
public void schDisp()
{
super.schDisp();
System.out.println("\n\t\t*PERSONAL INFORMATION*\n");
System.out.println("Student's Roll No is.:\t\t" + sRollNo);
System.out.println("Student's Name is:\t\t" + sName);
System.out.println("Student's Age is:\t\t" + sAge);
}
}
//Child class to STUDENT
class RESULT extends STUDENT
{
private String[] sub= {"English","Hindi ","Maths ","Science","EVS "};
private float[] rMarks = new float[5];
private float res = 0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public void rRead() throws IOException
{
super.sRead();
int i;
res = 0;
for(i=0; i<5; i++)
{
System.out.print("Marks in " + sub[i] + ":\t\t");
rMarks[i] = Float.parseFloat(br.readLine());
if(rMarks[i] < 101)
{
res = res + rMarks[i];
}
else
{
i--;
System.out.println("Error:Marks should be less than 100");
}
}
}
public void rDisp()
{
super.schDisp();
System.out.println("\t\t*MARKS*\n");
int i;
for(i=0; i<5; i++)
{
System.out.println("Marks in " + sub[i] + " is:\t\t" + rMarks[i]);
}
}
//Checking if the student is pass or fail
public void pof()
{
float ress = (res/5);
System.out.println("Percentage :\t\t\t" + ress + "%");
if (ress>35)
System.out.println("Result :\t\t\tPASS\n");
else
System.out.println("Result :\t\t\tFAIL\n");
}
}
public class REPORT
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
RESULT obj = new RESULT();
byte ch = 0,choice =0;
do {
System.out.println("\n\t***Please Enter the Following Details for Mordern Public School***\n");
obj.rRead();
do
{
System.out.print("\nChoose from the following:\n\t1. Display Result\n\t2. Status and Percentage\n\t3. Enter Values again or Exit\n\nChoice:\t\t");
ch = Byte.parseByte(br.readLine());
System.out.print("\n");
if(ch==1)
{
System.out.println("\n\n\t\t\t**Report Card:**");
obj.rDisp();
}
else if(ch==2)
{
obj.pof();
}
else if(ch==3)
{
break;
}
else
{
System.out.println("\n\n\t\t**Not a valid option, please try again!**\n\n");
}
}while(ch!=3);
System.out.print("\nPress 1 if you want to exit, otherwise enter any number to enter new values:\t");
choice = Byte.parseByte(br.readLine());
}while (choice!=1);
}
}