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
Alex17521 [72]
2 years ago
10

Write a user input program that simulates a game of a rolling pair of dice. You can create/simulate rolling one die by choosing

one of the integers values of 1, 2, 3, 4, 5, or 6 at randomly. The number that the user chooses will represents the number on the dice after it is rolled. As a hint use Math.random Which will perform the computation to select a random integer between 1 and 6. Assign the value to a variable to represent one of the dice that are being rolled. Perform this operation twice then you will add the results in order to obtain the total roll. Your program should output the number showing on each dice as well as the total roll. For example:
Computers and Technology
1 answer:
balu736 [363]2 years ago
6 0

Answer:

Follows are the program to this question:

public class Main//defining a class  

{

  public static void main(String[] bax)//main method

  {

       int d1,d2,r;   //defining integer variables  

       d1 = (int)(Math.random()*6) + 1;//defining d1 variables that use random method to store a random value  

       d2 = (int)(Math.random()*6) + 1;//defining d2 variables that use random method to store a random value

       r= d1 + d2;//defining r variable that adds d1 and d2 values

       System.out.println("On the first time die will gives: " + d1);//print values with the message

       System.out.println("On the second time die will gives: " + d2);//print values with the message

       System.out.println("The total roll value is: " + r);//print values with the message

   }  

}  

Output:

On the first time die will gives: 6

On the second time die will gives: 1

The total roll value is: 7

Explanation:

In this code three integer variable "d1,d2, and r" is declared, in which the "d1 and d2" variable is used, that uses the random method to hold a random value from 1 to 6 in its variable.

In the next step "r" variable is declared that calculates the addition of the "d1 and d2", and at the last, it uses the print method to print value with the message.  

You might be interested in
1D Array Assignment Outcome: Student will demonstrate the ability to use a one-dimensional array. Student will demonstrate the a
sukhopar [10]

Answer:

Program to this question as follows:

program:

import java.util.*; //import package for user input

public class Main  //defining class  

{

public static void main(String[] as)//defining main function

{//defining integer array

int [] num = new int[113];  

boolean find_in = false; //defining boolean variable

int [] counts = new int[101];//defining integer array

int y, tem = 0, counter = 0,in=0,x,find; //defining integer variable

Scanner ox= new Scanner(System.in); //creating Scanner class Object

while(counter <= 112) //loop to check condition

{

num[counter++] = generateRandomNumber(); //using array to hold random function value.  

}

System.out.println("The array:"); //message

for(x = 0; x < 112; x++) // loop to count the value

{

if(x != 0 && x % 9 == 0) // if block to chek value

System.out.println(); // print  

else

System.out.print(num[x] + " "); // print array

}

// sort in ascending order

Arrays.sort(num); //using sort method

System.out.print("\n\nThe array in sorted order:"); // print value

for( x = 0; x < num.length; x++) // loop uses if block to check value is divisiable by 9  

{

if(x % 9 == 0) //check condition  

System.out.println(); // print  

else

System.out.print(num[x] + " "); // print array

}

// search for a number

System.out.print("\n\nEnter a number to search: "); // print message

find= ox.nextInt(); // input number by user

for(x= 0;x< num.length;x++) //loop to count values

{

if(num[x] == find) //check value

{

find_in = true; //change value

in= x;

break; //using break keyword

}

}

if(find_in)  //find value

System.out.println(find + " is found at index " + in); // print location

else

System.out.println("Not found"); //message

// display count of each numbers

System.out.println("Count of each numbers:"); //message

for(y = 1; y< num.length; y++) // loop to store element in counts array  

{

tem = num[y]; //hold value

counts[tem]++; //increment value

}

for(x = 1; x< counts.length; x++) //loop to print value

{

System.out.println(x + ": " + counts[x]); // print value

}

// average of the numbers in the array

for(x = 0; x < num.length; x++) // loop to calculate sum and average

{

sum += num[x]; //calculate sum

}

avg = (sum / 100); // calculate avg

System.out.println("\nThe average of the numbers in the array: " + avg);

// highest number in the array

int high= num[0]; //find number

for(x= 0;x < num.length;x++)

{

if(num[x] > high)

high = num[x]; //hold value of highest Number

}

System.out.println("\nThe highest number is: " + high); //print value

int low = num[0]; // defining variable for lowest number

for(x= 0; x < num.length - 1; x++) // loop to calculate lowest number

{

if(num[x] < low) //condition for lowest number

low = num[x]; //hold lowest number

}

System.out.println("\nThe lowest number is: " + low); //print value

}

public static int generateRandomNumber() //defining function  

{

Random ra = new Random(); //creating Random function Object

return (ra.nextInt(100)+ 1); //input and return value

}

}

Output:

the output of the given code is display in image

Explanation:

In the above program, an array is declared that uses a random function to input the number, in the next step the sort function is used, that sorted all array elements, in the next step the scanner class is used, that input the number form the user ends and pass search in the sorted array.

  • After searching the average of array elements is calculated. In this array we calculate the highest and lowest number of the array to print all the values the print method is used.
  • At the last, the rand method is used that generates the random number for the array and passes into a num array that prints the values.

7 0
3 years ago
I.d 9934607467<br> p.a.s.s 54321<br><br> P.L.E.A.S.E J.O.I.N. Z.O.0.M. M.E.E.T.I.N.G
dusya [7]

Answer:

You could just go to social medIa to say j.o.i.n z.o.o.m not brainly mate

7 0
3 years ago
Which of the following is NOT true about a flow chart?
SCORPION-xisa [38]
I think the answer is A
4 0
3 years ago
Write the code to compute and output how many times the value 99 is found in an array of integers named numbers
astraxan [27]
Thank you for being the rare question where you actually provide what language you want your answer in; I approve, and encourage this.

In Java, the following will work.
I made it a bit more versatile to work with others numbers, other than 99, if you so please (if not, just hardcode the 99 in yourself).

// Example list - fill this with numbers yourself.
ArrayList<Integer> nums = new ArrayList<>();
int n = 99;
int count = (int)nums.stream().filter(i -> i == n).count();
System.out.println(n + " occurences.");
8 0
3 years ago
Can you withdraw from courses in top hat?
ad-work [718]

Answer:

Yes, but this must be done before the withdraw deadline

Explanation:

TopHat is an online learning platform. Students register for courses and if they decide not to continue with a course for reasons best known to them, they are allowed a time period usually one to two weeks to drop the courses. They are then reimbursed the fee for that particular course.

But if that time period elapses and they drop the course, that is considered a withdrawal that is not accepted and which no provisions for reimbursements are made.

7 0
2 years ago
Other questions:
  • Write a program in C++ or C that includes two different enumeration types and has a significant number of operations using the e
    15·1 answer
  • Describe two types of storage devices?​
    15·1 answer
  • A business that helps people find jobs for a fee
    12·1 answer
  • FlimFlam.Shop is the best clothing shop ever.
    9·2 answers
  • Which of the following technologies is an example of social media
    12·1 answer
  • Why would over-50 executives have a harder time buying into the idea of social media?​
    15·1 answer
  • How to test someone elese internet speed from a distance
    15·1 answer
  • How many 60 KB jpeg files can be stored on a 2 MB folder in your hard drive?​
    7·1 answer
  • An end-user license agreement protects _____.
    11·1 answer
  • Why do relational databases use primary keys and foreign keys?.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!