Advertisement
Shailrshah

Implementing Interfaces to Print the Exam Result

Oct 30th, 2013
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. import java.util.Scanner;
  2. interface Exam{
  3.     boolean pass(int marks);
  4. }
  5. interface Classify{
  6.     String division(int average);
  7. }
  8. class Result implements Exam, Classify{
  9.     public boolean pass(int marks){
  10.         if(marks > 40) return true;
  11.         else return false;
  12.     }
  13.     public String division(int average){
  14.         if(average < 40) return "Third";
  15.         else if (average > 40 && average < 60) return "Second";
  16.         else return "First";
  17.     }
  18.     public static void main(String[] args){
  19.         int DSA, OOPM, DBMS;
  20.         Scanner sc = new Scanner(System.in);
  21.         Result r = new Result();
  22.         System.out.print("Enter marks for DSA on 100: ");
  23.         DSA = sc.nextInt();
  24.         if(r.pass(DSA)) System.out.println("Passed in DSA.");
  25.         else System.out.println("Failed in DSA.");
  26.         System.out.print("Enter the score for OOPM on 100: ");
  27.         OOPM = sc.nextInt();
  28.         if(r.pass(OOPM)) System.out.println("Passed in OOPM.");
  29.         else System.out.println("Failed in OOPM.");
  30.         System.out.print("Enter the score for DBMS on 100: ");
  31.         DBMS = sc.nextInt();
  32.         if(r.pass(DBMS)) System.out.println("Passed in DBMS.");
  33.         else System.out.println("Failed in DBMS.");
  34.         System.out.println("The class is "+r.division((DSA+OOPM+DBMS)/3));
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement