Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class exam {
- public static void main(String[] Args)
- {
- Scanner sc = new Scanner(System.in);
- System.out.print("Enter name : ");
- Basic.name = sc.nextLine();
- System.out.print("Enter Roll_no : ");
- Basic.roll_no = sc.nextInt();
- Advanced obj = new Advanced();
- Basic.Details();
- obj.ExamMarks();
- obj.AllRounds();
- }
- }
- class Basic{
- double percentage;
- static double total;
- static double full_marks;
- String label;
- static String name;
- static int roll_no;
- Scanner sc;
- Basic()
- {
- sc = new Scanner(System.in);
- full_marks = 100.0;
- total = 0.0;
- }
- private void Question()
- {
- System.out.print("\nWhat is 2+2? : ");
- if(4 == sc.nextInt())
- total += 20;
- System.out.print("\nWhat is 5*2? : ");
- if(10 == sc.nextInt())
- total += 20;
- System.out.print("\nWhat is 8*8? : ");
- if(64 == sc.nextInt())
- total += 20;
- System.out.print("\nWhat is 7*7? : ");
- if(49 == sc.nextInt())
- total += 20;
- System.out.print("\nWhat is 10*2? : ");
- if(20 == sc.nextInt())
- total += 20;
- }
- static void Details()
- {
- System.out.print("\n\nWelcome, " + name + ", Roll no : " + roll_no + "\n\n\tEXAM STARTS\n\n");
- }
- void ExamMarks()
- {
- label = "BASIC";
- System.out.println("\n\n<---" + label + "--->");
- Question();
- percentage = (total / full_marks) * 100.0;
- System.out.println(total + "/" + full_marks+"\tPercentage = " + percentage + "%");
- }
- boolean Qualified_for_Inter()
- {
- if(percentage >= 60.0)
- return true;
- return false;
- }
- }
- class Intermediate extends Basic{
- double percentage;
- static double total;
- static double full_marks;
- Intermediate()
- {
- super();
- total = 0.0;
- full_marks = 100.0;
- }
- private void Question()
- {
- System.out.print("\nWhat is 22+2? : ");
- if(24 == sc.nextInt())
- total += 20;
- System.out.print("\nWhat is 25*4? : ");
- if(100 == sc.nextInt())
- total += 20;
- System.out.print("\nWhat is 23*3? : ");
- if(69 == sc.nextInt())
- total += 20;
- System.out.print("\nWhat is 7*8? : ");
- if(56 == sc.nextInt())
- total += 20;
- System.out.print("\nWhat is 10*29? : ");
- if(290 == sc.nextInt())
- total += 20;
- }
- void ExamMarks()
- {
- super.ExamMarks();
- if(!Qualified_for_Inter())
- {
- System.out.println("Sorry, not qualified for Inter Round.");
- return;
- }
- System.out.println("Qualified for inter round!");
- label = "INTERMEDIATE";
- System.out.println("\n\n<---" + label + "--->");
- Question();
- percentage = (total / full_marks) * 100.0;
- System.out.println(total + "/" + full_marks+"\tPercentage = " + percentage + "%");
- }
- boolean Qualified_for_Advanced()
- {
- if(percentage >= 60.0)
- return true;
- return false;
- }
- }
- class Advanced extends Intermediate{
- double percentage;
- static double total;
- static double full_marks;
- Advanced()
- {
- super();
- full_marks = 100.0;
- total = 0.0;
- }
- private void Question()
- {
- System.out.print("\nWhat is 22+28? : ");
- if(50 == sc.nextInt())
- total += 20;
- System.out.print("\nWhat is 25*40? : ");
- if(1000 == sc.nextInt())
- total += 20;
- System.out.print("\nWhat is 69/3? : ");
- if(23 == sc.nextInt())
- total += 20;
- System.out.print("\nWhat is 9%8? : ");
- if(1 == sc.nextInt())
- total += 20;
- System.out.print("\nWhat is 250+602? : ");
- if(852 == sc.nextInt())
- total += 20;
- }
- void ExamMarks()
- {
- super.ExamMarks();
- if(!Qualified_for_Advanced())
- {
- System.out.println("Sorry, not qualified for Advanced Round.");
- return;
- }
- System.out.println("Qualified for Advanced round!");
- label = "ADVANCED";
- System.out.println("\n\n<---" + label + "--->");
- Question();
- percentage = (total / full_marks) * 100.0;
- System.out.println(total + "/" + full_marks+"\tPercentage = " + percentage + "%");
- }
- void AllRounds()
- {
- double all_total = 0.0, all_perc;
- if(Qualified_for_Advanced())
- {
- System.out.println("Advanced Round\tTotal Marks : "+total+"/"+full_marks+"\tPercentage : "+percentage+"%");
- System.out.println("Inter Round\tTotal Marks : "+Intermediate.total+"/"+Intermediate.full_marks+"\tPercentage : "+((Intermediate) this).percentage+"%");
- all_total = total + Intermediate.total;
- }
- else if(Qualified_for_Inter())
- {
- System.out.println("Inter Round\tTotal Marks : "+Intermediate.total+"/"+Intermediate.full_marks+"\tPercentage : "+((Intermediate) this).percentage+"%");
- all_total += Intermediate.total;
- }
- System.out.println("Basic Round\tTotal Marks : "+Basic.total+"/"+Basic.full_marks+"\tPercentage : "+((Basic) this).percentage+"%");
- all_total += Basic.total;
- all_perc = (all_total/300.0)*100;
- System.out.println("\nALL ROUND\tTotal Marks : "+all_total+"/"+"300.0"+"\tPercentage : "+all_perc+"%");
- }
- }
Add Comment
Please, Sign In to add comment