Computers are playing an increasing role in education. Implement a GUI program t
ID: 3693882 • Letter: C
Question
Computers are playing an increasing role in education. Implement a GUI program that helps first grade students to learn simple addition and subtraction Use Math.random() to produce two positive One-digit integers (numbers must be less than 10). It should then type a question such as: 5 + 3 = ? A card as shown in Fig 1 appears where the student is prompted to enter the answer. The program checks the student's answer. If it is correct, print an encouragement statement with a Star as shown in Fig 2. If the answer is wrong, print the correct answer with a sad face as shown in Fig 3. After 5 questions show the student his total grade. Fig. 1 shows a sample screen for asking a question Fig.2 shows a sample screen for a correct answer with the next question. 3 Fig 3. Sample of screen after incorrect answerExplanation / Answer
Solution: Please follow these coding as shown in below..
import javax.swing.JOptionPane;
public class Math {
public static void main( String args[] )
{
String firstNumber, secondNumber;
int number1, number2, sum,sub;
// read in first number from user as a string
firstNumber = JOptionPane.showInputDialog( "Enter first integer" );
// read in second number from user as a string
secondNumber = JOptionPane.showInputDialog( "Enter second integer" );
// convert numbers from type String to type int
number1 = Integer.parseInt( firstNumber );
number2 = Integer.parseInt( secondNumber );
sum = number1 + number2;
sub = number1 - number2;
// display the results
JOptionPane.showMessageDialog( null, "The sum is " + sum, "Results", JOptionPane.PLAIN_MESSAGE );
JOptionPane.showMessageDialog( null, "The sub is " + sub, "Results", JOptionPane.PLAIN_MESSAGE );
System.exit( 0 ); // terminate the program
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.