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
Hitman42 [59]
3 years ago
14

Create a game that rolls two dies (number from 1 to 6 on the side) sequentially for 10 times (use loop). If at least once out of

10 times the sum of two random numbers is equal to 10, you win, else you loose. You will need to get your own method getRandom(int n) that generates a random number, see below (you can modify it as needed), a loop, and IF statement in the loop that checks if a sum of two random numbers is 10 or not.
Please start your program as follows, similar to what we did in class:
import java.util.Random;
public class UseRandom{
//your method getRandom() is here below, n is a range for a random number from 0 to n
public int getRandom(int n)
{
Random r=new Random();
int rand=r.nextInt(n);
return rand;
}
//code continues here, don't forget your main() method inside the class, and making your own object in main() using "new" keyword.
Computers and Technology
1 answer:
Alex73 [517]3 years ago
8 0

Answer:

Explanation:

The following code is written in Java and loops through 10 times. Each time generating 2 random dice rolls. If the sum is 10 it breaks the loop and outputs a "You Win" statement. Otherwise, it outputs "You Lose"

import java.util.Random;

class Brainly {

   public static void main(String[] args) {

       UseRandom useRandom = new UseRandom();

       boolean youWin = false;

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

           int num1 = useRandom.getRandom(6);

           int num2 = useRandom.getRandom(6);

           if ((num1 + num2) == 10) {

               System.out.println("Number 1: " + num1);

               System.out.println("Number 2: " + num2);

               System.out.println("You Win");

               youWin = true;

               break;

           }

       }

       if (youWin == false) {

           System.out.println("You Lose");

       }

   }

}

class UseRandom{

   public int getRandom(int n)

   {

       Random r=new Random();

       int rand=r.nextInt(n);

       return rand;

   }}

You might be interested in
If you want an app to reach the largest possible audience, which two platforms should you use?
Papessa [141]

Android Studio for Android, and Xcode for Apple devices.

6 0
3 years ago
Identify at least two advantages and two disadvantages of using color to visually represent information.
crimeas [40]
Color could be use as a advantage visually representing something ,For example its help identify whats being presented through color depending on the object also if helps reveal its characteristics. The disadvantages are using color to visually representing info could be deceiving and also color has to works efficiently with your other senses to be 100% correct . Hope this helps 
6 0
3 years ago
How do you get a free ps4
KatRina [158]

Answer:

By having very good luck and winning it in a giveaway!!!

4 0
3 years ago
Read 2 more answers
Which item below is NOT output? A. monitor B. speakers C. printer D. mouse
Molodets [167]
D. mouse that is  your answer <span />
6 0
4 years ago
Read 2 more answers
What is JavaScript? JavaScript is a _____ language.
disa [49]

Answer: dynamic computer language

Explanation:

JavaScript is a dynamic computer language. Hope this helps! (•‿•)

5 0
3 years ago
Read 2 more answers
Other questions:
  • Horizontal lines should be avoided in photographs t/f
    5·1 answer
  • Oxygen-18 has an atomic number of 8. How many neutrons are in this isotope?
    7·1 answer
  • Where can I watch infinity war for free?
    9·1 answer
  • Referential integrity states that:______.
    15·1 answer
  • An inventory clerk, using a computer terminal, views the following on screen: part number, part description, quantity on hand, q
    8·1 answer
  • In 2000, operating a basic internet application cost businesses approximately _____ per month. In mid-2016, operating the same a
    10·1 answer
  • From which of the following locations can you run a single line of the program?
    12·1 answer
  • You are reviewing the output of the show interfaces command for the Gi0/1 interface on a switch. You notice a significant number
    12·1 answer
  • Part B - Find the solutions for the following Case Study Real World Problems by applying the appropriate concepts that you learn
    5·1 answer
  • (e) The entries in each column of the array A are sorted into strictly increasing order.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!