Hello everyone,
This is my first java class and I am trying to understand the terms and different types of programs. I finished my program as an application then did it as a gui without realizing it had to be in a applet. It feels like I just learned 2 different languages because the syntax was a little different between them. Now I am trying to figure how to convert this mess into a applet. I am going to mess around with it when I get home from work. Is there any advance help you guys could give to help me start this? I would be very grateful. This is the program that I did in my application and gui. How hard would it be to convert to applet?

import javax.swing.JOptionPane;
import java.util.*;
importstatic java.lang.Math.*;


publicclass program4
{
publicstaticvoid main( String[] args )
{


int number1 = 0;
int number2 = 0;
int actualAnswer = 0;


JOptionPane.showMessageDialog(null, "You will be given math problems to solve.");

number1 = (int)( Math.random () * 9 ); // first variable that will appear in math problem
number2 = (int)( Math.random () * 9 ); // second variable that will appear in math problem
actualAnswer = number1 * number2; // variable that holds true answer to random math problem


String userInput;
double userAnswer = 0.00;
String grade;
String output;
int correctAnswers = 0;
int incorrectAnswers = 0;


userInput = JOptionPane.showInputDialog (null, "Find Product: " + "\n" +
number1 + " Times " + number2);

userAnswer = Double.parseDouble( userInput );


if (userAnswer == actualAnswer) {
JOptionPane.showMessageDialog (null, "You are correct!");
correctAnswers = correctAnswers + 1; // counter to sum total correct answers
JOptionPane.showMessageDialog (null, " You received " + correctAnswers + " Correct answer");

} // if correct, then this is the outcome
else {
JOptionPane.showMessageDialog (null, "You are incorrect! Please try again. ");
incorrectAnswers = incorrectAnswers + 1; // counter to sum total incorrect answers

while (userAnswer != actualAnswer)
{

userInput = JOptionPane.showInputDialog (null, "Find Product: " + "\n" +
number1 + " Times " + number2);
userAnswer = Double.parseDouble( userInput );

if (userAnswer == actualAnswer) {
JOptionPane.showMessageDialog (null, "Great you were able to get the answer!!");
JOptionPane.showMessageDialog (null, " You received " + incorrectAnswers + " incorrect answer");
}

}

}

Recommended Answers

All 2 Replies

Member Avatar for iamthwee

1. try using code tags
2. find a book that shows u how to write an applet then experiment?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.