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
What do we call the input and output devices that are connected externally to the computer?
Anna35 [415]

Explanation:

computer peripheral is an external device that provides input and output for the computer. for example keyboard and mouse are input peripherals while mouse and printer are output peripherals...

5 0
3 years ago
Read 2 more answers
When using NAND gate instead of NOR gate in SR flip-flop, Q and Q’ both become one when?
Anika [276]

Answer:

  S and R both are 0

Explanation:

A <em>0</em> at the input of a NAND gate causes its output to be <em>1</em>. There is no other logic between the output NAND gate and the S or R inputs, so both inputs 0 will make both outputs 1.

4 0
4 years ago
Nick won a $1,000 lottery prize. He can't decide what he should spend the money on. For some time now, he has been planning to b
miv72 [106K]
The opportunity cost is the full cost of the trip
4 0
3 years ago
Write a program that asks the user to enter a number of seconds and then printsthe same amount of time in days, hours, minutes,
MariettaO [177]

Answer:3363 seconds

Explanation:3363 is equivalent to 0days 1 hour, 1 min, and 7 sec

8 0
3 years ago
Use the nutrition label to determine how many calories would be consumed by drinking 1 liter of Mountain Dew.
Rus_ich [418]
1 liter of mountain dew is 170 calories
4 0
3 years ago
Read 2 more answers
Other questions:
  • What must you do when you save a file for the first time
    7·2 answers
  • 3. The combination of keys that we should press to select all document is
    14·1 answer
  • The false reject rate describes the number of legitimate users who are denied access because of a failure in the biometric devic
    11·1 answer
  • Ms. Myers commented that _____ she slept in at the hotel was better than _____ she slept in at home.
    7·1 answer
  • which internet technology allows businesses to make presentation and share visual aids such as charts and graphs
    14·2 answers
  • Difference between Hard copy and Soft copy?​
    13·1 answer
  • In this first journal assignment, you will explore the role of testing in the SDLC. You will explain the role and importance of
    9·1 answer
  • Which search phrase is the most effective to find out about the most popular pizza chains worldwide in 2019?
    9·2 answers
  • Compare and contrats the vain digestive system from the human digestive system.​
    10·1 answer
  • What does the computer receive when you press a key on a laptop keyboard?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!