Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that prompts the user for the number n of die tosses, then calls a constructor with argument n. Your class should have

Write a program that prompts the user for the number n of die tosses, then calls a constructor with argument n. Your class should have a method which then generates a sequence of n random die tosses in an array and returns the array reference. Your main program then prints the die values, marking runs by including them in parentheses, like this:

1 2 (5 5) 3 1 2 4 3 (2 2 2 2) 3 6 (5 5) 6 3 1

Use the following pseudocode:

Set a boolean value inRun to false. For each index i in the array { If inRun { if(values[i] is different from the preceding value{ print ) inRun = false } } if not inRun { if values[i] is the same as the following value{ print ( inRun = true } } print values[i] } If inRun, print )

I have ...... needs to be OOP java thanks

public class DieTosses { public static void printRun(int[] values) {

boolean inRun = false;

int previousValue = values[0];

for (int i = 0; i < values.length - 1; i++) {

if (inRun) {

if (values[i] != previousValue) {

System.out.print(")");

inRun = false;

}

} else {

if (values[i] == values[i + 1]) {

System.out.print(" (");

inRun = true;

} else {

System.out.print(" ");

}

}

previousValue = values[i];

System.out.print(values[i]);

}

if (inRun && values[values.length - 1] == previousValue) {

System.out.print(" " + values[values.length - 1] + ")");

} else if (inRun && values[values.length - 1] != previousValue) {

System.out.print(") " + values[values.length - 1]);

} else {

System.out.print(" " + values[values.length - 1]);

}

}

public static int[] generateDieTosses(int n) {

int[] tosses = new int[n];

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

tosses[i] = (int) (Math.random() * 6 + 1);

}

return tosses;

}

}

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_2

Step: 3

blur-text-image_3

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

Database Design Application Development And Administration

Authors: Michael V. Mannino

4th Edition

0615231047, 978-0615231044

More Books

Students also viewed these Databases questions

Question

Write a note on job design.

Answered: 1 week ago

Question

Compute the derivative of f(x)cos(-4/5x)

Answered: 1 week ago

Question

Discuss the process involved in selection.

Answered: 1 week ago

Question

Differentiate tan(7x+9x-2.5)

Answered: 1 week ago