Players: 2-6
Object: To be the last player with any coins.
Setup: Each player starts with four pennies, three nickels, two dimes, and a quarter. The pot is empty at the beginning of the game.
Play: On your turn, put one of your coins into the pot. You may then take change from the pot, up to one cent less than the value of the coin you played. For example, if you put in a dime, you may take out up to nine cents worth of coins.
This is the objective of the program and here is the actual game program I can't figure out how to alternate between the two players and to add to the pot as of right now the program runs but takes the user input and ends the program I been trying to use a while to for the players to take turns but it always comes back as an error
This is the setCoin class
Object: To be the last player with any coins.
Setup: Each player starts with four pennies, three nickels, two dimes, and a quarter. The pot is empty at the beginning of the game.
Play: On your turn, put one of your coins into the pot. You may then take change from the pot, up to one cent less than the value of the coin you played. For example, if you put in a dime, you may take out up to nine cents worth of coins.
This is the objective of the program and here is the actual game program I can't figure out how to alternate between the two players and to add to the pot as of right now the program runs but takes the user input and ends the program I been trying to use a while to for the players to take turns but it always comes back as an error
import java.util.Scanner; public class PennyWiseGame { private SetCoin pOne; private SetCoin pTwo; private SetCoin pot; private int deposit; Scanner input; public PennyWiseGame(){ pOne = new SetCoin(4, 3, 2, 1); pTwo = new SetCoin(4, 3, 2, 1); pot = new SetCoin(0, 0, 0, 0); deposit = 0; input = new Scanner(System.in); } public void turn(){ System.out.print("Player 1\nSelect which coin to add to the pot:\n1. Penny\n2. Nickel\n3.Dime\n4. Quarter\n"); deposit = input.nextInt(); while(deposit > 4 || deposit < 0){ System.out.println("Invalid Choice!"); System.out.print("Select which coin to add to the pot:\n1. Penny\n2. Nickel\n3. Dime\n4. Quarter\n"); deposit = input.nextInt(); } } public static void main(String[] args){ System.out.println("Welcome to PennyWise!"); PennyWiseGame game = new PennyWiseGame(); game.turn(); } }
This is the setCoin class
public class SetCoin { private double pennies; private double nickels; private double dimes; private double quarters; public SetCoin(double numPen, double numNic, double numDi, double numQu){ pennies = numPen; nickels = numNic; dimes = numDi; quarters = numQu; } public void addPenny(){ pennies++; } public void addNickel(){ nickels++; } public void addDime(){ dimes++; } public void addQuarter(){ quarters++; } public void subPenny(){ pennies--; } public void subNickel(){ nickels--; } public void subDime(){ dimes--; } public void subQuarter(){ quarters--; } public void setPen(double newPen){ pennies = newPen; } public double getPen(){ return pennies; } public void setNic(double newNic){ nickels = newNic; } public double getNic(){ return nickels; } public void setDi(double newDi){ dimes = newDi; } public double getDi(){ return dimes; } public void setQu(double newQu){ quarters = newQu; } public double getQu(){ return quarters; } }