Question: import java.util.*; public class Die { private int faceValue; private final int MAX = 6; public Die() { faceValue = 0; } public void roll()
import java.util.*;
public class Die
{
private int faceValue;
private final int MAX = 6;
public Die()
{
faceValue = 0;
}
public void roll()
{
Random rand = new Random();
int n = rand.nextInt(MAX) + 1;
setFaceValue(n);
}
public void setFaceValue(int n)
{
faceValue = n;
}
public int getValue()
{
return faceValue;
}
public String toString()
{
return getValue() + "";
}
}
______________________________________
public class PairOfDice {
private Die die1;
private Die die2;
public int value1, value2, total;
public PairOfDice()
{
die1=new Die();
die2=new Die();
}
public Die getDie1()
{
return die1;
}
public Die getDie2()
{
return die2;
}
public int sumDice()
{
return (value1+value2);
}
public int rollDice()
{
die1.roll();
die2.roll();
value1=die1.getValue();
value2=die2.getValue();
return value1+value2;
}
public String toString()
{
return "Die 1=" + die1 + ", Die 2=" + die2 ;
}
}_______________________________________
import java.util.Scanner;
public class Hog
{
public static void main(String[] args) //Main method to call the provided classes
{
char x= 'Y';
int sum=0,sum1=0;
int computer1=0, You=0;
while(x=='Y' || x=='y')//while loop to check if user wants to continue or not
{
PairOfDice human=new PairOfDice();
human.rollDice();
System.out.println(human.toString());
sum+=human.sumDice();
System.out.println("Your points: "+sum); //Print the current round value
System.out.println("Your points: "+sum); //Print potential round value
int d1=Integer.parseInt(human.getDie1().toString()); //to get value of die1
int d2=Integer.parseInt(human.getDie2().toString()); //to get value of die2
if(sum>50)
{
System.out.println("You Won!"+sum);
break;
}
if(d1==1||d2==1)//Comapre value of die1 and die2
{
// System.out.println("computer : "+(computer1+=sum1));
//System.out.println("You : "+(You+=sum));
while(x=='Y' || x=='y')
{
System.out.println("Busted..!!");
PairOfDice computer=new PairOfDice();
computer.rollDice();
System.out.println(computer.toString());
sum1+=computer.sumDice();
System.out.println("computer points: "+sum1); //Print the current round value
System.out.println("computer points: "+(sum1)); //Print potential round value
int cd1=Integer.parseInt(computer.getDie1().toString()); //to get value of die1
int cd2=Integer.parseInt(computer.getDie2().toString()); //to get value of die2
System.out.println("computer : "+(computer1+=sum));
System.out.println("You : "+sum1);
if(sum1>50)
{
System.out.println("computer Won!!"+(computer1+=sum));
break;
}
if(cd1==1||cd2==1)
{
System.out.println("Busted..!!");
break;
}
System.out.println("Take another turn (y/n)?"); //user input dialog
Scanner in = new Scanner(System.in); //Scanner used to accept user input from console
x = in.next().charAt(0);
}
break;
}
System.out.println("Take another turn (y/n)?"); //user input dialog
Scanner in = new Scanner(System.in); //Scanner used to accept user input from console
x = in.next().charAt(0); //read only 1st char
}
}
}
basing on these 3 code , how to modify the mian class to satisfy the conditions below?
Note: You may use any loop you want. But...points off if you use break or continue.
while (computerTotalScore < 50 and humanTotalScore < 50) computerPlayer takes their turn if computerTotalScore < 50 humanPlayer takes their turn Display winner and final results B) Design and implement the Computer Player (one round/turn) 1) Think about what keeps Computer Player rolling again(their turn)
computerRoundTotal < 20 and rolls no 1
2) Roll the dice and accumulate computerRoundScore
3) What happens when computer's turn is over?
if (either die == 1) display busted else add computerRoundScore + computerTotalScore update computerRoundScore for next round display computerRoundScore and computerTotalScore C) Next design and implement the Human Player (one turn) 1) Think about what keeps Human Player rolling (their turn)
player answers "yes" to take another turn and and rolls no 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
