Question
Die class public class Die { int value; boolean freeze; int sides; public Die(int sides) { super(); this.freeze = false; if (sides > 1) {
public class Die {
int value; boolean freeze; int sides;
public Die(int sides) { super();
this.freeze = false;
if (sides > 1) { this.sides = sides; this.value = 1;
}
else { System.out.println(\"Number of sides Should be greater than one. Setting it to 6\"); this.sides = 6; this.value = 1; } }
public Die() {
this.freeze = false; this.sides = 6; this.value = 1; } public void setValue(int v) { if(!this.freeze) { if(v>0 && v=this.sides)> this.value = v; } else { System.out.println(\"Value should be between 0 and \"+this.sides); this.value = 1; } } } public int getValue() { return this.value; } public void freeze() { this.freeze = true; } public void unfreeze() { this.freeze = false; } public void roll() { if(!this.freeze) { int val = (int) (1+Math.random()*sides); this.value = val; } } public void print() { System.out.println(\"[\"+this.value+\":\"+this.sides+\"]\"); } public void draw() { switch(value) { case 1: System.out.println(\"*********\"); System.out.println(\"* *\"); System.out.println(\"* * *\"); System.out.println(\"* *\"); System.out.println(\"*********\"); break; case 2: System.out.println(\"*********\"); System.out.println(\"* *** *\"); System.out.println(\"* * *\"); System.out.println(\"* *** *\"); System.out.println(\"*********\"); break; case 3: System.out.println(\"*********\"); System.out.println(\"* *** *\"); System.out.println(\"* ** *\"); System.out.println(\"* *** *\"); System.out.println(\"* *\"); System.out.println(\"*********\"); break; case 4: System.out.println(\"**********\"); System.out.println(\"* * *\"); System.out.println(\"* * * *\"); System.out.println(\"* **** *\"); System.out.println(\"* * *\"); System.out.println(\"**********\"); break; case 5: System.out.println(\"***********\"); System.out.println(\"* **** *\"); System.out.println(\"* * *\"); System.out.println(\"* **** *\"); System.out.println(\"* * *\"); System.out.println(\"* **** *\"); System.out.println(\"**********\"); break; case 6: System.out.println(\"**********\"); System.out.println(\"* * *\"); System.out.println(\"* **** *\"); System.out.println(\"* **** *\"); System.out.println(\"* *\"); System.out.println(\"**********\"); break; default: print(); break; } }
}
______________________________________________________________________________
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started