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
Is megan the stallion hot
astraxan [27]

Answer:

Explanation:

Cool

8 0
3 years ago
Read 2 more answers
Taking an online class doesn't require any special skills.
mr_godi [17]

Answer:

F

Explanation:

It depends on whether the person has interest in it

5 0
3 years ago
Read 2 more answers
Two forms of compression are lossy and lossless. State giving reasons which
Helen [10]

Answer:

(i) When transmitting a draft manuscript for a book, the lossless compression technique is most suitable because after decompression, the data is rebuilt and restored in its form as it was from where it originated

(ii) When transmitting a video recording which you have made of the school play, a lossy compression technique is most suitable because the large size of video files require the increased data carrying capacity which is provided by the lossy transmission technique. The quality of the video can be reduced without affecting the message intended to be delivered

Explanation:

4 0
2 years ago
The _____ option will allow a user to remove text from one location and keep it for use later on the clipboard.
ValentinkaMS [17]

I believe the answer is the "cut" option?

8 0
3 years ago
Provide the definition of an abstract class named DesktopComponent that contains the following:
Bess [88]

package mypackage; // Whatever package this should be in.

public abstract class DesktopComponent {

   

   private String type;

   // Alternatively you may want a final variable.

   // private final String type;

   

   public DesktopComponent(String type)

   {

       this.type = type;

   }

   

   abstract void onClick();

   

   

 

}

7 0
3 years ago
Other questions:
  • Does anyone have any social media message me
    14·1 answer
  • This activity will help you meet these educational goals:
    7·2 answers
  • 17) you need to locate an article that (1) is published by a university or proffessional association(2) is authored by clearly d
    6·1 answer
  • Describe how one can change row and height
    6·1 answer
  • What is a Hard Drive
    13·1 answer
  • Before performing a Web Recorder task, which two options should the user ensure are setup correctly?
    6·2 answers
  • PLZ HELP! ANSWER (WITH CORRECT ANSWER AND EXPLANATION THAT ACTUALLY IS CORRECT) GETS BRAINLIEST!
    13·1 answer
  • Please answer my question y'all!
    6·2 answers
  • WILL GIVE BRAINLIEST! The command simplify is used if you only want the first two digits of a decimal to appear in the interpret
    13·1 answer
  • Every windows service has the 3 start types what are those service types?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!