By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,651 Members | 1,368 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,651 IT Pros & Developers. It's quick & easy.

need help with my code

P: 1
I am having hard time completing my java lottery program. i am trying to write two public function play()and score. Play supposed to prompt the user to input $1 in the machine. Score should calculate the number of picks that match the winning number. Please help me. here is my code that is what i got so far.

Expand|Select|Wrap|Line Numbers
  1. import  java.util.*;
  2.  
  3.  
  4. public class Lottery {
  5.  
  6. //private int[] winner;
  7.  
  8. //private int[] picks;
  9.  
  10. int play;
  11.  
  12. int score;
  13.  
  14. //winner =int [5];
  15.  
  16.  
  17.  
  18. public static void main(String[] args) {
  19.  
  20. //Random generator and scanner
  21.  
  22. Scanner sc = new Scanner(System.in);
  23.  
  24. Random generator = new Random();
  25.  
  26. System.out.println("Enter a number between 1-35.");
  27.  
  28. int ch =sc.nextInt();
  29.  
  30. int winner = (int) (Math.random() *35) + 1;
  31.  
  32. if(ch == 10)
  33.  
  34. System.out.println("Congrast, you have won!");
  35.  
  36. else
  37.  
  38. System.out.println("Sorry, you did not have the winning number\n."
  39.  
  40. +"The winning number is " + winner + ",");
  41.  
  42. //class play{
  43.  
  44. //int paly = 0;
  45.  
  46. for(int i = 1;i < 35; i++){
  47.  
  48. Scanner diceRoller = new Scanner(System.in);
  49.  
  50. int roll = diceRoller.nextInt(5)+1;
  51.  
  52. System.out.println(roll);
  53.  
  54. }
  55.  
  56.  
  57. }
  58.  
  59. }
Feb 19 '12 #1

✓ answered by r035198x

play and score are methods but you haven't defined them as such:

Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner;
  2.  
  3. public class Lottery {
  4.     public void play() {
  5.         //your code goes here
  6.     Scanner sc = new Scanner(System.in);
  7.     }
  8.  
  9.     public void score() {
  10.          //your code goes here
  11.  
  12.     }
  13.  
  14.     public static void main(String[] args) {
  15.     new Lottery().play();
  16.  
  17.     }
  18. }

Share this Question
Share on Google+
1 Reply


10K+
P: 13,264
play and score are methods but you haven't defined them as such:

Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner;
  2.  
  3. public class Lottery {
  4.     public void play() {
  5.         //your code goes here
  6.     Scanner sc = new Scanner(System.in);
  7.     }
  8.  
  9.     public void score() {
  10.          //your code goes here
  11.  
  12.     }
  13.  
  14.     public static void main(String[] args) {
  15.     new Lottery().play();
  16.  
  17.     }
  18. }
Feb 20 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.