Dice Game Write a program that plays a simple dice game between the computer and the user. When the program runs, a loop should repeat 10 times. Each iteration of the loop should do the following: Generate a random integer in the range of 1 through 6. This is the value of the computer's die. . Generate another random integer in the range of 1 through 6. This is the value of the user's die. The die with the highest value wins. (In case of a tie, there is no winner for that particular roll of the dice.) As the loop iterates, the program should keep count of the number of times the computer wins, and the number of times that the user wins. After the loop performs all of its iterations, the program should display who was the grand winner, the computer or the user. Computername is a specially-formed String that consists of 3 letters (can be upper-case or lower-case), followed by a dash, followed by 4 numbers. For example, "abc-1234". All computer name follow this pattern, otherwise they are invalid. Use this UML diagram.
class: die
Data Memebers:
-computername: String
-Username: String
-sides: int
-value: int
Method Members:
+Die(sides : int)
+Die(computename:String,username:String)
+ getSide() :int
+ setSide(sides : int) : void
+ getValue() : int
+ setValue(value : int) : void
+roll() : void
+getComputername(): String
+setComputername(value: String):void
+getUsername(): String
+setUsername(value:String): void
Sample output:
Enter computer name: yza-3512
Enter user name: Johny
This simulates the rolling of a 6 sided die and a 6 sided die
Rolling the dice 10 times
Die1 Die2
3 6
5 4
6 6
6 5
1 4
4 4
6 6
1 2
3 5
2 6
Computer=8 user=2
Grand winner is computer yza-3512
Or
Grand winner is user xyz
Or
There is tie between computer xyz-1234 and user Han
public class Die {
private final int MAX_ROLLS = 10;
private int MAX = 6;
private int Sides;
private int value;
public Die() {
getSides();
setSides(6);
getValue();
setValue(6);
roll();
}
public int getSides() {
return Sides;
}
public void setSides(int sides) {
Sides = sides;
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
public void roll() {
System.out.println("Dice 1 Dice 2");
for (int i = 1; i <= MAX_ROLLS; i++) {
int q, p;
q = (int) (MAX * Math.random() + 1);
p = (int) (MAX * Math.random() + 1);
System.out.println(" " + q + " " + p);
}
}
public String getComputername(){
return "";
}
public void setComputername(String value){
}
public String getUsername(){
return "";
}
public void setUsername(String value){
}
}
public class TestDie {
public static void main(String[] args) {
int Sides, values;
Scanner input = new Scanner(System.in);
System.out.println("Enter Computer Name: ");
String comname = input.nextLine();
System.out.println("Enter User Name: ");
String Username = input.nextLine();
System.out.println("This Simulates the rolling of 6 sided die and" +
" a 6 sided die\nRolling the Dice 10 Times");
Die die1 =new Die();
Die die2 = new Die();
}
}
Can someone check my code why it keeps doing this all the time:
Computer....0
User........0
Ties........1
The game has ended in a tie!