Help Creating a method for my jellyBean gussing game
I need help on creating a method for my project. What should I do?
Code Java:
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
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?
Re: Help Creating a method for my jellyBean gussing game
Quote:
Originally Posted by
CookiesForRandy
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.
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.
Code Java:
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");
}
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{}
Re: Help Creating a method for my jellyBean gussing game
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
Re: Help Creating a method for my jellyBean gussing game
Re: Help Creating a method for my jellyBean gussing game
k nvm i got it put an ; which was causing the error
Re: Help Creating a method for my jellyBean gussing game
So now, how to create a method who's the winner or winners
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
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