Question: Write a Java program which will prompt the user to choose a task between two tasks (RollDice or Distance). When the user types in RollDice,

Write a Java program which will prompt the user to choose a task between two tasks (RollDice or Distance).

When the user types in RollDice, then your program will carry out the simulation of the rolling of a pair of dice. For each die in the pair, the program should generate a random number between 1 and 6 (inclusive). It should print out the result of the roll of each die and the total roll (the sum of the two dice).

When the user types in Distance, then your program will carry out the computation of the distance between two points in the Cartesian coordinate system. The distance between the two points (x1,y1) and (x2,y2) is computed by taking the square root of the quantity (x1-x2) 2 + (y1-y2) 2 . Format the resulting distance so that it is represented with two digits after the decimal place. The inputs will always be integers.

You must use a switch statement and the Random class (plus other classes) for this program.

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!