View Single Post
Old Apr 12th, 2008, 10:45 PM   #5
kewlgeye
Programmer
 
Join Date: Jan 2008
Posts: 53
Rep Power: 1 kewlgeye is on a distinguished road
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?

java Syntax (Toggle Plain Text)
  1. import java.util.*;
  2. import javax.swing.JOptionPane;
  3.  
  4.  
  5. public class guessing
  6. {
  7. static Scanner console = new Scanner(System.in);
  8.  
  9. public static void main (String[] args)
  10. {
  11. //declare the variables
  12. int num; //variable to store the random number
  13. double guess; // variable to store the number guess by user
  14. boolean done;
  15. String input;
  16. String correct;
  17. String coroutput;
  18. String wrong;
  19. String yguess;
  20. int noOfGuesses = 0;
  21. String[] max = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"};
  22.  
  23. int rand = (int) (Math.random() * max)+1;
  24. num = (int) (Math.random() * 10);
  25. done = false;
  26.  
  27. while ((noOfGuesses < 3) && (!done))
  28. {
  29. yguess = JOptionPane.showInputDialog("Please enter a letter beween A-J or number between 1-10");
  30. guess = Double.parseDouble(yguess);
  31. noOfGuesses++;
  32. if (guess == num)
  33. {
  34. coroutput = "Congratulations you guessed it";
  35. JOptionPane.showMessageDialog(null, coroutput,
  36. "Congratulations", JOptionPane.INFORMATION_MESSAGE);
  37. done = true;
  38. }
  39. else
  40. if (guess < num)
  41. {
  42. JOptionPane.showMessageDialog(null, "You're too low!",
  43. "Failure", JOptionPane.INFORMATION_MESSAGE);
  44. }
  45. else
  46. if (guess > num)
  47. {
  48. JOptionPane.showMessageDialog(null, "You're too high!",
  49. "Failure", JOptionPane.INFORMATION_MESSAGE);
  50. }
  51.  
  52. if (noOfGuesses == 3)
  53. {
  54. JOptionPane.showMessageDialog(null, "You lose, Too many Tries, Correct number = " + num,
  55. "Failure", JOptionPane.INFORMATION_MESSAGE);
  56. }
  57.  
  58.  
  59. } //end while
  60. }
  61. }
kewlgeye is offline   Reply With Quote