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
Your assignment is to write an assembly language program which read a string and print it in uppercase. This program asks the us
-BARSIC- [3]

Answer:

Check the explanation

Explanation:

.data

prompt: .asciiz "Please enter your string :"

result_str: .asciiz "\nYour captalized string :"

error_prompt: .asciiz "\nInvalid Entry !"

buffer: .space 20

.text

.globl __start

__start:

ASKING_STR:

la $a0,prompt

li $v0,4

syscall

li $v0,8 #take in input

la $a0, buffer #load byte space into address

li $a1, 20 # allot the byte space for string

move $t0,$a0 #save string to t0

syscall

li $v0, 4

li $t0, 0

loop:

lb $t1, buffer($t0)

beq $t1, 0, exit

slti $t2,$t1,91

bne $t2,$0,UPPER_CHECK

slti $t2,$t1,123

bne $t2,$0,LOWER_TO_UPPER

UPPER_CHECK:

slti $t2,$t1,65

bne $t2,$0,INVALID_ENTRY

slti $t2,$t1,90

bne $t2,$0,NEXT

j INVALID_ENTRY

LOWER_TO_UPPER:

sub $t1, $t1, 32

sb $t1, buffer($t0)

NEXT:

addi $t0, $t0, 1

j loop

INVALID_ENTRY:

li $v0, 4

la $a0, error_prompt

syscall

j ASKING_STR

exit:

li $v0, 4

la $a0, result_str

syscall

li $v0, 4

la $a0, buffer

syscall

li $v0, 10

syscall

4 0
3 years ago
Explain the nature of documents that can be suitable for mergin
sveta [45]
Asldfjasjdkflajfasjdf;laksjdf;kljas
5 0
3 years ago
Write the definition of a class clock. the class has no constructors and three instance variables. one is of type int called hou
expeople1 [14]
<span>The definition of a class clock. the class has no constructors and three instance variables. one is of type int called hours, initialized to 12, another is of type boolean called isticking, and the last one is of type integer called diff. 
</span><span>
public class Clock

{private int hours = 12;
private boolean isTicking;
private Integer diff;}</span>
4 0
2 years ago
How to get out of compatibility mode in word?
fomenos
Compatibility mode is so older or different versions of word all look the same regardless of its current version.  So a lot of features you see in compatibility mode will be unavailable unless you upgrade.  If you upgrade though be sure to uninstall the older version first.  I hope this helped!!! Good Luck! :)
5 0
3 years ago
In today's society, unethical actions are: A) Easier than ever to get away with, because the general public and insurers are les
ra1l [238]
B I think is the best answer
7 0
3 years ago
Read 2 more answers
Other questions:
  • Before responding to an e-mail from another student in an online course, a student should
    13·2 answers
  • During the past decade ocean levels have been rising faster than in the past, an average of approximately 3.1 millimeters per ye
    14·1 answer
  • Behaving in an acceptable manner within a workplace environment is referred to as having
    9·1 answer
  • You disassemble and reassemble a desktop computer. when you first turn it on, you see no lights and hear no sounds. nothing appe
    11·2 answers
  • Access Control can be defined as putting controls (or countermeasures) in place to help achieve information security goals. Whic
    13·2 answers
  • We will pass in 2 values, X and Y. You should calculate XY XY and output only the final result. You will probably know that XY X
    13·1 answer
  • What safety feature melts to protect a circuit? a. fuse b. diode c. three-prong plug d. transistor
    10·2 answers
  • Write a function to output an array of ints on a single line. Funtion Should take an array and an array length and return a void
    9·1 answer
  • How has technology impacted our lives and the world we live in? In your own words.
    9·1 answer
  • The technique helps you explore possible risks by providing access to risk areas identified in the past. It also provides the so
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!