Question: turn this code from java to OOP!!! ~ This task, you will create game Bars 21 or Sticks 21. There are 21 Bars and two

turn this code from java to OOP!!!
~
This task, you will create game Bars 21 or Sticks 21. There are 21 Bars and two players (A and B) in this game. The program must randomly select who is the first player (A or B). Each player can pick up the bars or sticks only 1, 2 or 3. The player who picks up the last bar(s) will loss in the game.
The program MUST detect the error and let player to pick the appropriate number of bars(sticks) as shown in:
~
import java.util.*;
public class Main {
public static void main(String args[]) {
Random rand = new Random ();
System.out.println("Bars 21 Game, each player picks 1,2 or 3 bars");
int random = (rand.nextInt(2))+1; // Random number to choose first player
char player1,player2;
if(random==1) {
player1 = 'A';
player2='B';
}
else {
player1='B';
player2='A';
}
int Bars = 21;
while(Bars>=0){
if(Bars>0){
System.out.print("Bars = " + Bars + " Player " + player1 + " Picks : ");
int n = (rand.nextInt(Math.min(Bars,3)))+1; // Random number to choose the number of sticks.
System.out.println(n);
Bars-=n;
}
else{
System.out.println("Player " + player2 + " Win !!");
break;
}
if(Bars>0){
System.out.print("Bars = " + Bars + " Player " + player2 + " Picks : ");
int n = (rand.nextInt(Math.min(Bars,3)))+1; // // Random number to choose the number of sticks.
System.out.println(n);
Bars-=n;
}
else {
System.out.println("Player " + player2 + " Win !!");
break;
}
}
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!