-
Notifications
You must be signed in to change notification settings - Fork 1
/
MultiLevelInheritance.java
77 lines (67 loc) · 2.46 KB
/
MultiLevelInheritance.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
import java.util.Scanner;
class Students {
Scanner input = new Scanner(System.in);
int roll_no;
String name;
void getInfo() {
System.out.print("Enter Name :: ");
name = input.nextLine();
System.out.print("Enter Roll No. :: ");
roll_no = input.nextInt();
}
}
class Marks extends Students {
int phy,chem,maths,computer,assign;
void getMarks() {
System.out.print("Enter Marks of Physics :: ");
phy = input.nextInt();
System.out.print("Enter Marks of Chemistry :: ");
chem = input.nextInt();
System.out.print("Enter Marks of Mathematics :: ");
maths = input.nextInt();
System.out.print("Enter Marks of Computer Science :: ");
computer = input.nextInt();
System.out.print("Enter Marks of Co-curricular Acitivities/Assignments :: ");
assign = input.nextInt();
}
}
class Results extends Marks {
int total_marks;
float avg;
void getDetails() {
getInfo();
getMarks();
}
int TotalMarks() {
total_marks = phy+chem+maths+computer+assign;
return total_marks;
}
float AverageMarks() {
int x = TotalMarks();
avg = total_marks/5.0f;
return avg;
}
void displayDetails() {
System.out.println("\n\t ANNUAL MARKSHEET");
System.out.println("*****************************************");
System.out.println("Name \t : "+name);
System.out.println("Roll No. : "+roll_no);
System.out.println("-----------------------------------------\n");
System.out.println("PHYSICS \t\t\t: "+phy);
System.out.println("CHEMISTRY \t\t\t: "+chem);
System.out.println("MATHEMATICS \t\t\t: "+maths);
System.out.println("COMPUTER SCIENCE \t\t: "+computer);
System.out.println("CO-CURRICULAR / ASSIGNMENTS \t: "+assign);
System.out.println("\n*****************************************");
System.out.println("TOTAL MARKS OBTAINED (out of 500) : "+TotalMarks());
System.out.printf("PERCENTAGE OBTAINED : %.2f %% \n", AverageMarks());
System.out.println("\n*****************************************");
}
}
public class MultiLevelInheritance {
public static void main(String[] args) {
Results student = new Results();
student.getDetails();
student.displayDetails();
}
}