104k views
1 vote
2. Write a Java program for this 3-dice game. This game will roll the three dice together for 10 times (i.e., a repetition strueture), In each time, it will a. Display the face values from the three dice. b. Decide how to calculate the total points from the three dice face values. (A selection structure) c. Decide if it is blasted, so no point to earn, or otherwise, carn the points to the game total (A selection siructure) After 10 times of dice rolling, this program displays game output including the number of blasts and total point earned in the game. Sce the execution example above. ( 10pts) Requirements: a) Your class should be named ThreeDiceGame, and your java file should be named ThreeDiceGame.java. b) Pseudocode: you should start your java file by providing the class and method blocks with (1. indentation, and comment lines for major tasks in the program. c) In this question, use the Random class and its object to simulate dice rolling. Make sure your dice will generate integer values in the range of 1−6. d) This question doesn't take user input, thus doesn't really need Seanner class and object. But the program usually generates mndom values and do all 10 rolling attempts very fist. To slow it down for the users and for you to check the result from each rolling attempt, you could PRETEND to take user input before each dice rolling attempt. That means, you can still import Scanner and create a Scanner object. You can use a statement like: input. nextline () ; before each dice rolling attempt. This will hold the program execution and requires the user the press the Enter key on the keyboard to continue the dice rolling. Of course, to use it, please provide a nice prompt message / an instruction to the user to let them know that they need to press the Enter key to continue. e) How to set up condition to check if all three values are the same? Consider using & &. f) How to set up condition to check if two values are the same? There are different cases, the first and second are the same, the first and the third are the same, or the second and third are the same. Consider using II to allow all three possibilities. g) You must use WHILE loop for this question. DO NOT USE THE OTHER TYPES OF LOOP. h) You will need two counter variables. One is to count for how many attempts you have rolled the three dice - to control the loop for 10 times. The other is to count how many times that it blasts. Name your two counts clearly and meaningfilly, so you will not be confused between them. i) As a counter variable, the attempt value starts at 0 and stops at 9 for 10 times. However, to display the face values in each dice rolling, you may want to use (attempt +1), so it will print out the attempt# from 1 to 10. j) Programming styles are always required. file and motraction quiz for 2nd graders. Please DO NOT use your AdditionQoi. something similar like the Additiongod opportunity for you to test if you can do get stuck somewhere, you can quickly cheek on the AdditionQuiz as a reference, and then continue on your own for the rest. Please read the requirements below carefully for the details you need to do in this program. (8 p sts) Requirements: k) Your class should be named SubtractionQuiz, and your java file should be named SubtractionQuiz.java. I) In this question, use the random 0 method in the Math elass to genente two integer random numbers in the range of 0 to 99 to make the subtraction questions. m) The 2nd graders haven't leamed negative numbers yet. So when you make the subtraction questions, please make sure you always use the larger number to minus the smaller number. To do that, you can use a simple IF statement to compare nI and n2. If n2 is greater than nl, we can swap the values in nl and n2using the codes like below in the IF block for true action. No false action or ELSE is needed. int temp =n1;

n1=n2;
n2= temp; So after the IF statement, nl is for sure the larger value, and n2 is the smaller value, and you can always make subtraction question like n1−n2. n) In this program, students will take a 10-question quiz. You must use FOR loop for this question. DO NOT USE THE OTHER TYPES OF LOOP. o) Display the quiz summary at the end of this program, to tell how many question the student got correct out of 10 questions. p) Programming styles are always required.

User Aeran
by
8.4k points

1 Answer

4 votes

Here is a concise Java program for the Three Dice Game:

The Code

import java.util.Random;

public class ThreeDiceGame {

public static void main(String[] args) {

int totalPoints = 0;

int blasts = 0;

Random random = new Random();

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

// Display the face values of three dice

int dice1 = random.nextInt(6) + 1;

int dice2 = random.nextInt(6) + 1;

int dice3 = random.nextInt(6) + 1;

System.out.println("Roll " + (i + 1) + ": Dice 1: " + dice1 + ", Dice 2: " + dice2 + ", Dice 3: " + dice3);

// Decide how to calculate the total points

int sum = dice1 + dice2 + dice3;

// Decide if it's blasted or not

if (dice1 == dice2 && dice2 == dice3) {

blasts++;

System.out.println("Blast! No points earned.");

} else {

totalPoints += sum;

System.out.println("Points earned: " + sum);

}

}

// Display game output

System.out.println("\\Game Output:");

System.out.println("Number of blasts: " + blasts);

System.out.println("Total points earned: " + totalPoints);

}

}

User BooTooMany
by
8.1k points

No related questions found