Skip to content

Commit 9d2b21c

Browse files
committed
Create StudentResult.java
1 parent a9bcffb commit 9d2b21c

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

Derived_Class/StudentResult.java

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Design a class called Student having data members like student name and roll
3+
* number and method called show to display the name and roll number. Derive a
4+
* class called Test from student class having three subjects marks as a data
5+
* members and method named show_marks to display the marks. Create an interface
6+
* called Sports contains constant sports marks and method show_sportswt. Derive
7+
* a class Result from Test class and implement the interface Sports. Calculate
8+
* total marks by considering sports marks. Then display the total in Result
9+
* class.
10+
*/
11+
12+
package Derived_Class;
13+
14+
import java.util.Scanner;
15+
16+
class Student {
17+
String name;
18+
int rollno;
19+
20+
Student(String name, int rno) {
21+
this.name = name;
22+
rollno = rno;
23+
}
24+
25+
void show() {
26+
System.out.println("Name: " + name + "\nRoll Number: " + rollno);
27+
}
28+
}
29+
30+
31+
class Test extends Student {
32+
int sub1, sub2, sub3;
33+
34+
Test(int sub1, int sub2, int sub3, String name, int rno) {
35+
super(name, rno);
36+
this.sub1 = sub1;
37+
this.sub2 = sub2;
38+
this.sub3 = sub3;
39+
}
40+
41+
void show_marks() {
42+
super.show();
43+
System.out.println("Subject 1: " + sub1 + "\nSubject 2: " + sub2 + "\nSubject 3: " + sub3);
44+
}
45+
}
46+
47+
48+
interface Sports {
49+
final int sport_mark = 40;
50+
51+
void show_sportswt();
52+
}
53+
54+
55+
class Result extends Test implements Sports {
56+
int total = sub1 + sub2 + sub3 + sport_mark;
57+
58+
public void show_sportswt() {
59+
System.out.println("Sports marks: " + sport_mark);
60+
}
61+
62+
Result(String name, int rollno, int sub1, int sub2, int sub3) {
63+
super(sub1, sub2, sub3, name, rollno);
64+
}
65+
66+
void display() {
67+
super.show_marks();
68+
System.out.println("Total Marks: " + total);
69+
}
70+
}
71+
72+
public class StudentResult {
73+
public static void main(String[] args){
74+
Scanner s = new Scanner(System.in);
75+
System.out.println("Enter name, roll number and marks in 3 subjects:");
76+
String name = s.nextLine();
77+
int rno = s.nextInt();
78+
int sub1 = s.nextInt();
79+
int sub2 = s.nextInt();
80+
int sub3 = s.nextInt();
81+
82+
Result res = new Result(name, rno, sub1, sub2, sub3);
83+
84+
res.display();
85+
res.show_sportswt();
86+
87+
s.close();
88+
}
89+
}

0 commit comments

Comments
 (0)