-
Notifications
You must be signed in to change notification settings - Fork 1
/
MultiInheritence.java
53 lines (41 loc) · 1.33 KB
/
MultiInheritence.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
import java.util.*;
public class MultiInheritence {
int rollNumber;
MultiInheritence(int rollNumber) {
this.rollNumber = rollNumber;
}
}
class Test extends MultiInheritence {
double[] marks;
public Test(int rollNumber, double[] marks) {
super(rollNumber);
this.marks = marks;
}
}
class Result extends Test {
public Result(int rollNumber, double[] marks) {
super(rollNumber, marks);
}
public void display() {
double total = 0;
for (double mark : marks) {
total += mark;
}
double average = total / marks.length;
System.out.println(rollNumber + " " + total + " " + average);
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int testCases = scanner.nextInt(); // Number of test cases
for (int i = 0; i < testCases; i++) {
int rollNumber = scanner.nextInt(); // Roll number of the student
double[] marks = new double[5]; // Array to store the marks
for (int j = 0; j < 5; j++) {
marks[j] = scanner.nextDouble();
}
Result result = new Result(rollNumber, marks);
result.display();
}
scanner.close();
}
}