Doing a Lottery program (or trying 2) [Need help!!]

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ImortalSorrow
    New Member
    • Feb 2008
    • 13

    Doing a Lottery program (or trying 2) [Need help!!]

    Hey, I'm quite new in programing so need some help with this lottery program I'm making. What I'm trying to do is very simple, simulate a lottery but my effords are in vain since when I'm compiling it, it says that there are 100 errors ... -.- The code is right here:

    class lottery {

    public static void main (Strings [] args){

    int ball1;
    int ball2;
    int ball3;
    int ball4;
    int ball5;
    int star1;
    int star2;

    ball1 <= 50 && ball1 > 0;
    ball2 <= 50 && ball2 > 0;
    ball3 <= 50 && ball3 > 0;
    ball4 <= 50 && ball4 > 0;
    ball5 <= 50 && ball5 > 0;
    star1 <= 50 && star1 > 0;
    star2 <= 50 && star2 > 0;

    System.out.prin tln("The Lottery has Begun!!");
    System.out.prin tln("And The Numbers are:");
    System.out.prin tln(ball1 + "for the number one");
    System.out.prin tln(ball2 + "for the number two");
    System.out.prin tln(ball3 + "for the number three");
    System.out.prin tln(ball4 + "for the number four");
    System.out.prin tln(ball5 + "for the number five");
    System.out.prin tln("Now The Stars Are:");
    System.out.prin tln(star1 + "for the star number one");
    System.out.prin tln(star2 + "for the star number two");
    }
    }


    Hope you can answer and help me with this!
    Thanks a lot, ImortalSorrow
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    This lines is not a Java statement:

    [CODE=Java]ball1 <= 50 && ball1 > 0;[/CODE]

    What were you trying to do? What where you trying to express?

    Comment

    • ImortalSorrow
      New Member
      • Feb 2008
      • 13

      #3
      I'm trying to simulate a lottery, like some random number between 1 and 50 for five balls and between 1 and 9 for other two. just like euromilions.

      Comment

      • Laharl
        Recognized Expert Contributor
        • Sep 2007
        • 849

        #4
        Those statements involving ranges for the ball's value have no meaning. To generate random numbers, use the Math.random() function (or the Random class). Math.random() returns a decimal between 0 and 1, so then you multiply by the range you want and cast to int.

        [CODE=java]
        int a = (int)(Math.rand om()*r) //Add 1 if you want to avoid getting 0
        [/CODE]

        Comment

        • BigDaddyLH
          Recognized Expert Top Contributor
          • Dec 2007
          • 1216

          #5
          Originally posted by Laharl
          Those statements involving ranges for the ball's value have no meaning. To generate random numbers, use the Math.random() function (or the Random class). Math.random() returns a decimal between 0 and 1, so then you multiply by the range you want and cast to int.

          [CODE=java]
          int a = (int)(Math.rand om()*r) //Add 1 if you want to avoid getting 0
          [/CODE]
          Class java.util.Rando m is a little easier and clearer to use -- less arithmetic: http://java.sun.com/javase/6/docs/ap...il/Random.html

          Comment

          • ImortalSorrow
            New Member
            • Feb 2008
            • 13

            #6
            ohh ok thanks, so in this case i do:

            Code:
             ball1 = (Math.random()1*50)
            ?

            srry about all these questions =P

            Comment

            • BigDaddyLH
              Recognized Expert Top Contributor
              • Dec 2007
              • 1216

              #7
              Originally posted by ImortalSorrow
              ohh ok thanks, so in this case i do:

              Code:
               ball1 = (Math.random()1*50)
              ?

              srry about all these questions =P
              What I suggest you do is write a tiny program just to learn how to generate random numbers. When you've learned how, apply that knowledge to your assignment. That's a strategy you should apply widely.

              Comment

              • ImortalSorrow
                New Member
                • Feb 2008
                • 13

                #8
                yes i guess you'r right

                thank you very much for your time and help!

                Comment

                • BigDaddyLH
                  Recognized Expert Top Contributor
                  • Dec 2007
                  • 1216

                  #9
                  Good luck on your program!!

                  Comment

                  Working...