Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2014
    Posts
    11
    Rep Power
    0

    Default May someone please help me out and give me a hint?

    Okay I desperately need a hint with this. When I run all of the code in this how do I keep the writeOutput() from being "0 0 0 0 0 " with the pick[] array? I thought I changed the values but, I have no clue what I am doing wrong. I tried to return values back but, I kept getting errors and it wouldn't compile. May someone please give me a hint as to which method I need to fix the most? I have included both classes so you can see all the programming I have done. This thing is bringing me to frustration tears.


    Java Code:
    import java.util.Scanner;
    
    public class PowerballTest
    {
    	Scanner input = new Scanner(System.in);
    	
    	public static void main(String[] args)
    	{
    		Powerball.readInput();
    		Powerball.writeOutput();
    	}
    
    	
    }
    Java Code:
    import java.util.Scanner;
    
    public class Powerball {
    
    	static Scanner input = new Scanner(System.in);
    	static int pick[] = new int[5];
    
    	public static void readInput() {
    
    		String[] place = { "first", "second", "third", "fourth", "fifth" };
    		int number = 0;
    		boolean noDupes = false;
    		int powerball = 0;
    
    		for (int size = 0; size < 5; ++size) {
    			while (noDupes = true) {
    
    				System.out
    						.println("Enter the "
    								+ place[size]
    								+ " Powerball number which should be greater than 0 and less than 60");
    				number = input.nextInt();
    
    				if (number > 0 && number <= 59) {
    					checkNumber();
    					number = pick[size];
    					break;
    				} else {
    					System.out
    							.println("Numbers cannot be less than 1 or greater than 59.");
    				}
    
    			}
    
    		}
    		while (noDupes = true) {
    			System.out
    					.println("Enter the Powerball number that is greater than 0 or lesser than 36");
    			number = input.nextInt();
    
    			if (number > 0 && number <= 36) {
    				number = powerball;
    				break;
    			} else {
    				System.out
    						.println("Numbers cannot be less than 1 or greater than 35.");
    			}
    		}
    	}
    
    	public static void writeOutput() {
    		System.out
    				.println("The numbers you have chosen for your Powerball Ticket are "
    						+ pick[0]
    						+ " "
    						+ pick[1]
    						+ " "
    						+ pick[2]
    						+ " "
    						+ pick[3] + " " + pick[4]);
    	}
    
    	public static void checkNumber() {
    		/*
    		 * left blank intentionally to save space in reading on this forum thread.
    		 */
    	}
    
    }

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,716
    Rep Power
    17

    Default Re: May someone please help me out and give me a hint?

    How do I keep the writeOutput() from being "0 0 0 0 0 " with the pick[] array?
    Where - which line of your code - do you assign a nonzero values to any of the array elements?

  3. #3
    Join Date
    Dec 2014
    Posts
    11
    Rep Power
    0

    Default Re: May someone please help me out and give me a hint?

    Yes i do. when i run the code it is supposed to have number = pick[size]. so when i enter, for example, the numbers 1, 2, 4, 5, and 6 it is supposed to retain those values in the pick[] array. but it isnt being called correctly i believe. so I am really confused as to why this isn't working.

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,716
    Rep Power
    17

    Default Re: May someone please help me out and give me a hint?

    Remember that when you say

    Java Code:
    foo = bar;
    the value of the expression bar is assigned to foo, not the other way around. In the line of code you referred to it is the variable number that is assigned a value, not pick[size]. (In fact it is assigned the value zero because that is the value that pick[size] has).

  5. #5
    Join Date
    Dec 2014
    Posts
    11
    Rep Power
    0

    Default Re: May someone please help me out and give me a hint?

    omg...... how did I miss that? i feel dumb. But also thank you very much. I want to hug you. I can get the complex stuff but, i forget all the really simple stuff. Go figure. haha. Agains *hugs* you are great.

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,716
    Rep Power
    17

    Default Re: May someone please help me out and give me a hint?

    You're welcome. Array expressions like foo[i] are a little odd in that they can go on the left hand side where we would normally expect to see a variable. Happy coding!

Similar Threads

  1. NetBeans 7.2 RC1 adding a custom hint
    By DarVar in forum NetBeans
    Replies: 1
    Last Post: 07-05-2012, 05:20 PM
  2. Gridbaglayout, hint on label alignment...
    By Marcoita_88 in forum AWT / Swing
    Replies: 1
    Last Post: 08-09-2011, 09:53 PM
  3. Methods - give hint
    By iWonder in forum New To Java
    Replies: 25
    Last Post: 01-07-2009, 03:34 PM
  4. code hint scroll bar ?
    By tryit in forum Eclipse
    Replies: 3
    Last Post: 04-28-2008, 08:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •