need help with my code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NOno al
    New Member
    • Feb 2012
    • 1

    need help with my code

    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.

    Code:
    import  java.util.*;
    
    
    public class Lottery {
    
    //private int[] winner;
    
    //private int[] picks;
    
    int play;
    
    int score;
    
    //winner =int [5];
    
    
    
    public static void main(String[] args) {
    
    //Random generator and scanner
    
    Scanner sc = new Scanner(System.in);
    
    Random generator = new Random();
    
    System.out.println("Enter a number between 1-35.");
    
    int ch =sc.nextInt();
    
    int winner = (int) (Math.random() *35) + 1;
    
    if(ch == 10)
    
    System.out.println("Congrast, you have won!");
    
    else
    
    System.out.println("Sorry, you did not have the winning number\n."
    
    +"The winning number is " + winner + ",");
    
    //class play{
    
    //int paly = 0;
    
    for(int i = 1;i < 35; i++){
    
    Scanner diceRoller = new Scanner(System.in);
    
    int roll = diceRoller.nextInt(5)+1;
    
    System.out.println(roll);
    
    }
    
    
    }
    
    }
    Last edited by Rabbit; Feb 20 '12, 05:41 AM. Reason: Please use code tags when posting code.
  • r035198x
    MVP
    • Sep 2006
    • 13225

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

    [CODE=java]import java.util.Scann er;

    public class Lottery {
    public void play() {
    //your code goes here
    Scanner sc = new Scanner(System. in);
    }

    public void score() {
    //your code goes here

    }

    public static void main(String[] args) {
    new Lottery().play( );

    }
    }[/CODE]

    Comment

    Working...