Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 12 of 12

Thread: Help Creating a method for my jellyBean gussing game

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help Creating a method for my jellyBean gussing game

    I need help on creating a method for my project. What should I do?

    import java.util.*;
     
    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 playerNum = input.nextInt();
     
    		// Create two variables
    		String[] playerName = new String[playerNum];
    		int[] playerGuess = new int [playerNum];
     
    		int jeallyBeans =(int)(Math.random()*(1999-1001+1) + 1001);
     
    		for (int i =0; i < playerNum; i++)
    		{
    			// input buffer
    			input.nextLine();
     
    			// Inputting users name
    			System.out.print("Please enter name #: " + (i+1) + ": ");
    			playerName[i] = input.nextLine();
     
    			do 
    			{
    				// Enter guess
    				System.out.print(playerName[i] + ", Enter your guess between 1000 and 2000: ");
    				playerGuess[i] = input.nextInt();
     
    			} while (playerGuess[i] <= 1000 || playerGuess[i] >=2000);	
    		}
     
    	// calculation	
    	int awayFromTheNumber = playerGuess.length- jeallyBeans; 
     
    	// The result
    	System.out.println("There were " + jeallyBeans + " jelly beans in the jar");	
    	for (int i = 0; i < playerGuess.length; i++)
    	{
    		if (playerGuess.length == jeallyBeans);
    		{
    			System.out.println("\nThe winner is " + playerName[i] + "with a guess of " + playerGuess[i] + ", which is exactly the same as the number of jelly beans in the jar.");
    			System.out.println("\nYou were " +  + awayFromTheNumber + " of " + jeallyBeans + "jellyBeans");
    		}
     
    		else (playerGuess.length > jeallyBeans || playerGuess.length < jeallyBeans);
    		{
    			System.out.println("\n The Winners is + " + playerName[i] + "with a guess of " + playerGuess[i] + " you were away from " + awayFromTheNumber + " jelly beans");
    		} 
     
    	} // end for
     
     
    	} // end main
     
    } // end class
    Last edited by CookiesForRandy; November 19th, 2010 at 12:49 PM. Reason: i miss an else statement and i need help to fix


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: Help Creating a method for my jellyBean gussing game

    Hello and welcome to the forums

    Can you please give us some more information. What does the method need to do?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  3. #3
    Member DavidFongs's Avatar
    Join Date
    Oct 2010
    Location
    Minneapolis, MN
    Posts
    107
    Thanks
    1
    Thanked 45 Times in 41 Posts

    Default Re: Help Creating a method for my jellyBean gussing game

    Quote Originally Posted by CookiesForRandy View Post
    I need help on creating a method for my project. What should I do?
    You should either give us more information, or create the method.

  4. #4
    Junior Member
    Join Date
    Nov 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help Creating a method for my jellyBean gussing game

    i need help creating a method for who's the winner or winners but i add an else statement but i get an error on it. Im hoping you guys can help me fix it.

    else (playerGuess.length > jeallyBeans || playerGuess.length < jeallyBeans);
    		{
    			System.out.println("\n The Winners is + " + playerName[i] + "with a guess of " + playerGuess[i] + " you were away from " + awayFromTheNumber + " jelly beans");
    		}

  5. #5
    Member DavidFongs's Avatar
    Join Date
    Oct 2010
    Location
    Minneapolis, MN
    Posts
    107
    Thanks
    1
    Thanked 45 Times in 41 Posts

    Default Re: Help Creating a method for my jellyBean gussing game

    That's because else doesn't take a conditional statement.

    You want to use else if, or just else{}

  6. #6
    Junior Member
    Join Date
    Nov 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help Creating a method for my jellyBean gussing game

    what do you mean?

  7. #7
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,371
    Thanks
    183
    Thanked 836 Times in 779 Posts
    Blog Entries
    5

    Default Re: Help Creating a method for my jellyBean gussing game

    See the following link for the proper syntax using if-then or if-then-else Java Control Statements

  8. #8
    Junior Member
    Join Date
    Nov 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help Creating a method for my jellyBean gussing game

    I don't know, lm stuck

  9. #9
    Junior Member
    Join Date
    Nov 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help Creating a method for my jellyBean gussing game

    k nvm i got it put an ; which was causing the error

  10. #10
    Junior Member
    Join Date
    Nov 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help Creating a method for my jellyBean gussing game

    So now, how to create a method who's the winner or winners

  11. #11
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    495
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Help Creating a method for my jellyBean gussing game

    Go through the tutorial link posted. Or give up -- it's your choice.

    Just don't expect someone here to do your homework for you.

    db

  12. #12
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    495
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Help Creating a method for my jellyBean gussing game

    This thread has been cross posted here:

    http://compsci.ca/v3/viewtopic.php?p=223555

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting

    db


Similar Threads

  1. Creating a scaleUp main method in a new class
    By Brainz in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 16th, 2010, 08:58 AM
  2. Can i call init() method in destroy method.?
    By muralidhar in forum Java Servlet
    Replies: 1
    Last Post: October 22nd, 2010, 12:18 PM
  3. Replies: 8
    Last Post: December 9th, 2009, 04:45 PM
  4. Creating new instance
    By vluong in forum Object Oriented Programming
    Replies: 2
    Last Post: November 28th, 2009, 11:35 PM
  5. creating a gui
    By rsala004 in forum AWT / Java Swing
    Replies: 2
    Last Post: July 21st, 2009, 03:17 AM