Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help jelly beans guessing game
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
asianrandy




PostPosted: 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
Sponsor
sponsor
asianrandy




PostPosted: Thu Nov 18, 2010 7:35 pm   Post subject: RE:Help jelly beans guessing game

NVM i got it
conman14




PostPosted: Thu Nov 25, 2010 9:08 pm   Post subject: Re: Help jelly beans guessing game

could you show me your final code?
SS1389




PostPosted: 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




PostPosted: 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




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

@conman14: What method?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
SS1389




PostPosted: Tue Dec 14, 2010 8:56 pm   Post subject: Re: Help jelly beans guessing game

[access_level] [static] [return type] identifier ([formal parameters])
TheGuardian001




PostPosted: 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
Sponsor
sponsor
SS1389




PostPosted: 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:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: