I'm a beginner in java and I have the following exercise to solve:
Read a set of sports lottery bets to an unspecified number of players. After that, read the template, compare the result and display a message.
Bet Class: must contain the player's name and an integer vector with thirteen positions to store the bet: 1 – winner of team A, 2 – winner of team B, and 0 for draw. Create the necessary constructor methods and the toString method.
ReadBets Class: This class must have an attribute that is a vector of objects of the Bet class. In addition, this class must have a method to read the person's name and their sports lottery game. Create the necessary constructor methods and the toString method.
ReadTemplate Class: This class should read the correct answers from the sports lottery game and store the result in an integer vector. Create the necessary constructor methods and the toString method.
GenerateResult Class: this class must compare the players' bets with the result of the template and, if you have 6 correct answers, show the winner's name, his game and the message: “WINNER, CONGRATULATIONS”. Otherwise, show the player name and the message “Try again, this time you didn't win”.
Main Class: implement in this class the control and execution flow for this problem creating the necessary objects to solve this class.
There is a complicating factor for me which is that each object bet is composed of a string name with a vector with the bets.
I made a solution to the problem that already reads validating only the allowed values (0,1,2), reads the template and compares.
However, I noticed that the last name typed and the last bets are always being recorded in the vector. In all positions.
I'm hours assembling and disassembling the code and I can't find a way to solve it.
I read that it may have to do with the new but I didn't understand how to solve it because at each position of the vector of objects I need to give a new to create the object with the internal vector that will store that player's bets.
Below are my classes:
MAIN:
import java.util.Scanner;
import javax.swing.JOptionPane;
public class Main {
public void execute(){}
static Scanner input = new Scanner (System.in);
public static void main(String[] args) {
//ReadBet a = new ReadBet();
V_Bets a = new V_Bets();
System.out.println("Enter the total bets that will be placed");
a.totalBets(input.nextInt());
a.Data entry();
a.Data output();
ReadTemplate g = new ReadTemplate();
g.getTemplate();
GenerateResult gr = new GenerateResult();
gr.generateResult();
}
}
BETS:
import java.util.Arrays;
public class Bet {
private static String name;
public static int[] Bet vector =new int [6];
/*public String getName(){
return this.name;
}*/
public static String getName() {
return name;
}
public void setName(String name){
this.name=name;
}
#Override
public String toString() {
return "Bet [name=" + name + ",Betvector=" + Arrays.toString(Betvector) + "]";
}
public int getBet(int i) {
return this.vector Bets[i];
}
public void setBets(int[] bets) {
this.vector Bets = bets;
}
public int[] getCloneArray() {
returnVectorBets.clone();
}
}
V_BETS
import java.util.Scanner;
public class V_Bets {
Input Scanner = new Scanner (System.in);
private int size;
public static Total BetBets[] = new Bet[100];
//total Bets[j] = new Bet(); //Creating a bet object for each registration - bet object contains name and bet vector of that bettor
private Bet bets = new Bet();
int i=0;
int j=0;
public void dataentry() {
for(j=0;j<size;j++) { //for external - from J that controls the total bets that will be registered
totalBets[j] = new Bet(); //Creating a bet object for each registration - bet object contains name and bet vector of that bettor
System.out.println("Enter the name of the Player:");
totalStakes[j].setName(input.next()); //setting the player's name
// loop to set the guesses
System.out.println("Please enter guesses for each Sports Lottery game");
System.out.println("1 - Winner Team A, 2 - Winner Team B and 0 - Tie");
for ( i=0;i<bets.vetorApostas.length;i++) // receive the bet until it reaches 6
{
System.out.println("Game "+i +":");
totalStakes[j].vectorStakes[i] = input.nextInt(); // receive the user's bets
while (totalApostas[j].vectorApostas[i] < 0 ) // if the user enters a negative number it says to try again
{
System.err.println("Negative Number, try again:");
totalBets[j].vectorBets[i]= entry.nextInt();
}
if (totalApostas[j].vetorApostas[i] > 2) // if the number is greater than 2 it says to try again
{
while (totalBets[j].vectorBets[i] > 2 ) {
System.err.println("Please enter numbers between 0 and 2");
totalBets[j].vectorBets[i]= entry.nextInt();
}
}
}
}
}
/*public void dataoutput() {
//System.out.println("The player's name is:"+total Bets[i].getName());
System.out.println("Your Bet:");
for ( i=0;i < Bet.vectorBeats.length; i++){
System.out.print(+TotalStakes[i].vectorStakes[i].getStakes(i)+ " ");
}
}
public void dataoutput() {
System.out.println("Your Bet::");
for (j=0; j<totalBets[i].vectorBets.length; j++) {
System.err.print("Player "+Total Bets[j].getName()+" ");
for (i = 0; i < totalBets[i].vectorBets.length; i++) {
System.err.print(total Bets[j].vector Bets[i] + " ");
}
}
}*/
public void totalOfBets(int size) {
this.size = size;
}
public int getSize() {
return size;
}
}
TEMPLATE:
public class Template {
//private String name;
public static int[]vectorTemplate =new int [6];
public int getBet(int i) {
return this.vectorTemplate[i];
}
public void setBets(int[] bets) {
this.vectorTemplate = bets;
}
public int getTemplate(int i) {
return this.vectorTemplate[i];
}
public void setTemplate(int[] bets) {
this.vectorTemplate = bets;
}
}
READ TEMPLATE:
import java.util.Arrays;
import java.util.Scanner;
public class ReadTemplate {
private Template template = new Template();
Input Scanner = new Scanner (System.in);
int guesses;
int counter=0;
int j;
int x;
int i;
public void getTemplate() {
System.out.println(" ");
for ( j=0;j<6;j++) // Receive numbers until it reaches 6
{
System.out.println("Now Enter Game Template: "+j);
template.vectorTemplate[j]= entry.nextInt(); // Receive user numbers
while (template.vetorTemplate[j] < 0 ) // If you enter a negative number, ask the user to type again
{
System.err.println("Negative Number, try again:");
template.vectorTemplate[j]=input.nextInt();
}
if (template.vectorTemplate[j] > 2) // if the number is greater than 2 ask again
{
while (template.vectorTemplate[j] > 2 )
{
System.err.println("Please enter numbers between 0 and 2");
template.vectorTemplate[j]=input.nextInt();
}
}
}
//printing the template
System.out.println("Template:");
for (i = 0; i < template.vectorTemplate.length; i++) {
System.out.print(template.vectorTemplate[i] + " ");
}
}
}
GENERATE RESULTS:
public class GenerateResult extends ReadTemplate {
private Bet bets = new Bet();
private Template template = new Template();
//private v_bets v_bets = new v_bets();
private int size;
public void generateResult() {
//Checking if it's right
int x;
V_Bets a = new V_Bets();
for(j=0;j<2;j++) {
int i=0;
int counter=0;
for (x = 0; x < template.vectorTemplate.length; x++) {
if (a.totalStakes[j].vectorStakes[i] == template.vectorTemplate[x]) {
counter++;
}
i++;
}
System.out.println(" ");
System.out.println("Counter of Equals! "+counter);
if (counter <= 5){
System.out.println("Player "+a.Total Bets[j].getName());
System.out.println("Try again, this time you won");
}
else if (counter == 6){
System.out.println("Player "+a.Total Bets[j].getName());
System.out.println("WINNER,CONGRATULATIONS!");
}
}
}
public void totalOfBets(int size) {
this.size = size;
}
}
I am immensely grateful to anyone who can help understand where I went wrong and how to evolve.
Related
my question is how would I sort the arrayofnames and arrayofdownloads so they're in ascending order and each name matches with it corresponding number of downloads. i've been trying for 4 hours and i can't seem to wrap my head around it
thanks
import java.util.*;
import java.util.stream.*;
public class short6
{
public static void main(String[] args)
{
String[] arrayofnames = new String[4];
int[] arrayofdownloads = new int[4];
printmessage(arrayofnames, arrayofdownloads);
details(arrayofnames, arrayofdownloads);
System.exit(0);
}
public static void printmessage(String[] arrayofnames, int[] arrayofdownloads)
{
Scanner scanner = new Scanner(System.in);
int totalDownloads = 0;
for (int i = 0; i < arrayofnames.length; i++)
{
System.out.println("What is track " + (i + 1));
arrayofnames[i] = scanner.nextLine();
System.out.println("How many thousands of times has it been downloaded? ");
arrayofdownloads[i] = Integer.parseInt(scanner.nextLine());
}
Arrays.sort(arrayofnames);
Arrays.sort(arrayofdownloads);
System.out.println("The track downloaded the most is " + arrayofdownloads[0]+".");
}
public static void details(String[] arrayofnames, int[] arrayofdownloads)
{
int totaldownloads = IntStream.of(arrayofdownloads).sum();
System.out.println("The track downloaded the most is " + arrayofdownloads[0]+".");
System.out.println("The total number of downloads of these 4 tracks was " + totaldownloads * 1000 +".");
System.out.println("\nThe details of the downloads are");
for (int i = 1; i < arrayofnames.length; i++)
{
System.out.println(arrayofnames[i]);
System.out.println((arrayofdownloads[i]));
}
}
}
I'd start creating a Song (e.g.) class that contains both the song name, and the number of downloads:
public class Song {
private String name;
private int downloads;
public Song(String name, int downloads) {
this.name = name;
this.downloads = downloads;
}
public String getName() {
return this.name;
}
public int getDownloads() {
return this.downloads;
}
}
And then, create an array of songs:
Song[] arrayOfSongs = new Song[4];
And load it from the input:
arrayOfSongs[i] = new Song(scanner.nextLine(), Integer.parseInt(scanner.nextLine()));
Now you just need to sort it using a comparator:
Arrays.sort(arrayOfSongs, new Comparator<Song> () {
public int compare(Song o1, Song o2) {
// Sorting by name
return o1.getName().compareTo(o2.getName());
}
});
Or, as #Benoit has said in the comments, it would be even easier this way (Java 8 or up):
Arrays.sort(arrayOfSongs, Comparator.comparing(Song::getName));
And your done, just printing the objects (a toString method can be helpful here) you have the information sorted.
Edit: to read the input writing the questions, you just need to store the values in variables e.g.
System.out.println("What is track " + (i + 1));
String songName = scanner.nextLine();
System.out.println("How many thousands of times has it been downloaded? ");
int songDownloads = Integer.parseInt(scanner.nextLine());
arrayOfSongs[i] = new Song(songName, songDownloads);
Or you can just implement setter methods in the Song class and create a constructor with no parameters, so you can set the values as you are reading them.
thanks for the reply, so I've figured that i can use a for loop to ask the questions for song name and number of downloads. what im finding hard is putting their response in each array from 1-4 and saving dong name in the correct field of the song record and same for number of downloads?
public static void printmessage(song[] arrayOfSongs)
{
Scanner scanner = new Scanner(System.in);
int totalDownloads = 0;
for (int i = 0; i < arrayOfSongs.length; i++)
{
System.out.println("What is track " + (i + 1));
// store in array x name field
System.out.println("How many downloads does this track have? ");
//store in array x downloads field
}
I would like to know what is the best way to get the index of a specific letter in a word. The reason i am doing this, is because i am making and modifying a Hangman game. I am already done with the game and it works good, however i want to implement a score based system. I created a method called keepScore() that takes a boolean value to see if the answer is right or wrong. If it is right, i am going to add 10 points for each letter found. If its wrong, i will deduct 10 points. My method keepScore() is implemented incorrectly any help?
Hangman.java
import Game.Game;
import Prompter.Prompter;
/* This class is the main class that starts the game.
* It instantiates the Game and Prompter objects.
*/
public class Hangman {
public static void main(String[] args) {
//Check if an argument has been passed, we expect the answer to be passed
if(args.length == 0) {
System.out.println("Expected: Java Hangman <answer>");
System.err.println("Answer is required!");
System.exit(1);
}
System.out.println("Welcome to Hangman!");
//Create an instance of our game
Game game = new Game(args[0]);
//Create an instance of our prompter
Prompter prompter = new Prompter(game);
//Starts the game
while (game.getRemainingTries() > 0 && !game.isWon()) {
prompter.displayProgress();
prompter.promptForGuess();
}
//Displays the outcome of the game
prompter.displayOutcome();
}
}
Game.java
package Game;
/* This class is responsible for implementing the game
* logic.
*/
public class Game {
//Declare our member variables
public final static int TOTAL_TRIES = 3;
public final static int MAX_SCORE_POINTS = 10;
private String mAnswer;
private String lettersHit;
private String lettersMissed;
private int score;
//Default constructor
public Game(String answer) {
//Initialize our member variables
mAnswer = answer.toLowerCase();
lettersHit = "";
lettersMissed = "";
}
//This method checks to see if the letter was a hit or a miss
public boolean checkLetter(char letter){
letter = validateGuess(letter);
boolean isHit = mAnswer.indexOf(letter) != -1;
//If correct
if (isHit) {
//Add the letter to the lettersHit pool
lettersHit += letter;
keepScore(isHit);
System.out.println("Hit! Score: " + score);
}else {
//Add the letter to the lettersMissed pool
lettersMissed += letter;
keepScore(isHit);
System.out.println("Missed! Score: " + score);
}
return isHit;
}
private void keepScore(boolean isHit) {
if(isHit) {
for (int i = 0; i < lettersHit.length(); i++) {
score += MAX_SCORE_POINTS;
}
} else {
for (int i = 0; i < lettersMissed.length(); i++ ) {
score -= MAX_SCORE_POINTS;
}
}
}
/*
This method handles an empty string input. For example,
if the user were to press enter on input a 0 length String
will cause the program to crash.
*/
public boolean checkLetter(String letters) {
if (letters.length() == 0) {
throw new IllegalArgumentException("No letter entered");
}
return checkLetter(letters.charAt(0));
}
//This method validates the user guess
private char validateGuess(char letter) {
//If the character is not a letter
if (!Character.isLetter(letter)) {
//Ask user for a valid letter
throw new IllegalArgumentException("A letter is required!");
}
//If entry was valid, convert character to lowercase
letter = Character.toLowerCase(letter);
//Check if the letter has been guessed already
if (lettersHit.indexOf(letter) != -1 || lettersMissed.indexOf(letter) != -1) {
throw new IllegalArgumentException("The letter " + letter + " has already been guessed");
}
return letter;
}
//This method keeps track of the user's game progress
public String getCurrentProgress() {
String progress = "";
//For each character in the array of strings of mAnswer
for (char letter : mAnswer.toCharArray()) {
char display = '-';
if (lettersHit.indexOf(letter) != -1){
display = letter;
}
progress += display;
}
return progress;
}
//Get the current remaining tries
public int getRemainingTries() {
return TOTAL_TRIES - lettersMissed.length();
}
//Get the current answer
public String getAnswer() {
return mAnswer;
}
//This method checks if the game is won.
public boolean isWon() {
return getCurrentProgress().indexOf('-') == -1;
}
public int getScore(){
return score;
}
}
Prompter.java
package Prompter;
import Game.Game;
import java.util.Scanner;
/* This class is responsible for displaying instructions and information to the user
* regarding the game.
*/
public class Prompter {
//The game object
private Game mGame;
private boolean isHit;
private boolean acceptable;
//Default constructor
public Prompter(Game game) {
//Get the instance of our game
mGame = game;
isHit = false;
acceptable = false;
}
//This method prompts the user for a guess
public boolean promptForGuess() {
//Create an instance of scanner
Scanner scanner = new Scanner(System.in);
//Loop for input
do {
System.out.println("Please enter a letter: ");
String guess = scanner.nextLine();
try {
isHit = mGame.checkLetter(guess);
acceptable = true;
}catch (IllegalArgumentException iae) {
System.out.printf("%s. Please try again!%n", iae.getMessage());
}
} while (!acceptable);
return isHit;
}
//This method displays the progress
public void displayProgress() {
System.out.printf("You have %d tries to guess the answer" +
" before you are taken to the gallows. Try to solve: %s%n", mGame.getRemainingTries(),
mGame.getCurrentProgress());
}
//This method displays the outcome of the game
public void displayOutcome() {
if( mGame.isWon()) {
System.out.printf("Congratulations! you won with %d tries remaining.%n" +
"Your total score: %d%n", mGame.getRemainingTries(), mGame.getScore());
}else {
System.out.printf("Bummer! The answer was: %s", mGame.getAnswer());
}
}
}
Look at this method of yours:
private void keepScore(boolean isHit) {
if(isHit) {
for (int i = 0; i < lettersHit.length(); i++) {
score += MAX_SCORE_POINTS;
}
} else {
for (int i = 0; i < lettersMissed.length(); i++ ) {
score -= MAX_SCORE_POINTS;
}
}
}
It doesn't add MAX_SCORE_POINTS times the number of good letters you just found, it does so with the number of good letters in lettersHit. Now, what is in lettersHit ? Well, there is all the letters you found since the start.
So you'll have :
word to guess: anaconda
letter: a
lettersHit = "a", score += (lettersHit.length * 10) = 10
letter: c
lettersHit = "ac", score += (lettersHit.length * 10) = 30
You could just use StringUtils.countMatches(mAnswer, letter); to get the number of occurence, hence the score.
I´m trying to create a simple yahtzee game where an array is filled with 5 random numbers and where the player can choose to roll specific dices again. However I cant figure out how to write the method that is supposed to replace specific numbers in the array with new random numbers and return it. Any suggestions how to approach this?
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
public class YatzyGame {
private final Integer NBROFDICE = 5;
private final Integer DICEMAXVALUE = 6;
Random rnd = new Random();
Scanner keyboard = new Scanner(System.in);
public void startGame() {
int[] dice = new int[NBROFDICE];
rollDice(dice);
printDice(dice);
System.out.println("Do you want to reroll any dices? " + "Y/N");
String answer = keyboard.nextLine();
if (answer.equalsIgnoreCase("y")) {
rerollDice(dice);
} else if (answer.equalsIgnoreCase("n")) {
calculateSum(dice);
} else {
System.out.println("Wrong command!");
}
}
public int[] rollDice(int[] dice) {
for (int i = 0; i < dice.length; i++) {
dice[i] = rnd.nextInt(DICEMAXVALUE) + 1;
}
return dice;
}
public int[] rerollDice(int[] dice) {
System.out.println("What dices do you want to reroll? Dices index are 0-4");
int diceToReroll = keyboard.nextInt();
// Replace the numbers at the index the user specifies with new random numbers and return the array.
}
public void printDice(int[] dices) {
System.out.println("Your dices show: " + Arrays.toString(dices));
}
public void calculateSum(int[] dices) {
int sum = 0;
for (int i : dices) {
sum += i;
}
if (sum == 30) {
System.out.println("YAHTZEE! Your total score is 50! Congratulations!");
} else
System.out.println("Your total score is: " + sum);
}
public static void main(String[] args) {
new YatzyGame().startGame();
}
}
public int[] rollDice(int[] dice) {
System.out.println("What dice do you want to reroll? Dices index are 0-4");
int diceToRoll = keyboard.nextInt();
dice[diceToRoll] = rnd.nextInt(DICEMAXVALUE) + 1;
}
Like this you can make a function:
public int[] reroll(int amountOfRerolls, int[] dices){
for(int i =0;i<dicesToReroll;i++){
this.rollDice(dices);
}
return dices;
}
This makes the programm a bit more modal since you can reuse your rollDice() method wherever you need it. Also you could expand it a bit by handing in the indexes that are allowed to be rerolled in case needed.
edit: style
So I was asked to do these task:
Write an executable console application GuessingGame where a player tries to guess a
number between 1 and 20. At the start of each game, GuessingGame instantiates a Player
object which will be used to store the game scores for a given player. The player’s name is
assigned from user input. The program then generates a random number between 1 and 20
and asks the player to guess the number. When the player enters a number, the program tells
the player whether the number is too high or too low. The player should keep entering guess
numbers until the correct number is entered.
The score is computed as follow:
score = (20 – the number of guesses).
Each player is asked to play the game five times, so five scores are stored for each player.
The application should then display the average and best score for the player.
I got the game working although I am stuck on the if statement. I tried calling the getScore method from Player class but I am getting operand errors. here is my GuessingGame code:
public class GuessingGame
{
public static void main (String [] args)
throws IOException
{
String name;
final int numberOfGuess = 5;
//Create Scanner object
Scanner input = new Scanner (System.in);
Player[] player1 = new Player[numberOfGuess];
//Ask user for name
System.out.printf("\n Enter Player Name:");
name = input.nextLine();
PrintStream fout = new PrintStream(new File("PlayerData.txt"));
for (int index = 0; index < player1.length ; index++)
{
int playerId = index + 1;
player1[index] = new Player(name); // reference to Student object
player1[index].setName(name);
//Ask user for number input
System.out.println("Please pic a number between 1 - 20");
player1[index].setScore(Integer.parseInt(input.nextLine()));
Random rand = new Random();
int answer = rand.nextInt(20) + 1;
System.out.println(answer);
System.out.println(player1[index].getScores());
if(answer >= player1[index].getScores())
{
System.out.println("Your guess is too low");
}
}
fout.println( "" + player1[1].getName() );
for (int index = 0; index < player1.length ; index++)
{
int playerId = index + 1;
fout.println( "" + player1[index].getScores() );
}
}
}`
And here is my Player class:
//Class declaration of Player class
public class Player
{
/*--------------- Data Fields ---------------------------------------
Attributes of the class
*/
private String name;
private int playerId;
private int bestScore;
private static int numberOfPlayers = 0;
private ArrayList<Integer> scores = new ArrayList<Integer>();
/* -------------- CONSTRUCTOR --------------------------------------
*/
public Player(String name)
{
this.name = name;
numberOfPlayers++;
playerId = numberOfPlayers;
}
//Create set method for setName
public void setName(String name)
{
this.name = name;
}
//Create set method for setScores
public void setScore(int score)
{
scores.add(score);
}
//Create get method for getScores
public ArrayList<Integer> getScores()
{
return scores;
}
}
I did not put the rest of the methods as they are not the issue.
Did I set the methods incorrectly ? If so how do I get around this issue ?
This attempts to compare an int to an ArrayList<Integer>:
if (answer >= player1[index].getScores())
Perhaps you want to compare the int to the size of the ArrayList:
if (answer >= player1[index].getScores().size())
or to compare the int to some element of the ArrayList:
if (answer >= player1[index].getScores().get(someIndex))
It's not clear from your question what the desired logic is.
I'm working on a roulette game and I'm having an error with my makeDecision method in my Roulette class. The reason is because I am having trouble with the updatePot method in my Player class and am not sure what to do in it. I am using 4 classes, here is my code for each:
public class Assign3 {
public static void main(String[] args) {
Roulette roulette = new Roulette();
roulette.run();
}
}
and
public class Roulette {
private String decision;
Player player = new Player();
Wheel wheel = new Wheel();
private void makeDecision(){
String bet = player.getBet();
try {
int value = Integer.parseInt(bet);
if (value == wheel.getValue()){
decision = " you win 40 times your bet";
player.updatePot(40);
} else {
decision = "you lose the game";
player.updatePot(0);
}
} catch (NumberFormatException e){
if (bet.equals("odd")){
if (wheel.getValue() %2 == 0){
decision = "you lose the game";
player.updatePot(0);
} else {
decision = "you win double your bet";
player.updatePot(2);
}
} else if (bet.equals("equals")){
if (wheel.getValue() %2 == 0){
decision = "you win double your bet";
player.updatePot(2);
}
}
}
}
private void displayDecision(){
}
public void run(){
System.out.println("Welcome to Cache Creek style Roulette..bet an amount and type\n"
+ " if you select the correct colour, you win double your bet\n"
+ " if you select the correct odd/even, you win double your bet\n"
+ " if you select the right number, you win 40 times your bet\n"
+ " otherwise you lose your bet\n"
+ " If you lose all your money, the game is over");
do {
player.setBetAmount();
player.setBet();
wheel.spin();
wheel.display();
makeDecision();
displayDecision();
} while (true);
}
}
and
package Assignment3;
import java.util.Scanner;
public class Player {
private int pot = 0;
private int amount = 0;
Scanner input = new Scanner(System.in);
public void setBetAmount() {
System.out.print("\nHow much do you want to bet? ");
amount = input.nextInt();
int pot =100;
if (amount > pot || amount < 1){
System.out.print("Invalid bet amount..How much do you want to bet? ");
amount = input.nextInt();
}
}
public void setBet() {
System.out.print("What is your bet? (odd/even/red/black/exact number)");
}
public String getBet() {
return null;
}
public void updatePot(int i) {
}
}
and
package Assignment3;
import java.util.Random;
public class Wheel {
private int value;
private String colour;
Random random;
public Wheel(){
value = 0;
colour = null;
random = new Random();
}
public int getValue(){
return value;
}
public void setValue(int value){
this.value = value;
}
public String getColour(){
return colour;
}
public void spin(){
value = random.nextInt(39)+1;
colour = (random.nextInt(1)==0)?"red":"black";
}
public void display(){
System.out.print(value+" "+colour);
}
}
the input for your program has to be a String because your Player can input both text or a specific number. You then have to check this String for the occurence of either (odd/even/red/black) or a valid number. If neither is true then the input is invalid.
When looking at your code you need to think about how you want your updatePot method to work.
Should it set the pot to the given value (that's what the method name would suggest to me)
Should it add the given value to the pot or
Should it multiply the current pot value by the given value
When you have decided how it should work you have to update your Roulette.makeDecision() method.
Good luck with your assignment!
Markus
Just change the datatype of bet from String to int and then add your updatePot methode. You will also need to adjust your NumberFormatException.