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
Phishing is a broad term that describes any program that is designed to cause harm or transmit information to others without the
katrin [286]
False phishing is the fraudulent practice of sending emails purporting to be from reputable companies in order to induce individuals to reveal personal information, such as passwords and credit card numbers.
6 0
4 years ago
Marty uses a customized database to sort parts and track inventory. The customized database is an example of _____.
Alexeev081 [22]

cataloging is a term for that

5 0
3 years ago
What will the following segment of code output?
Elanso [62]

Answer:

"You passed the test!"

Explanation:

Here user reading grade "test_score" and  checking the student score in "If" condition. If it is less than 60 we are printing "You failed the test!" and if it is >60 we are outputting the string  "You passed the test!" and else if it not satisfying any of these then we are printing "You need to study for the next test!".As "test_score" value is 90 which is >60 it satisfies the condition >60. So we are printing the string "You passed the test!"

8 0
3 years ago
What is done when Python complies your program
alexgriva [62]

Answer:

It makes

Explanation:

it run the program

4 0
3 years ago
Read 2 more answers
In c++
Elodia [21]

Answer:

class studentType: public personType

{

public:

virtual void print() = 0;

virtual void calculateGPA() = 0;

void setID(long id) {

studentId = id;

}

void setCourses(const string c[], int noOfC) {

noOfCourses = noOfC;

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

courses[i] = c[i];

}

}

void setGrades(const char cG[], int noOfC) {

noOfCourses = noOfC;

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

coursesGrade[i] = cG[i];

}

}

long getID() {

return studentId;

}

string* getCourses() {

return courses;

}

char* getGrades() {

return coursesGrade;

}

studentType(string fName = "", string lastName = "",

long id = 0, string c[] = NULL, char cG[] = NULL, int noOfC = 0);

private:

long studentId;

string courses[6];

char coursesGrade[6];

int noOfCourses;

};

Explanation:

Code rewritten

5 0
3 years ago
Other questions:
  • Suppose that cells B1 through B100 of an Excel spreadsheet contain the quantity of units ordered on each of 100 different days.
    13·1 answer
  • What happens when the computer is thrashing? quizzlet?
    12·1 answer
  • Suppose two hosts, A and B, are separated by 15,000 kilometers and are connected by a direct link of R = 5 Mbps. Suppose the pro
    11·1 answer
  • HURRY!! Ill give brainily and 25 points. Describe how Scent is related to the culture and historical period when it was created.
    15·1 answer
  • How does emotional awareness help you with non-verbal communication?
    13·2 answers
  • The students of a college have to create their assignment reports using a word processing program. Some of the questions in thei
    9·1 answer
  • Cuantos MB son 8,192 kb?​
    13·1 answer
  • How many different textile items would you find at a festival? (please list 5 items)
    7·1 answer
  • Running away from home
    11·2 answers
  • A computer is defined by 4 specific criteri. Select all 4.*
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!