Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: powerball

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default powerball

    This program will allow you to select Powerball numbers. For the first 5 numbers you
    will be requested to enter a number that is greater than zero and less than or equal
    to 59. However, there’s a catch! Each number must be different.

    When any of the first five numbers is less than 0 or greater or equal to 59 the user will receive a message to this effect and will be asked to re-enter the number. You will create a code that will display one message when a number less than 1 is entered and a different message if a number greater than 59 is entered.

    If the number is the same as any number entered before it (with the exception of the powerball number) the user will receive a message to the effect asking to re-enter the number. This is the same for the 2nd through 5th numbers

    When entering the powerball number, if the number entered IS NOT between 0
    and 39 then the user will receive a message to this effect and asked to reenter the
    number. One message will display if the number is less than 1, and a different if
    the number is greater than 39.

    The following MUST be included in the program:
    • You must have multiple classes. One that contains the accessor and mutator
    methods, a readInput() method and a writeOutput() method. You will not
    use the mutator methods but include them anyway to show that you know
    how to write them. Name this first program “Powerball.java”.
    • The second program is to be named “PowerballTest.java” and will be
    responsible for creating a Powerball object and calling the writeOutput() and
    readInput() methods from the Powerball class.
    Submit both the following programs in zip format. You will not be asked to
    resubmit if you forget to include one of the files in your submission. Points will
    simply be deducted accordingly.

    Powerball.java
    Powerball.class
    PowerballTest.java
    PowerballTest.class

    Im lost on this.

    Here is what I have so far:

    public class PowerBallTrial
    {

    private int[] numbers;
    private int size;
    private int range;
    private int rangePowerBall;
    private int powerBall;


    PowerBallTrial()
    {
    size = 5;
    range = 59;
    rangePowerBall = 35;
    number = new int[size];
    selectNumbers();
    PowerBallNumber();
    }
    public int getIndividualNumber(int number)
    {
    return number;
    }


    public int getPowerBallNumber()
    {
    return powerBall;
    }


    public String getAllNumbers()
    {
    String listOfNumbers="";
    for(int count=0; count<size; count++)
    {
    listOfNumbers += numbers[count] + " ";
    }
    listOfNumbers += " Powerball is " + getPowerBallNumber();
    return listOfNumbers;
    }
    public void resetAllNumbers()
    {
    selectNumbers();
    setPowerBallNumber();
    }
    public void readInput()
    {
    Scanner keyboard =new Scanner(System.in);

    for(int size=0;size<5;++size)
    {
    System.out.println("Enter Powerball " + number + 1 + " which should be > 0 and less than 60");
    number= keyboard.nextLine();

    if(numbers > 0)
    {
    number = newNumbers;
    else
    {
    System.out.println("Numbers cannot be less than 0.");
    }
    if(numbers < 59)
    {
    number = newNumbers;
    }
    else
    {
    System.out.println("Numbers must be less than 60");
    }
    if(number = newNumber)
    {
    System.out.println("Numbers cannot be the same as previous numbers");
    }
    }
    if(PowerBallNumber > 0)
    {
    powerBall = newPowerBall;

    else
    {
    System.out.println("Powerball cannot be less than 0.");
    }
    if(numbers < 35)
    {
    powerBall = newPowerBall;
    }
    else
    {
    System.out.println("Numbers must be less than 35");
    }
    }
    }
    public void writeOutput()
    {


    }
    }
    private void sortNumbers()
    {
    int first, second, temp;
    for(first = 0; first<number.length; first++)
    for(second = first+1; second<number.length; second++)
    {
    if(numbers[first]>number[second])
    {
    temp = numbers[first];
    number[first] = number[second];
    number[second] = temp;
    }
    }
    }
    }
    How can I apply this to the second class with main arg


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,619
    Thanks
    45
    Thanked 1,958 Times in 1,932 Posts

    Default Re: powerball

    How can I apply this to the second class with main arg
    Can you explain?
    What does "apply" mean?
    What is the second class?
    What is the main arg?

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: powerball

    basically it has to be public class powerball on one and the other has to be public class powerballtest.
    i have to use read/write input output that works in both. The description is above code.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,619
    Thanks
    45
    Thanked 1,958 Times in 1,932 Posts

    Default Re: powerball

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.


    What problems are you having with the code you have written?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: powerball

    I did wrap my code but it still is not showing, dont know what im doing wrong. I need the program to lopp 5 times for the different powerball numbers. it has to be greater than 0 but less than 60. The numbers cannot be the same, which shoud display error, cannot be less than 0 or greater than 60, which should display error. I have to enter five numbers seperately. So it cant randomly generate a number. Im sure I messed the loop up, thats were my error is coming at. Then on my powerball test i have to have the main arg which will be the file I compile and run to display the program.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,619
    Thanks
    45
    Thanked 1,958 Times in 1,932 Posts

    Default Re: powerball

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.


    Work on the list of things you need done one at a time. Code them, compile it, fix any errors and then test to see if it does what you want.
    The first item in the list was:
    I need the program to lopp 5 times
    When that works, move on to:
    different powerball numbers. it has to be greater than 0 but less than 60
    etc
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    489
    Thanks
    8
    Thanked 45 Times in 43 Posts

    Default Re: powerball

    This thread has been cross posted here:

    http://www.java-forums.org/new-java/65927-help-powerball-assignment.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting

    db