Author |
Message |
asianrandy
|
Posted: Wed Nov 17, 2010 5:02 pm Post subject: 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
|
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
|
|
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
asianrandy
|
Posted: Thu Nov 18, 2010 7:35 pm Post subject: RE:Help jelly beans guessing game |
|
|
NVM i got it |
|
|
|
|
 |
conman14
|
Posted: Thu Nov 25, 2010 9:08 pm Post subject: Re: Help jelly beans guessing game |
|
|
could you show me your final code? |
|
|
|
|
 |
SS1389
|
Posted: Thu Nov 25, 2010 10:15 pm Post subject: 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
|
Posted: Mon Nov 29, 2010 6:55 pm Post subject: Re: Help jelly beans guessing game |
|
|
im stuck with calling a method could anyone help? |
|
|
|
|
 |
Tony

|
|
|
|
 |
SS1389
|
Posted: Tue Dec 14, 2010 8:56 pm Post subject: Re: Help jelly beans guessing game |
|
|
[access_level] [static] [return type] identifier ([formal parameters]) |
|
|
|
|
 |
TheGuardian001
|
Posted: Tue Dec 14, 2010 9:12 pm Post subject: Re: Help jelly beans guessing game |
|
|
SS1389 @ Tue Dec 14, 2010 8:56 pm wrote: [access_level] [static] [return type] identifier ([formal parameters])
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. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
SS1389
|
Posted: Tue Dec 14, 2010 9:21 pm Post subject: 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); |
|
|
|
|
 |
|