Generate and grade math quizzes. ( JAVAFX only , no awt or swing) Write an apple
ID: 3828452 • Letter: G
Question
Generate and grade math quizzes. (JAVAFX only, no awt or swing) Write an applet that allows the user to select a question type and difficulty level, as shown in the illustration. When the user clicks the Start button, the program begins to generate a question. After the user enters an answer with the Enter key, a new question is displayed. When the user clicks the Start button, the elapsed time is displayed. The time is updated every second until the Stop button is clicked. The correct count is updated whenever a correct answer is made. Exercise 18_26 Introduction to Java Programming, Comprehensive Version (9th Edition)
Explanation / Answer
import java.util.Scanner; import java.util.Random; class Machine { int num1, num2, ans, att; int score = 0; Random rand = new Random(); Scanner in = new Scanner(System.in); public void sumGenerator(){ num1 = rand.nextInt(10); num2 = rand.nextInt(10); ans = num1 + num2; System.out.println(num1 + " + " + num2 ); }//sumGenerator Method public void answerGetter_score(){ att = in.nextInt(); if(att == ans){ score = score + 1; System.out.println("Correct"); System.out.println("Score is currently: " + score + "/5"); }else{ score = score - 1; System.out.println("Incorrect"); System.out.println("Score is currently: " + score + "/5"); }//else }//answer Getter method }//machine class public class calcu { public static void main(String[] args) { Machine machine1 = new Machine(); System.out.println("***Welcome to addition Math test***"); for(int i=5; i>0; i--){ machine1.sumGenerator(); machine1.answerGetter_score(); } System.out.println("Thanks for taking the test."); }//main method
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.