Question: Please help me make a UML for Java! Look at the code below and make a UML for it. Die.Java public class Die { private

Please help me make a UML for Java! Look at the code below and make a UML for it.

Die.Java

public class Die {

private int number_of_Sides;

private int currentSide;

public Die(int numSides) {

this.number_of_Sides = number_of_Sides;

roll();

}

public int get_Num_Sides() {

return number_of_Sides;

}

public int get_Current_Side() {

return currentSide;

}

public void roll() {

currentSide = (int) (Math.random() * number_of_Sides) + 1;

}

public String toString() {

return "Die with " + number_of_Sides + " sides showing " + currentSide;

}

}

DiceCollection.Java

public class DiceCollection {

private Die[] dice;

public DiceCollection(int[] numSidesArray) {

dice = new Die[numSidesArray.length];

for (int i = 0; i < numSidesArray.length; i++) {

dice[i] = new Die(numSidesArray[i]);

}

}

public int get_Current_Sum() {

int sum = 0;

for (Die die : dice) {

sum += die.getCurrentSide();

}

return sum;

}

public int get_Min_Possible_Sum() {

int sum = 0;

for (Die die : dice) {

sum += 1;

}

return sum;

}

public int get_Max_Possible_Sum() {

int sum = 0;

for (Die die : dice) {

sum += die.get_Num_Sides();

}

return sum;

}

public void rollAll() {

for (Die die : dice) {

die.roll();

}

}

public String toString() {

StringBuilder sb = new StringBuilder();

for (Die die : dice) {

sb.append(die.toString() + " ");

}

sb.append("Minimum possible roll: " + getMinPossibleSum() + " ");

sb.append("Maximum possible roll: " + getMaxPossibleSum() + " ");

sb.append("Current total showing on the dice: " + getCurrentSum());

return sb.toString();

}

public int[] histogram(int numRolls) {

int[] counters = new int[getMaxPossibleSum() - getMinPossibleSum() + 1];

for (int i = 0; i < numRolls; i++) {

rollAll();

int sum = getCurrentSum();

counters[sum - getMinPossibleSum()]++;

}

return counters;

}

}

Main.java

public class Main {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter the no. of dice: ");

int numDice = scanner.nextInt();

int[] sides = new int[numDice];

for (int i = 0; i < numDice; i++) {

System.out.print("Enter the number of sides for die " + (i + 1) + ": ");

sides[i] = scanner.nextInt();

}

DiceCollection diceCollection = new DiceCollection(sides);

System.out.println(diceCollection);

while (true) {

System.out.println(" Select an option:");

System.out.println("1. Roll once");

System.out.println("2. Roll 100,000 times");

System.out.println("3. Quit");

int choice = scanner.nextInt();

switch (choice) {

case 1:

diceCollection.roll();

System.out.println(diceCollection);

break;

case 2:

System.out.print("Enter the number of rolls: ");

int numRolls = scanner.nextInt();

int[] histogram = diceCollection.histogram(numRolls);

System.out.println("Histogram of " + numRolls + " rolls:");

for (int i = 0; i < histogram.length; i++) {

if (histogram[i] != 0) {

System.out.println(i + ": " + histogram[i]);

}

}

break;

case 3:

System.exit(0);

default:

System.out.println("Invalid option");

}

}

}

}

Please PUT your UML. Thank you!!

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!