|
Programmer
Join Date: Jan 2008
Posts: 53
Rep Power: 1 
|
Re: Random "Letter" Generator
I have been working more on this, and here is the code I have now. But I am receiving this error.
"operator * cannot be applied to double.java.lang.String[]"
I can't figure it out, does any one know how I can fix this?
import java.util.*; import javax.swing.JOptionPane; public class guessing { static Scanner console = new Scanner(System.in); public static void main (String[] args) { //declare the variables int num; //variable to store the random number double guess; // variable to store the number guess by user boolean done; String input; String correct; String coroutput; String wrong; String yguess; int noOfGuesses = 0; String[] max = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"}; int rand = (int) (Math.random() * max)+1; num = (int) (Math.random() * 10); done = false; while ((noOfGuesses < 3) && (!done)) { yguess = JOptionPane.showInputDialog("Please enter a letter beween A-J or number between 1-10"); guess = Double.parseDouble(yguess); noOfGuesses++; if (guess == num) { coroutput = "Congratulations you guessed it"; JOptionPane.showMessageDialog(null, coroutput, "Congratulations", JOptionPane.INFORMATION_MESSAGE); done = true; } else if (guess < num) { JOptionPane.showMessageDialog(null, "You're too low!", "Failure", JOptionPane.INFORMATION_MESSAGE); } else if (guess > num) { JOptionPane.showMessageDialog(null, "You're too high!", "Failure", JOptionPane.INFORMATION_MESSAGE); } if (noOfGuesses == 3) { JOptionPane.showMessageDialog(null, "You lose, Too many Tries, Correct number = " + num, "Failure", JOptionPane.INFORMATION_MESSAGE); } } //end while } }
|