Advertisement
brandblox

Java lab 2 (30/10/2023)

Oct 30th, 2023
886
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1.  
  2.  
  3. class Student {
  4.     String name;
  5.     int id;
  6.  
  7.     void getDetails(String n, int i) {
  8.         name = n;
  9.         id = i;
  10.     }
  11.  
  12.     void showDetails() {
  13.         System.out.println("Name: " + name);
  14.         System.out.println("ID: " + id);
  15.     }
  16. }
  17.  
  18. class Exam extends Student {
  19.     int marks1;
  20.     int marks2;
  21.  
  22.     void getMarks(int marks1, int marks2) {
  23.         this.marks1 = marks1;
  24.         this.marks2 = marks2;
  25.     }
  26.  
  27.     void putMarks() {
  28.         System.out.println("Marks 1: " + marks1);
  29.         System.out.println("Marks 2: " + marks2);
  30.     }
  31. }
  32. interface Sports {
  33.     int sportwt = 7;
  34.  
  35.     void putWt();
  36. }
  37. class Result extends Exam implements Sports {
  38.  
  39.  
  40.     public void putWt() {
  41.         System.out.println("Sport Weight: " + sportwt);
  42.     }
  43.  
  44.     int total;
  45.  
  46.     void totalMarks() {
  47.         total = marks1 + marks2 + sportwt;
  48.     }
  49.  
  50.     void display() {
  51.         showDetails();
  52.         putMarks();
  53.         putWt();
  54.         System.out.println("Total Marks: " + total);
  55.     }
  56. }
  57.  
  58. class DemoMain {
  59.     public static void main(String[] args) {
  60.         Result result = new Result();
  61.         result.getDetails("Arijit", 29);
  62.         result.getMarks(80, 85);
  63.         result.totalMarks();
  64.         result.display();
  65.     }
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement