AnindyaBiswas

exam

Jun 15th, 2022 (edited)
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.55 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class exam {
  4.     public static void main(String[] Args)
  5.     {
  6.         Scanner sc = new Scanner(System.in);
  7.         System.out.print("Enter name : ");
  8.         Basic.name = sc.nextLine();
  9.         System.out.print("Enter Roll_no : ");
  10.         Basic.roll_no = sc.nextInt();
  11.         Advanced obj = new Advanced();
  12.         Basic.Details();      
  13.         obj.ExamMarks();
  14.         obj.AllRounds();
  15.     }
  16. }
  17.  
  18. class Basic{
  19.     double percentage;
  20.     static double total;
  21.     static double full_marks;
  22.     String label;
  23.     static String name;
  24.     static int roll_no;
  25.     Scanner sc;
  26.     Basic()
  27.     {
  28.         sc = new Scanner(System.in);
  29.         full_marks = 100.0;
  30.         total = 0.0;
  31.     }
  32.    
  33.     private void Question()
  34.     {
  35.         System.out.print("\nWhat is 2+2? : ");
  36.         if(4 == sc.nextInt())
  37.             total += 20;
  38.         System.out.print("\nWhat is 5*2? : ");
  39.         if(10 == sc.nextInt())
  40.             total += 20;
  41.            
  42.         System.out.print("\nWhat is 8*8? : ");
  43.         if(64 == sc.nextInt())
  44.             total += 20;
  45.            
  46.        
  47.         System.out.print("\nWhat is 7*7? : ");
  48.         if(49 == sc.nextInt())
  49.             total += 20;
  50.         System.out.print("\nWhat is 10*2? : ");
  51.         if(20 == sc.nextInt())
  52.             total += 20;
  53.     }
  54.    
  55.     static void Details()
  56.     {
  57.         System.out.print("\n\nWelcome, " + name + ", Roll no : " + roll_no + "\n\n\tEXAM STARTS\n\n");
  58.     }
  59.  
  60.  
  61.     void ExamMarks()
  62.     {
  63.         label = "BASIC";
  64.         System.out.println("\n\n<---" + label + "--->");
  65.         Question();
  66.         percentage = (total / full_marks) * 100.0;
  67.         System.out.println(total + "/" + full_marks+"\tPercentage = " + percentage + "%");
  68.     }
  69.  
  70.     boolean Qualified_for_Inter()
  71.     {
  72.         if(percentage >= 60.0)
  73.             return true;
  74.         return false;
  75.     }
  76.  
  77. }
  78.  
  79. class Intermediate extends Basic{
  80.     double percentage;
  81.     static double total;
  82.     static double full_marks;
  83.    
  84.     Intermediate()
  85.     {
  86.         super();
  87.         total = 0.0;
  88.         full_marks = 100.0;
  89.     }
  90.    
  91.     private void Question()
  92.     {
  93.         System.out.print("\nWhat is 22+2? : ");
  94.         if(24 == sc.nextInt())
  95.             total += 20;
  96.         System.out.print("\nWhat is 25*4? : ");
  97.         if(100 == sc.nextInt())
  98.             total += 20;
  99.            
  100.         System.out.print("\nWhat is 23*3? : ");
  101.         if(69 == sc.nextInt())
  102.             total += 20;
  103.            
  104.         System.out.print("\nWhat is 7*8? : ");
  105.         if(56 == sc.nextInt())
  106.             total += 20;
  107.         System.out.print("\nWhat is 10*29? : ");
  108.         if(290 == sc.nextInt())
  109.             total += 20;
  110.     }
  111.    
  112.     void ExamMarks()
  113.     {
  114.         super.ExamMarks();
  115.         if(!Qualified_for_Inter())
  116.         {
  117.             System.out.println("Sorry, not qualified for Inter Round.");
  118.             return;
  119.         }
  120.        
  121.         System.out.println("Qualified for inter round!");
  122.         label = "INTERMEDIATE";
  123.         System.out.println("\n\n<---" + label + "--->");
  124.         Question();
  125.  
  126.         percentage = (total / full_marks) * 100.0;
  127.         System.out.println(total + "/" + full_marks+"\tPercentage = " + percentage + "%");
  128.     }
  129.  
  130.     boolean Qualified_for_Advanced()
  131.     {
  132.         if(percentage >= 60.0)
  133.             return true;
  134.         return false;
  135.     }
  136. }
  137.  
  138. class Advanced extends Intermediate{
  139.  
  140.     double percentage;
  141.     static double total;
  142.     static double full_marks;
  143.  
  144.     Advanced()
  145.     {
  146.         super();
  147.         full_marks = 100.0;
  148.        
  149.         total = 0.0;
  150.     }
  151.  
  152.        private void Question()
  153.     {
  154.         System.out.print("\nWhat is 22+28? : ");
  155.         if(50 == sc.nextInt())
  156.             total += 20;
  157.         System.out.print("\nWhat is 25*40? : ");
  158.         if(1000 == sc.nextInt())
  159.             total += 20;
  160.            
  161.         System.out.print("\nWhat is 69/3? : ");
  162.         if(23 == sc.nextInt())
  163.             total += 20;
  164.            
  165.         System.out.print("\nWhat is 9%8? : ");
  166.         if(1 == sc.nextInt())
  167.             total += 20;
  168.         System.out.print("\nWhat is 250+602? : ");
  169.         if(852 == sc.nextInt())
  170.             total += 20;
  171.     }
  172.    
  173.     void ExamMarks()
  174.     {
  175.         super.ExamMarks();
  176.         if(!Qualified_for_Advanced())
  177.         {
  178.             System.out.println("Sorry, not qualified for Advanced Round.");
  179.             return;
  180.         }
  181.         System.out.println("Qualified for Advanced round!");
  182.         label = "ADVANCED";
  183.         System.out.println("\n\n<---" + label + "--->");
  184.         Question();
  185.         percentage = (total / full_marks) * 100.0;
  186.         System.out.println(total + "/" + full_marks+"\tPercentage = " + percentage + "%");
  187.     }
  188.  
  189.     void AllRounds()
  190.     {
  191.         double all_total = 0.0, all_perc;
  192.         if(Qualified_for_Advanced())
  193.         {
  194.             System.out.println("Advanced Round\tTotal Marks : "+total+"/"+full_marks+"\tPercentage : "+percentage+"%");
  195.             System.out.println("Inter Round\tTotal Marks : "+Intermediate.total+"/"+Intermediate.full_marks+"\tPercentage : "+((Intermediate) this).percentage+"%");
  196.             all_total = total + Intermediate.total;
  197.         }
  198.         else if(Qualified_for_Inter())
  199.         {
  200.             System.out.println("Inter Round\tTotal Marks : "+Intermediate.total+"/"+Intermediate.full_marks+"\tPercentage : "+((Intermediate) this).percentage+"%");
  201.             all_total += Intermediate.total;
  202.         }
  203.         System.out.println("Basic Round\tTotal Marks : "+Basic.total+"/"+Basic.full_marks+"\tPercentage : "+((Basic) this).percentage+"%");
  204.         all_total += Basic.total;
  205.         all_perc = (all_total/300.0)*100;
  206.          System.out.println("\nALL ROUND\tTotal Marks : "+all_total+"/"+"300.0"+"\tPercentage : "+all_perc+"%");
  207.  
  208.     }
  209.  
  210.  
  211.  
  212. }
Add Comment
Please, Sign In to add comment