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
lesantik [10]
3 years ago
7

Implement a class called PairOfDice, composed of two Die objects. Include methods to set and get the individual die values, a me

thod to roll the dice, and a method that returns the current sum of the two die values.Create a driver class called RollingDice2 to instantiate and use a PairOfDice object. The final program should have a main method or a test class.
Computers and Technology
1 answer:
bagirrra123 [75]3 years ago
8 0

Answer:

The java program to implement the given scenario is shown below. Comments are included at all places.

import java.util.*;

class PairOfDice

{

//variables to hold all required values

static int dice1, dice2;

static int min=1;

static int max=6;

//setter for two dice values

static void setFirstValue(int d1)

{

dice1 = d1;

}

static void setSecondValue(int d2)

{

dice2 = d2;

}

//getters for two dice values

static int getFirstValue()

{

return dice1;

}

static int getSecondValue()

{

return dice2;

}

//method to roll dice using random() method

static void rollDice()

{

int d1 =(int) ( (Math.random() * ((max - min) + 1)) + min);

int d2 = (int)( (Math.random() * ((max - min) + 1)) + min);

//randomly generated values passed to the setters

setFirstValue(d1);

setSecondValue(d2);

}

//method to return sum of two dice values

static int sumDice()

{

rollDice();

//getters called to get the two dice values to compute their sum

return getFirstValue() + getSecondValue();

//return dice1+dice2;

}

}

public class RollingDice2

{

public static void main(String[] args)

{

//first object

PairOfDice ob1 = new PairOfDice();

System.out.println("First object: Sum of two die values is " +ob1.sumDice());

//second object

PairOfDice ob2 = new PairOfDice();

System.out.println("Second object: Sum of two die values is " +ob2.sumDice());

}

}

OUTPUT

First object: Sum of two die values is 8

Second object: Sum of two die values is 6

Explanation:

1. All the variables and methods are declared as static.

2. Inside the rollDice() method, the values of both the dice are generated randomly using random() method.

3. The generated values are passed to the setter methods.

4. Inside the sumDice() method, first, rollDice() method is called which generates dice values and calls setter methods.

5. Next, getter methods are called for obtaining the dice values. These values are added and returned without using any variable.

6. Inside main(), two objects of the class PairOfDice are created and respective sum of dice values are displayed to the user.

You might be interested in
The act of illegally copying software, music,or movies that are copied protect?
miv72 [106K]
It’s protects piracy C
4 0
3 years ago
Read 2 more answers
Which software documentation guideline did the IEEE establish?
Tomtit [17]

Answer:

B

Explanation:

I am big brain

8 0
3 years ago
ROE: what does this represent (in plain terms)? In what range would this number typically be? What type of person/position would
LuckyWell [14K]

Answer:

<em>The ROE in plain terms is called  the return on equity (ROE) is a measure of inflow of profit in business in relation to the equity, also known as assets net worth  or assets of liabilities  ROE is a method  of how l  company generate earnings through investment </em>

Explanation:

<em>The ROE in plain terms is called  the return on equity (ROE) is a measure of inflow of profit in business in relation to the equity, also known as assets net worth  or assets of liabilities  ROE is a method  of how l  company generate earnings through investment </em>

<em>The ROE range number can be of any value or percentage example 15% upwards</em>

<em>The type of person or position with roles to play are usually a professional, such as an accountant, bookkeeper, or payroll processor, who completes ROEs on behalf of your clients in the organisation.</em>

4 0
4 years ago
SYN scanning is a tactic that a malicious hacker (or cracker) can use to determine the state of a communications port without es
Mashutka [201]

Answer:

A closed port that can not receive request from authorized users.

Explanation:

Networks comprises of end devices, routing and switching devices, servers, technical control devices etc. The communication and interconnection of these devices makes up a secure and resourceful network.

Attackers can exploit loopholes in networks to steal information. The attackers uses the SYN scanning or cracking technique to implement the DOS or denial of service attack.

DOS is used to flood ports on a server in a network, preventing authorized user access, as they steal information to avoid detection.

8 0
4 years ago
What does a first line indent look like
algol13
If u mean the indent when you’re writing an essay, then it is an indent to show how u separate the paragraphs. Hope this helps.
5 0
3 years ago
Other questions:
  • Which type of computer is the best? laptop, tablet, or desktop
    15·2 answers
  • A computer supply company is located in a building with three wireless networks.
    10·1 answer
  • You need to install an operating system on a computer that will be sharing files for the company employees. You estimate there w
    9·1 answer
  • MULTIPLE CHOICE:
    15·1 answer
  • How did you generate a random number for the user to guess?
    9·1 answer
  • What is the use of technology to enable people to learn anytime and anywhere​
    13·1 answer
  • How should work be allocated to the team in a Scrum project?
    13·1 answer
  • To excel at these professions, you need to be able to combine an eye for elegant design with a mind that delights in efficient o
    8·1 answer
  • Write a program named as reverse.c that reads a message, then prints the reversal of the message. The output of the program shou
    7·1 answer
  • How can you distinguish between a manually added page break and an automatic page break in a worksheet?.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!