I just made this really quick cuz I was bored...... Its rly crap, but I was rushing... Might make it better later...
player class:
I hope you like!!!!!
Code:
import java.util.*;
public class GuessingGame
{
private static int players;
private static int computers;
private static LinkedList<Player> users = new LinkedList<Player>();
public static void main(String[] args)
{
new GuessingGame();
}
public GuessingGame()
{
System.out.println("Welcome to JVT's Guessing Game!");
players = getInt("Number of players: ");
if (players > 10)
{
players = 10;
System.out
.println("Maximum number of players is 10. Players set to 10.");
}
computers = getInt("Number of computers: ");
if (computers >= players)
{
System.out
.println("Not everyone can be a computer! All players but one have been made computers!");
computers = players - 1;
}
for (int a = 0; a < players - computers; a++)
{
users.add(new Player(10, false, users.size() + 1));
}
for (int a = 0; a < computers; a++)
{
users.add(new Player(10, true, users.size() + 1));
}
System.out.println("All guesses must be 1-10");
Guess();
}
public static void Guess()
{
Scanner in = new Scanner(System.in);
int guess;
String win = "";
LinkedList<Player> winners = new LinkedList<Player>();
while (true)
{
guess = random(1, 10);
for (int a = 0; a < players; a++)
{
if (!users.get(a).isComputer())
{
users.get(a).setGuess(
getInt("Player " + a + "'s guess: "));
}
else
{
users.get(a).setGuess(random(1, 10));
}
}
for(int a = 0; a < players; a++)
{
if(users.get(a).getGuess() == guess)
{
winners.add(users.get(a));
System.out.println("Player " + users.get(a).getNumber() + " is a winner!");
}
}
System.out.println("The winning guess was " + guess);
System.out.println("");
}
}
public static int getInt(String msg)
{
Scanner a = new Scanner(System.in);
System.out.print(msg);
while (true)
{
try
{
return a.nextInt();
}
catch (InputMismatchException e)
{
a.next();
System.out.print(msg);
}
}
}
private static int random(int min, int max)
{
return (int) (Math.random() * (max - min + 1)) + min;
}
}
player class:
Code:
public class Player
{
private boolean computer;
private int cash;
private int guess;
private int number;
public Player(int startingCash, boolean computer, int number)
{
this.computer = computer;
this.cash = startingCash;
this.number = number;
}
public boolean isComputer()
{
return computer;
}
public void setComputer(boolean computer)
{
this.computer = computer;
}
public int getCash()
{
return cash;
}
public void setCash(int cash)
{
this.cash = cash;
}
public int getGuess()
{
return guess;
}
public void setGuess(int guess)
{
this.guess = guess;
}
public int getNumber()
{
return number;
}
}
I hope you like!!!!!


