Question

In: Computer Science

Create an application that can be used to practice adding,subtracting, multiplying, and dividing numbers. The...

Create an application that can be used to practice adding, subtracting, multiplying, and dividing numbers. The application should display a math problem on the screen and then allow the student to enter the answer and also verify that the answer is correct. The application should give the student as many chances as necessary to answer the problem correctly. The math problems should use random integers from 1 through 20, inclusive. The subtraction problems should never ask the student to subtract a larger number from a smaller one. The division problems should never ask the student to divide a smaller number by a larger number. Also, the answer to the division problems should always result in a whole number. The application should keep track of the number of correct and incorrect responses made by the student. The interface should include a button that allows the user to reset the counters for a different student.

Solutions

Expert Solution

//Code in java

import javafx.application.Application;
import java.util.*;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.stage.Stage;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.event.EventHandler;
import javafx.event.ActionEvent;
public class MyApplication extends Application{
   public void start(Stage stage) {
  
        Random R= new Random();
        GridPane root = new GridPane();
        int a,b;  
        Label a1=new Label("First Number ");
        Label a2 = new Label("Second Number ");
        Label a3 = new Label("Operation ");
        Label a4 = new Label("Enter Your answer ");
        Label a5 = new Label("Result after checking ");
        TextField tf1=new TextField();
        TextField tf2=new TextField();
        TextField tf3=new TextField();
        TextField tf4=new TextField();
        TextField tf5=new TextField();
        tf1.setEditable(false);
        tf2.setEditable(false);
            tf3.setEditable(false);
        tf5.setEditable(false);
            Button b1 = new Button("Check Result");  
        Button b2 = new Button("CLEAR");
        a = R.nextInt(20);
            b = R.nextInt(20);
            tf1.setText( Integer.toString(a));
            tf2.setText( Integer.toString(b));
            if(b > 0 && a%b == 0 ){
                 tf3.setText("Devision");
        }else if(a > b) {
                 tf3.setText("Subtraction");
        }else if(b%2 == 0){
                 tf3.setText("Addition");
        }else{
                 tf3.setText("Multiplication");
        }
            b1.setOnAction(e ->{
       String st = tf4.getText();
       String s = tf3.getText();
       int an,ans= Integer.parseInt(st);
                if(s.compareTo("Devision") == 0){
           an=a/b;
       }else if(s.compareTo("Subtraction") == 0 ){
           an = a-b;
       }else if(s.compareTo("Addition")==0){
           an = a+b;
       }else
           an = a*b;
       if(an == ans ){
           tf5.setText("Right answer ");
       }else
           tf5.setText("Wrong answer Correct answer is "+an);
            });
        root.addRow(0, a1, tf1);
        root.addRow(1, a2, tf2);
        root.addRow(2, a3,tf3);
        root.addRow(3, a4,tf4);
        root.addRow(5, b1 ,b2);
        root.addRow(6, a5,tf5);
        b2.setOnAction(new EventHandler() {
            public void handle(ActionEvent event) {
                tf1.clear();
                tf2.clear();
                tf3.clear();
                tf4.clear();
            }
            });
     
        Scene scene=new Scene(root,350,200);
            stage.setScene(scene);
        stage.setTitle("Text Field Example");
            stage.show();
   }
}

//Screenshot of output terminal


Related Solutions

In Verilog, implement a circuit capable of adding and subtracting 8-bit binary numbers. You should submit...
In Verilog, implement a circuit capable of adding and subtracting 8-bit binary numbers. You should submit a single Verilog file that contains all of the necessary modules and also contain a module named top(A, B, sel, F, C). For the selection, use a 0 to select Addition and a 1 to select Subtraction.
Create a Windows application in C# that can be used to change the form color. Your...
Create a Windows application in C# that can be used to change the form color. Your form background color should initially be blue. Provide at least two buttons with two different color choices and a Reset option. Change the font style and size on buttons. Align the buttons so that they are in the center of the form. The color choice buttons should be the same size. Add event handlers for the buttons so that when the user click the...
Create a mobile application using Android studio, for cinema tickets reservation. The application will be used...
Create a mobile application using Android studio, for cinema tickets reservation. The application will be used by the customers to book cinema tickets. Only users of 15 years old and above are allowed to book cinema tickets for a particular film. The user can book more than one ticket where ticket prices vary between 20 and 50 AED. Your app contains tree Activities. The first activity is a launching activity containing a logo and a button start. When the user...
Create a Java application NumberLoops to practice loops. The draft has one loop to calculate a...
Create a Java application NumberLoops to practice loops. The draft has one loop to calculate a product and the final will add another loop to print integers in a required format. There is no starter code for the problem. Use a Scanner to input an integer then compute and display the product of all positive integers that are less than the input number and multiple of 3. If no numbers satisfy the conditions, then print out 1 for the product....
C# Create a console application that asks the user for two numbers in the range 0-255...
C# Create a console application that asks the user for two numbers in the range 0-255 and then divides the first number by the second: Enter a number between 0 and 255: 100 Enter another number between 0 and 255: 8 100 divided by 8 is 12 Enter a number between 0 and 255: apples Enter another number between 0 and 255: bananas FormatException: Input string was not in a correct format.
****java*** Create an application that generates 20 random numbers between 1 and 100 and writes them...
****java*** Create an application that generates 20 random numbers between 1 and 100 and writes them to a text file on separate lines. Then the program should read the numbers from the file, calculate the average of the numbers, and display this to the screen.
Create a java application that can solve the following differential equation and boundary condition with the...
Create a java application that can solve the following differential equation and boundary condition with the Runge Kutta method and the secant method. x' = f(t,x) = x + 0.09x2 + cos(10*t) differential equation x(0) + x(1) - 3.0 = 0            boundary condition Starting with the initial guesses 0.7 and 1.0 for the (unknown) initial value, x(0), obtain an approximation to x(0) {for the final solution, x(t)} such that the boundary condition is satisfied to within a tolerance of 10-4 ....
Which of the following is correct about the application of duration? a. Duration can be used...
Which of the following is correct about the application of duration? a. Duration can be used to provide an exact price impact from changes in interest rates. b. Yield curve risk does not impact duration. c. Effective duration is another name for modified duration. d. None of the above.
Create a JAVA lottery game application.  Generate four random numbers, each between 0 and 9 (inclusive).  Allow the...
Create a JAVA lottery game application.  Generate four random numbers, each between 0 and 9 (inclusive).  Allow the user to guess four numbers.  Compare each of the user’s guesses to the four random numbers and display a message that includes the user’s guess, the randomly determined four-digit number, and the amount of points the user has won as follows: No matches 0 points Any one digit matching 5 points Any two digits matching 100 points Any three digits matching 2,000 points All four...
Create a Java application that creates a window in which multiple bouncing balls can be animated....
Create a Java application that creates a window in which multiple bouncing balls can be animated. have attached a text file of the source found on that site. You can paste the entire application into an Eclipse source file named BounceThread.java and it will compile and run. Optionally, you may prefer to put some or all of the classes into separate files to organize your work. Your task is to add the following capability to the application: (5%)    Increase the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT