Advertisement
AlphaPenguino

Arithmetic Quiz with Score Counter 1.2.2

Oct 26th, 2022 (edited)
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.47 KB | Source Code | 0 0
  1. package practice.programpractice;
  2. import java.util.*;
  3. public class switchQuiz {
  4.    
  5.     //Author Zunder Jacob A. Pacis
  6.     // 1.2.2
  7.    
  8.     public static void main(String[] args) {
  9.        
  10.         Scanner sc = new Scanner(System.in);
  11.         System.out.println("How many items do you want to answer?");
  12.         byte item = sc.nextByte();
  13.         byte i;
  14.         System.out.println("What math operation do you want to solve?\n1 - addition\t\t2 - subtraction\n3 - multiplication\t4 - division");
  15.         byte operator = sc.nextByte();
  16.         int score = 0;
  17.         switch (operator) {
  18.             case 1 -> {
  19.                 System.out.println("You have chosen Addition!\n");
  20.                 for (i = 0; i < item; i++) {
  21.                 int a = (int) (Math.random() * 11);
  22.                 int b = (int) (Math.random() * 11);
  23.                 int itemNo = i + 1;
  24.                 System.out.println(itemNo + ". What is " + a + " + " + b + "?");
  25.                 int ans = a+b;
  26.                 int input = sc.nextInt();
  27.                 if (input==a+b) {
  28.                     System.out.println("Your answer is correct!");
  29.                     score++;
  30.                  }
  31.                 else System.out.println("Your answer is wrong!, the correct answer is " + ans);
  32.                  }
  33.                  }
  34.             case 2 -> {
  35.                 System.out.println("You have chosen Subtraction!\n");
  36.                 for (i = 0; i < item; i++) {
  37.                 int a = (int) (Math.random() * 11);
  38.                 int b = (int) (Math.random() * 11);
  39.                 int itemNo = i + 1;
  40.                 System.out.println(itemNo + ". What is " + a + " - " + b + "?");
  41.                 int ans = a-b;
  42.                 int input = sc.nextInt();
  43.                 if (input==a-b) {
  44.                     System.out.println("Your answer is correct!");
  45.                     score++;
  46.                  }
  47.                 else System.out.println("Your answer is wrong!, the correct answer is " + ans);
  48.                  }
  49.                  }
  50.             case 3 -> {
  51.                 System.out.println("You have chosen Multiplication!\n");
  52.                 for (i = 0; i < item; i++) {
  53.                 int a = (int) (Math.random() * 11);
  54.                 int b = (int) (Math.random() * 11);
  55.                 int itemNo = i + 1;
  56.                 System.out.println(itemNo + ". What is " + a + " x " + b + "?");
  57.                 int ans = a*b;
  58.                 int input = sc.nextInt();
  59.                 if (input==a*b) {
  60.                     System.out.println("Your answer is correct!");
  61.                     score++;
  62.                  }
  63.                 else System.out.println("Your answer is wrong!, the correct answer is " + ans);
  64.                  }
  65.                  }
  66.             case 4 -> {
  67.                 System.out.println("You have chosen Division!\n");
  68.                 for (i = 0; i < item; i++) {
  69.                 int a = (int) (Math.random() * 11);
  70.                 int b = (int) (Math.random() * 11);
  71.                 int itemNo = i + 1;
  72.                 float c = a;
  73.                 float d = b;
  74.                 System.out.println(itemNo + ". What is " + a + " ÷ " + b + "?");
  75.                 float ans = c/d;
  76.                 float input = sc.nextFloat();
  77.                 if (input==c/d) {
  78.                     System.out.println("Your answer is correct!");
  79.                     score++;
  80.                  }
  81.                 else System.out.println("Your answer is wrong!, the correct answer is " + ans);
  82.                  }
  83.                  }
  84.             default -> System.out.println("Enter a valid input!");
  85.          }
  86.        
  87.           //continuation
  88.                 if (operator <= 4 && operator >=1) {
  89.                 System.out.println("\nYour total score is " + score + " out of " + item);
  90.                 double s = score;
  91.                 double it = item;
  92.                 double grade = s / it;
  93.                 if (grade==1)
  94.                     System.out.println("\nPerfect Score!");
  95.                 else if (grade >= 0.75 && grade < 1)
  96.                     System.out.println("\nExcellent!");
  97.                 else if (grade >= 0.5 && grade < 0.75)
  98.                     System.out.println("\nGood");
  99.                 else if (grade >= 0.25 && grade < 0.5)
  100.                     System.out.println("\nTry Again");
  101.                 else if (grade >= 0 && grade < 0.25) {
  102.                     System.out.println("\nBetter Luck Next Time");
  103.                 } else {
  104.                 }
  105.          }
  106.     }
  107. }
  108.  
Tags: Java
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement