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
How to do the for loop in python
shusha [124]

Answer:

To loop through a set of code a specified number of times, we can use the range() function, The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and ends at a specified number.

Explanation:

hope this helps

8 0
3 years ago
_____ is a form of witty, amusing speech that is often used to bring people together.
Neporo4naja [7]

Answer:Informative

Explanation:

5 0
3 years ago
Read 2 more answers
When you save a drawing using paint, it's automatically stored as a?
serious [3.7K]

Answer:

Bitmap File

Explanation:

6 0
3 years ago
When you use the mvc pattern for a java web application, you often add ________________________ to the request object before you
aivan3 [116]
Hi,

JVM - Java Virtual Machine

Hope this helps.
r3t40
6 0
3 years ago
WILL MARK YOU BRAINLIEST :
valkas [14]

CodeHS is an interactive online learning platform offering computer science and programming instruction for schools and individual learners.

CodeHS is focused on spreading access to and knowledge of computer science by offering online instructional materials supported by remote tutors.

Explanation:

Downloading an image from a website on the internet.

  • Right-click the image.
  • Choose the command Save Picture As. The command might be different in browsers other than Internet Explorer.
  • Use the Save Picture dialog box to find a location to save the picture. You can rename the picture as it's saved to your computer's storage system
  • Click the Save button.

Download an image of Karel the dog from the URL

  • Create a folder in your laptop
  • Place your text file of images URL in the folder.
  • cd to that folder.
  • Use wget -i images.txt.
  • You will find all your downloaded files in the folder.

How your computer finds the CodeHS server, requests information from the server, and receives it.

  • When you enter an URL into the address bar of browser, browser will send the domain to a server call DNS to convert the domain into IP address.
  • For example: google dot com will be convert into 113.171.253.224
  • Next, the browser will send your request to that IP.
  • All your sent data will be divided into packages, each package contains your IP address.
  • That is the reason why server know who it will send the response.
3 0
3 years ago
Other questions:
  • What are multiple worksheets
    7·1 answer
  • Write multiple if statements. if caryear is 1969 or earlier, print "probably has few safety features." if 1970 or higher, print
    6·1 answer
  • Which option describes the purpose of configuring native supplicant profile on the cisco ise?
    7·1 answer
  • Google’s adwords system provides a quality score as a measure of _____, which indicates the usefulness of an ad message to consu
    6·1 answer
  • Complete the body of the decrement static method using only the NaturalNumberKernel methods (multiplyBy10, divideBy10, and isZer
    10·1 answer
  • What type of machine is a hand drill?<br><br> A. Simple machine <br> B. Compound machine
    8·2 answers
  • 20 POINTS AND BRAINLIEST TO CORRECT ANSWER
    15·2 answers
  • According to the video, what are some concerns of Webmasters? Check all that apply.
    7·2 answers
  • The New option is found in the ...............tab.​
    6·2 answers
  • The FCFS algorithm is particularly troublesome for ____________.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!