Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package practice.programpractice;
- import java.util.*;
- public class switchQuiz {
- //Author Zunder Jacob A. Pacis
- // 1.2.2
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.println("How many items do you want to answer?");
- byte item = sc.nextByte();
- byte i;
- System.out.println("What math operation do you want to solve?\n1 - addition\t\t2 - subtraction\n3 - multiplication\t4 - division");
- byte operator = sc.nextByte();
- int score = 0;
- switch (operator) {
- case 1 -> {
- System.out.println("You have chosen Addition!\n");
- for (i = 0; i < item; i++) {
- int a = (int) (Math.random() * 11);
- int b = (int) (Math.random() * 11);
- int itemNo = i + 1;
- System.out.println(itemNo + ". What is " + a + " + " + b + "?");
- int ans = a+b;
- int input = sc.nextInt();
- if (input==a+b) {
- System.out.println("Your answer is correct!");
- score++;
- }
- else System.out.println("Your answer is wrong!, the correct answer is " + ans);
- }
- }
- case 2 -> {
- System.out.println("You have chosen Subtraction!\n");
- for (i = 0; i < item; i++) {
- int a = (int) (Math.random() * 11);
- int b = (int) (Math.random() * 11);
- int itemNo = i + 1;
- System.out.println(itemNo + ". What is " + a + " - " + b + "?");
- int ans = a-b;
- int input = sc.nextInt();
- if (input==a-b) {
- System.out.println("Your answer is correct!");
- score++;
- }
- else System.out.println("Your answer is wrong!, the correct answer is " + ans);
- }
- }
- case 3 -> {
- System.out.println("You have chosen Multiplication!\n");
- for (i = 0; i < item; i++) {
- int a = (int) (Math.random() * 11);
- int b = (int) (Math.random() * 11);
- int itemNo = i + 1;
- System.out.println(itemNo + ". What is " + a + " x " + b + "?");
- int ans = a*b;
- int input = sc.nextInt();
- if (input==a*b) {
- System.out.println("Your answer is correct!");
- score++;
- }
- else System.out.println("Your answer is wrong!, the correct answer is " + ans);
- }
- }
- case 4 -> {
- System.out.println("You have chosen Division!\n");
- for (i = 0; i < item; i++) {
- int a = (int) (Math.random() * 11);
- int b = (int) (Math.random() * 11);
- int itemNo = i + 1;
- float c = a;
- float d = b;
- System.out.println(itemNo + ". What is " + a + " ÷ " + b + "?");
- float ans = c/d;
- float input = sc.nextFloat();
- if (input==c/d) {
- System.out.println("Your answer is correct!");
- score++;
- }
- else System.out.println("Your answer is wrong!, the correct answer is " + ans);
- }
- }
- default -> System.out.println("Enter a valid input!");
- }
- //continuation
- if (operator <= 4 && operator >=1) {
- System.out.println("\nYour total score is " + score + " out of " + item);
- double s = score;
- double it = item;
- double grade = s / it;
- if (grade==1)
- System.out.println("\nPerfect Score!");
- else if (grade >= 0.75 && grade < 1)
- System.out.println("\nExcellent!");
- else if (grade >= 0.5 && grade < 0.75)
- System.out.println("\nGood");
- else if (grade >= 0.25 && grade < 0.5)
- System.out.println("\nTry Again");
- else if (grade >= 0 && grade < 0.25) {
- System.out.println("\nBetter Luck Next Time");
- } else {
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement