
-----------------------------------
asianrandy
Wed Nov 17, 2010 5:02 pm

Help jelly beans guessing game
-----------------------------------
i need help with jelly beans gussing game.

1. Asking the user to enter how many people will be making guesses today. Use this number to
size your arrays.
2. Create an array of type String to hold the players? names, and create an array of type int to
hold the value of their guess.

[code] import java.util.Scanner;

public class JellyBeans
{
	public static void main(String[] args)
	{
		// Create a Scanner
		Scanner input = new Scanner(System.in);
		
		// Display a title
		System.out.println("------------------");
		System.out.println("-- Jelly Breans --");
		System.out.println("------------------");
		
		// how many people are playing
		System.out.print("How many players will be making guesses today? ");
		int howManyPeople = input.nextInt();
		
		// Inputting users name
		System.out.print("Please enter name #: ");
		String firstName = input.nextLine();
		
		// Enter guess
		System.out.print(firstName + ", Enter your guess between 0 and 2000: ");
		int guess = input.nextInt();
		
		// Calculation
		int jeallyBeans = (int)(Math.random() * 2000);
		System.out.println("There were " + jeallyBeans + " jelly beans in the jar");
		
		int awayFromTheNumber = guess - jeallyBeans; 
		
		if ( guess == jeallyBeans)
		{
			System.out.println("TheThe winner is" + firstName + "with a guess of " + jeallyBeans 
                          + ", which is exactly the same as the number of jelly beans in the jar.");
		}
		else 
		{
			System.out.println("The Winners are : ");
			System.out.println(firstName + " with a guess of " + guess + " which is " + awayFromTheNumber 
                         + " away from the actual number of jelly beans"); 
		}
		

	} // end main
	
} // end class
[/code]




k i edit my code but firstName can't be a variable and lm stuck help 
[code] import java.util.Scanner;

public class JellyBeans
{
	public static void main(String[] args)
	{
		// Create a Scanner
		Scanner input = new Scanner(System.in);
		
		// Display a title
		System.out.println("------------------");
		System.out.println("-- Jelly Breans --");
		System.out.println("------------------");
		
		// how many people are playing
		
			System.out.print("How many players will be making guesses today? ");
			int howManyPeople = input.nextInt();
			
		int[] guess = new int [howManyPeople];
	for (int i = 0; i < guess.length; i++)
	{
		// Inputting users name
		System.out.print("Please enter name #: ");
		String firstName = input.nextLine();
	   
		input.nextLine();
	
		// Enter guess
		System.out.print(firstName + ", Enter your guess between 0 and 2000: ");
		guess[i] = input.nextInt();
	}
	
	// Calculation
	int jeallyBeans = (int)(Math.random() * 2000);
	System.out.println("There were " + jeallyBeans + " jelly beans in the jar");
	
	int awayFromTheNumber = guess.length - jeallyBeans; 
	
	for (int i = 0; i < guess.length; i ++)
	{
		if (guess.length == jeallyBeans);
		{
			System.out.println("TheThe winner is" + firstName + "with a guess of " + jeallyBeans + ", which is exactly the same as the number of jelly beans in the jar.");
		}
		else
		{
			System.out.println("The Winners are : ");
			System.out.println(firstName + " with a guess of " + guess + " which is " + awayFromTheNumber + " away from the actual number of jelly beans"); 
		}
	}
	

	} // end main
	
} // end class
[/code]

-----------------------------------
asianrandy
Thu Nov 18, 2010 7:35 pm

RE:Help jelly beans guessing game
-----------------------------------
NVM i got it

-----------------------------------
conman14
Thu Nov 25, 2010 9:08 pm

Re: Help jelly beans guessing game
-----------------------------------
could you show me your final code?

-----------------------------------
SS1389
Thu Nov 25, 2010 10:15 pm

Re: Help jelly beans guessing game
-----------------------------------
For the holder array, you can work with it like this:

final int SIZE = 0;
int[] holder;

Scanner sc = new Scanner(System.in);

System.out.print("Enter the number of players: ");
SIZE = sc.nextInt();

holder = new int[SIZE]; 


Hope that helps!

-----------------------------------
conman14
Mon Nov 29, 2010 6:55 pm

Re: Help jelly beans guessing game
-----------------------------------
im stuck with calling a method could anyone help?

-----------------------------------
Tony
Mon Nov 29, 2010 7:20 pm

RE:Help jelly beans guessing game
-----------------------------------
@conman14: What method?

-----------------------------------
SS1389
Tue Dec 14, 2010 8:56 pm

Re: Help jelly beans guessing game
-----------------------------------
[access_level] [static] [return type] identifier ([formal parameters])

-----------------------------------
TheGuardian001
Tue Dec 14, 2010 9:12 pm

Re: Help jelly beans guessing game
-----------------------------------

That's how to define a method, not how to call one.
It's also a pretty useless post, as you simply posted a definition template without any kind of explanation.

-----------------------------------
SS1389
Tue Dec 14, 2010 9:21 pm

Re: Help jelly beans guessing game
-----------------------------------
Oops. Excuse my hurriedness. To call a method, simply call the identifier. 

i.e. If I wanted to call my formula method, I would use

formula (formal parameters); 


i.e. public static int formula(int x, int y)


call:  formula(x, y);
