1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Over [174]
3 years ago
9

Write a game that performs the roll of two dice randomly. The game should first ask for a target sum. Everytime the player enter

s r, the program should repeatedly print the side of the dice on a separate line. The game should stop prompting if one of these two events occur: -The sum of the two sides is equal to the target sum. -The player enters q.
Computers and Technology
1 answer:
Sophie [7]3 years ago
4 0

Answer:

Explanation:

The following program was written in Java. It asks the user to first enter the target sum. Then it creates a while loop that continues asking the user to either roll dice or quit. If they decide to roll, it rolls the dice and prints out both values. If the target sum was hit, it prints that out and exits the program otherwise it loops again. The code has been tested and can be seen in the attached image below.

import java.util.Random;

import java.util.Scanner;

class Brainly {

   public static void main(String[] args) {

       Random rand = new Random();

       Scanner in = new Scanner(System.in);

       System.out.print("Enter Target Sum: ");

       int targetSum = in.nextInt();

       while (true) {

           System.out.println("r: Roll Again");

           System.out.println("q: Quit");

           String choice = in.next();

           char choiceModified = choice.toLowerCase().charAt(0);

           if (choiceModified == 'r') {

               int roll1 = rand.nextInt(6) + 1;

               int roll2 = rand.nextInt(6) + 1;

               int total = roll1 + roll2;

               System.out.println("Dice 1: " + roll1);

               System.out.println("Dice 2: " + roll2);

               if (total == targetSum) {

                   System.out.println("Target Sum of " + targetSum + " hit.");

                   break;

               }

           } else if (choiceModified =='q') {

               break;

           } else {

               System.out.println("Wrong choice");

           }

       }

   }

}

You might be interested in
Which Azure service should you use to correlate events from multiple resources into a centralized repository?
Trava [24]

Answer:

D. Azure Log Analytics

Explanation:

The Azure service we can use when you have to correlate events from more than 1 sources into a repository which is centralized you have to use Azure Log Analytics.

it is a special surrounding for Azure monitor log data.Each workspace has their own repository and configuration.

Hence we conclude that the answer to this question is option D Azure Log Analytics.

6 0
3 years ago
You have recently been hired as the new network administrator for a startup company. The company's network was implemented prior
AleksAgata [21]

Answer: • Physically secure high-value systems

• Identify and document each user on the network

Explanation:

To develop a manageable network plan, the milestones include:

• prepare to document

• mapping network,

• protect your network

• network accessibility

• user access etc...

When identifying ways to protect the network, the tasks that should be completed are:

•®Physically secure high-value systems

• Identify and document each user on the network

4 0
3 years ago
What displays the columns dialog box?
kkurt [141]

More Columns Command displays the Column Dialog Box.  Our column choices aren't limited only to the drop-down menu. Select More Columns at the bottom of the menu so as  to access the Columns dialog box.

3 0
3 years ago
Which are two common methods a laptop uses to get an Internet connection over a cellular network?
Vikentia [17]
Wi-Fi or Tethering.
8 0
3 years ago
Write a program whose input is two integers. Output the first integer and subsequent increments of 10 as long as the value is le
Lubov Fominskaja [6]

Answer:

import java.util.Scanner;

public class TestClock {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       System.out.println("Enter two integer numbers");

       int num1 = in.nextInt();

       int num2 = in.nextInt();

       int newSum=num1+10;

       System.out.println("The first number is "+num1);

       do{

          System.out.println(newSum);

          newSum +=10;

       }while (newSum <=num2);

   }

}

Explanation:

Using Java Programming language

  1. Prompt user for the two inputs and save them as num1 and num2(Using the scanner class)
  2. Create a new Variable newSum = num1+10
  3. Create a do...while loop to continually print the value of newSum, and increment it by 10 while it is less or equal to num2
3 0
3 years ago
Other questions:
  • Why might you need to convert a file to another file type?
    14·1 answer
  • When did project management first emerge as a profession
    6·1 answer
  • Why aren’t white Wall auto tires as wide as they used to be?or why do most cars not have them at all?
    15·1 answer
  • You are most likely to automatically encode information about
    11·1 answer
  • This program will convert a set of temperatures from Fahrenheit to Celsius and Kelvin. Your program will be reading in three dou
    11·1 answer
  • Style of music that originated in New Orleans in the early 1900s
    11·2 answers
  • Suppose you are given a sequence that is described by a formula, starting at index n=0. If you need to change the starting index
    6·1 answer
  • Dash transfers several bits of data together at one time<br>​
    6·1 answer
  • In a program you need to store identification numbers of 5 employees and their weekly gross pay.
    11·1 answer
  • Data is communicated through various input devices true or false​
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!