Computer Science, asked by acmnittecommunity, 3 months ago

Create a class named Student. Define the method getDetails( ) to set values for name and roll no of student. Define another class Test which contains the method getMarks( ) to get the marks of student. Define an interface Sports and initialize weightage marks for sports. Create a class Results, which extends the class Test and implements the interface Sports. Using objects, invoke the appropriate methods and display the results.

Answers

Answered by mehtachintan983
0

Answer:

Explanation:

ok

Answered by theshubhamkumar01
3

Answer:

package lab_2;

import java.util.*;

class Student {

private String name;

private int roll_num;

 

Scanner s = new Scanner(System.in);

 

public void read()

   {

 System.out.println("Enter details of the Student : ");

    System.out.println("Enter name : ");

    name = s.next();

    System.out.println("Enter Roll no. : ");

    roll_num = s.nextInt();

   }

 

public String getName() {

 return name;

}

public int getRoll_num() {

 return roll_num;

}

public void show() {

 System.out.println("Details of the Student are : ");

 System.out.println("Name : "+name);

 System.out.println("Roll Number : "+roll_num);

}

}

class Test extends Student {

protected int m1,m2,m3;

 

public void read()

   {

       super.read();

       System.out.println("Enter marks of subject 1");

       m1 = s.nextInt();

       

       System.out.println("Enter marks of subject 2");

       m2 = s.nextInt();

       

       System.out.println("Enter marks of subject 3");

       m3 = s.nextInt();

   }

 

void show_marks() {

 System.out.println("Subject 1 Marks : "+m1);

 System.out.println("Subject 2 Marks : "+m2);

 System.out.println("Subject 3 Marks : "+m3);

}

 

}

interface Sports {

public static final int s1 = 3;

public void show_sportswt();

}

class Result extends Test implements Sports {

int tot_marks;

 

public void show_sportswt() {

 System.out.println("Sports marks is : "+Sports.s1);

}

public void show_res() {

 

 super.show();

 show_marks();

 tot_marks = m1 + m2 + m3 + Sports.s1;

 show_sportswt();

 System.out.println("Total Marks Obtained by "+ this.getName() +" is : "+tot_marks);

}

 

}

public class Test_Student {

public static void main(String[] args) {

 

 Result r = new Result();

 r.read();

 System.out.println();

 r.show_res();

 

}

}

Explanation:

Similar questions