need to write write a Java applet that will let the user guess the gas price and compare it with the price predicted by my program. Guess gas price (100 - 150): that never changes. so far i have this but stuck with method, generate a random number from 100 to 150, inclusive. Set it to predictPrice. so far i have this
import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JApplet; import javax.swing.JLabel; import javax.swing.JTextField; public class Assign7 extends JApplet implements ActionListener { int predictPrice; int guessPrice; JLabel questionLabel; JTextField answerField; public void init () { Container container = getContentPane(); container.setLayout( new FlowLayout() ); questionLabel = new JLabel(); container.add ( questionLabel); answerField = new JTextField ( 3 ); answerField.addActionListener ( this ); container.add (answerField ); predictPrice = generateQuestion(); } public void actionPerformed ( ActionEvent actionEvent ) { guessPrice = Integer.parseInt(answerField.getText()); displayMessage(); } public int generateQuestion() { int num1, num2; num1 = 1 + ( int ) (Math.random() * 100 ); num2 = 1 + ( int ) (Math.random() * 150 ); questionLabel.setText( "Guess oil price (100 - 150)" ); return num1 * num2; } public void displayMessage() { if ( guessPrice == predictPrice) { showStatus ( "You are right." ); predictPrice = generateQuestion(); } else { if (guessPrice >= predictPrice); { showStatus ( "Too low." ); predictPrice = generateQuestion(); } } } } { }