0% found this document useful (0 votes)
11 views4 pages

927622bec162 35306 2025 03 04

The document outlines a Java program that demonstrates multi-level inheritance through three classes: Student, Exam, and Result. The Student class holds basic student information, the Exam class adds subject marks, and the Result class calculates total marks and determines pass/fail status based on the scores. The program prompts user input for student details and subject marks, then displays the results accordingly.

Uploaded by

Ram prasath
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

927622bec162 35306 2025 03 04

The document outlines a Java program that demonstrates multi-level inheritance through three classes: Student, Exam, and Result. The Student class holds basic student information, the Exam class adds subject marks, and the Result class calculates total marks and determines pass/fail status based on the scores. The program prompts user input for student details and subject marks, then displays the results accordingly.

Uploaded by

Ram prasath
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 4
S.No:6 Exp. Name: Mult-level inheritance Date:2025-03-01 Ai Write a Java program to model a multi-level inheritance scenario involving classes Student, Exam, and Result. Student Class: Data members: + rollNumber (integer) + name (string) + branch (string) Methods: + Student(int rollNumber, String name, String branch): Constructor to initialize the data members. + void displayStudentDetails(): Method to display the details of the student. Exam Class (inherits from Student): Data members: + subjectMarks (array of integers, size 3) Methods: + Exam(int rollNumber, String name, String branch, int(] subjectMarks): Constructor to initialize the inherited data members from Student and its own data member subjectMarks. isplayExamDetails(): Method to display the details of the student (inherited from Student) and the subject marks, “voi Result Class (inherits from Exam): Data members: + totalMarks (integer) + result (string, either ‘Pass' or Fail’) Methods: + Result(int rollNumber, String name, String branch, intl] subjectMarks): Constructor to initialize the inherited data members from Exam and compute the totalMarks and result. + void displayResult(): Method to display the details of the student (inherited from Student and Exam), totalMarks, and result Pass/Fail Cr + Each subject is scored out of 100 marks, so the total maximum marks for all three subjects are 300. + The student is considered to Pass if their total marks across all subjects are greater than or equel to 150. + If the student's total marks are less than 150, they are considered to Fail Input Format: Prompt the user to enter: + Roll Number (integer) + Name (string) + Branch (string) + Matks for Subject 1, Subject 2, and Subject 3 (integers) Output Format: Display the following information after processing the input iD: 927622BEC162 [zoaa-2026-EcE-C Page No: 1 M.Kumarasamy College of Engineering Result: Exam Details: Student Details: Roll Number: Name: Branch: Subject Marks: Subject 1: Subject 2: Subject 3: Total Marks: Result: ‘Source Codi g25206/TestStudentExamResult. java package q35306; import java.util.Scanner; class Student { protected int rollNumber; protected String name; protected String branch; public Student(int rollNumber, String name, String branch) { this.rollNumber = rollNumber; this.name = name: this.branch = branch; + public void displayStudentDetails() { System.out.printin("Roll Nunber: " * rollNumber ); System.out.println("Name: " + name); System.out.println("Branch: " + branch); } class Exam extends Student { int(] subjectWarks; public Exam(int rollNumber, String name, String branch, int{] subjectMar ks) { super(rollNumber, name, branch); this.subjectMarks = subjectMarks; } public void displayExamDetails() { displayStudentDetails(); System.out.println("Subject Marks:"); for (int i i < subjectWarks.length; i++) { System.out.printin("Subject "+ (i#1) +": " + subjectMarks[i]); , } Class Result extends Exam { 162) PageNo:2 iD: 927622BEC162 [2022-2026-ECE-C M.Kumarasamy College of Engineering int totalMarks; String resul public Result(int rollNumber, String name, String branch, int[] subjectwar ks) { super(rollNumber, name, branch, subjectMarks); this.totalMarks = subjectMarks[0] + subjectMarks[1] + subjectMarks[2]; this.result = (totalarks >= 150) ? "Pass" : "Fail"; } public void displayResult() { system.out.printin("Result displayExamDetails(); System.out.printIn("Total Marks: " + totalMarks); System.out.printIn("Result: "+ result); } public class TestStudentéxamResult { public static void main(Stringt] args) { Scanner scanner = new Scanner(System. in); System.out.print("Roll Number: "); int rollNumber = scanner .nextInt(); scanner .nextLine(); System.out.print("Name: "); String name = scanner .nextLine(): System.out.print("Branch: "); String branch = scanner .nextLine(); int(] subjectWarks = new int(3]; System.out.printIn("Marks:"); for (int i= 0; i < 3; it+) { System.out.print("Subject "+ (i#1) #":"); subjectWarks[i] = scanner.nextInt(); } Result studentResult = new Result(rollNumber, name, branch, subjectMar ks); studentResult.displayResult(); scanner .close(); y } Execution Results - ail test cases have succeeded! Test Case-1 User Output Roll Number: 101 Name: Abhay Branch: Computer Science Marks: 80 Subject 1: 80 Subject 2: 75 Subject 3: 85 Result: Roll Number: 101 162) PageNo:3 iD: 927622BEC162 [2022-2026-ECE-C M.Kumarasamy College of Engineering Name: Abhay Branch: Computer Science Subject Marks: Subject 1: 80 Subject 2: 75 Subject 3: 85 3 Total Marks: 240 & Result: Pass é Test Case-2 2 User Output 8 Roll Nunber: 104 a Name: David Branch: Civil Marks: 40 Subject 1: 40 Subject 2: 35 Subject 3: 30 Result: Roll Number: 104 Name: David Branch: Civil Subject Marks: Subject 1: 40 Subject 2: 35 Subject 3: 30 Total Marks: 105 Result: Fail 9 a g M.Kumarasamy College of Engineering

You might also like