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
DanielleElmas [232]
3 years ago
13

Write a program that simulates rolling one die using the following steps: 1. Prompt the user for the number of sides on the die.

2. "Roll" the die three times by generating a random number between 1 and the number of sides (inclusive). 3. Keep track of the running sum of the rolls for the die and output the sum and average for the three rolls at the end. 4. You can set up one integer variable named roll and reuse it with each roll of the die. You will also need a variable named total, initialized to zero.
Computers and Technology
1 answer:
Mashcka [7]3 years ago
7 0

Answer:

The program to the given question can be given as:

Program:

//import package.

import java.util.*;                    

//define class.

public class Main                    

{

 public static void main(String ar[])  //define main method.  

 {

Scanner  ob = new Scanner(System.in);     //creating scanner class object.

   Random ran = new Random();                 //creating random class object.

   int roll1,roll2,roll3,number,total=0;          //define variable.

   float avg=0;

   System.out.print("Enter the sides= ");           //print message.

   number = scanner.nextInt();                 //input number by user.

   roll1 = ran.nextInt(number++);         //using random function.

   roll2 = ran.nextInt(number++);

   roll3 = ran.nextInt(number++);

   System.out.print("First roll= ");           //print message

   System.out.println(roll1);               //print value.

   System.out.print("Second roll= ");

   System.out.println(roll2);

   System.out.print("Third roll= ");

   System.out.println(roll3);

   System.out.print("total roll= ");

   total=roll1+roll2+roll3;                            //add all number.

   System.out.println(total);

   System.out.print("Average roll= ");                      

   avg=total/3;                                 //Average of the number.

   System.out.println(avg);

 }

}

Output:

Enter the sides= 4

First roll= 2

Second roll= 3

Third roll= 5

total roll= 10

Average roll= 3.0

Explanation:

In the above program first, we import the package form the user input and random number. In java, there are many packages but we use only the util package because in that package both the class like scanner class and random class are inbuilt. Then we declare the class that name is Main in that class we define the main function. In the main function, we create both class object (scanner class and random class). Then we take input a number from the user and pass into the random function. The random function is used to give a unique number and we pass the number into the random function that is increasing by post-increment operator i.e (X++). Then we print all the rolls and total by add all the roll and at the last, we print an average of it.

You might be interested in
Write a program that asks the user to enter two numbers,obtains the two numbers from the user and prints the sum,product,
Andru [333]

Answer:

#include<iostream>

using namespace std;

//main function

int main(){

   //initialization

   float a1,a2;

//display the message

cout<<"Enter the first number: ";

   cin>>a1;  //store the value

   cout<<"Enter the second number: ";

   cin>>a2;   //store the value

   //display the calculation result

   cout<<"The sum is: "<<a1+a2<<endl;

   cout<<"The Subtraction is: "<<a1-a2<<endl;

   cout<<"The product is: "<<a1*a2<<endl;

   cout<<"The Quotient is: "<<a1/a2<<endl;

}

Explanation:

Create the main function and declare the two variables of float but we can enter the integer as well.

display the message on the screen and then store the input enter by the user into the variable using the cin instruction.

the same process for second input as well, display the message and store the input.

after that, print the output of the calculation. the operator '+' is used to add the two numbers like a1+a2, it adds the number stored in the variable.

similarly, the subtraction operator is '-', product '*' and quotient operator '/'.

and finally, we get the desired output.

4 0
3 years ago
Which situations are most likey to use Telehealth
Scilla [17]

Answer:

Emergency situations that make it difficult to go to a clinic will likely require Telehealth. Examples include cases of

1. heart attack

2. breathing difficulties

3. health challenges that begin in the night

4. onset of child labor

5. a pandemic situation where hospitals are filled up

6. sickness among aged people in rural communities with no clinic, etc.

Explanation:

Summarily, the World Health Organization (WHO) defines Telehealth as the 'incorporation of Information Communication Technology in the delivery of health care services in situations where patients and health care providers are separated by distance'. Emergency health situations that make it difficult to quickly access medical help can benefit from Telehealth.

In the cases of a pandemic such as the one experienced in 2020, where hospitals were filled to the brim, telehealth proved to be a useful form of health care delivery.

4 0
3 years ago
Hello, can you help me answer these questions?
Anna35 [415]

Answer:

Ans 1.To connect to the Internet and other computers on a network, a computer must have a NIC (network interface card) installed. A network cable plugged into the NIC on one end and plugged into a cable modem, DSL modem, router, or switch can allow a computer to access the Internet and connect to other computers.

Ans 2.Data travels across the internet in packets. Each packet can carry a maximum of 1,500 bytes. ... When you send an e-mail to someone, the message breaks up into packets that travel across the network. Different packets from the same message don't have to follow the same path.

Ans 3.protocol is a set of rules that governs the communications between computers on a network. A network protocol defines rules and conventions for communication between network devices.

Ans3 A protocol is a set of rules that governs the communications between computers on a network. A network protocol defines rules and conventions for communication between network devices.

Hope this fine

<h2>Pls Make me a brainlest </h2>
8 0
4 years ago
Read 2 more answers
The data components of a class that belong to every instantiated object are the class's ____ variables.
ryzh [129]
The data components of a class that belong to every instantiated object are the class's Instance variables.
7 0
3 years ago
Read 2 more answers
Write a static method called bothStart that allows the user to input two Strings and returns the String that is the longest subs
marishachu [46]

Answer:

  1.    public static String bothStart(String text1, String text2){
  2.        String s = "";
  3.        if(text1.length() > text2.length()) {
  4.            for (int i = 0; i < text2.length(); i++) {
  5.                if (text1.charAt(i) == text2.charAt(i)) {
  6.                    s += text1.charAt(i);
  7.                }else{
  8.                    break;
  9.                }
  10.            }
  11.            return s;
  12.        }else{
  13.            for (int i = 0; i < text1.length(); i++) {
  14.                if (text1.charAt(i) == text2.charAt(i)) {
  15.                    s += text1.charAt(i);
  16.                }else{
  17.                    break;
  18.                }
  19.            }
  20.            return s;
  21.        }
  22.    }

Explanation:

Let's start with creating a static method <em>bothStart()</em> with two String type parameters, <em>text1 </em>&<em> text2</em> (Line 1).  

<em />

Create a String type variable, <em>s,</em> which will hold the value of the longest substring that both inputs start with the same character (Line 2).

There are two possible situation here: either <em>text1 </em>longer than<em> text2 </em>or vice versa. Hence, we need to create if-else statements to handle these two position conditions (Line 4 & Line 13).

If the length of<em> text1</em> is longer than <em>text2</em>, the for-loop should only traverse both of strings up to the length of the <em>text2 </em>(Line 5). Within the for-loop, we can use<em> charAt()</em> method to extract individual character from the<em> text1</em> & <em>text2 </em>and compare with each other (Line 15). If they are matched, the character should be joined with the string s (Line 16). If not, break the loop.

The program logic from (Line 14 - 20) is similar to the code segment above (Line 4 -12) except for-loop traverse up to the length of <em>text1 .</em>

<em />

At the end, return the s as output (Line 21).

5 0
3 years ago
Other questions:
  • Data about the size and composition of a population are gathered in a survey called _____.
    6·2 answers
  • Now, my Laptop has been working since I bought it yesterday it won’t start up and it when it does it overheats and shuts off, th
    10·2 answers
  • Windows on the desktop are just one of many objects used in a graphical user interface (GUI)-- buttons, drop-down list boxes, po
    7·1 answer
  • I need help making this table in html code I have some of chart done but idk where to go after the 6:30pm part
    13·1 answer
  • The best way to insert an existing Excel chart into a document is to
    12·2 answers
  • What is blockchain? How it works? I heard bitcoin uses it.
    8·1 answer
  • explain the following with regard to a microcomputer. 1)program 2)stored program concept 3)instruction decoder
    5·1 answer
  • The number of bytes in an array is always a multiple of the number of ____ in an array.
    6·1 answer
  • Which of the following was (and still is) used by computer programmers as a first test program?
    13·2 answers
  • Computing is the provision of IT services on demand.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!