Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Help jelly beans guessing game
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
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

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

Posted: Mon Nov 29, 2010 7:20 pm   Post subject: RE:Help jelly beans guessing game

@conman14: What method?
Tony's programming blog. DWITE - a programming contest.
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.
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);
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 9 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: