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

Threaded View

  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


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, 11:18 AM
  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, 02:17 AM