Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Die class public class Die { int value; boolean freeze; int sides; public Die(int sides) { super(); this.freeze = false; if (sides > 1) {

Die class

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions