What is the constructors

Assignment Help Programming Languages
Reference no: EM131476646

Question: The following is a short snippet of code that simulates rolling a 6-sided dice 100 times.

There is an equal chance of rolling any digit from 1 to 6.

public static void printDiceRolls(Random randGenerator)

{

for ( int i = 0; i

{

System.out.println(randGenerator.nextInt(6) + 1);

}

}

public static void main(String[] args)

{

Random randGenerator = new Random();

printDiceRolls(randGenerator);

}

Create your own class, LoadedDice , that is derived from Random . The constructor for LoadedDice needs to only invoke Random 's constructor. Override the public int nextInt(int num) method so that with a 50% chance, your new method always returns the largest number possible (i.e., num - 1), and with a 50% chance, it returns what Random 's nextInt method would return.

Test your class by replacing the main method with the following:

LoadedDice myDice = new LoadedDice();

printDiceRolls(myDice);

You do not need to change the printDiceRolls method even though it takes a parameter of type Random . Polymorphism tells Java to invoke LoadedDice 's nextInt() method instead of Random 's nextInt() method.

Reference no: EM131476646

Questions Cloud

Examine the theoretical constructs of hrm : Analyze the external environmental factors that impact human resource policies and procedures.Examine the theoretical constructs of human resource management.
Draw a straight line at a desired temperature : CME1026. Provide a checkbox to give the user an ability to draw a straight line at a desired temperature in order to estimate the solubility of the selected gas
Acquisition of capital equipment and business services : Discuss the basic differences between the acquisition of capital equipment and business services. What are the salient characteristics of each?
Explain incident where individual had to solve a problem : Explain one incident where this individual had to solve a difficult problem or situation because things did not go as planned. What lessons did they learn.
What is the constructors : The following is a short snippet of code that simulates rolling a 6-sided dice 100 times.
Consider the effects of outsourcing : Consider the effects of outsourcing. Describe an organization that has experienced success with outsourcing and describe an organization
Sourcing process of supplies and services : How does the sourcing process of equipment differ for the sourcing process of supplies and services?
Describe why the given study is important : Describe why this study is important. State the experimental design of your study, the independent and dependent variables.
Define all goals according to the requirements : The goal for this programming project is to create a simple 2D predator-prey simulation. In this simulation, the prey is ants, and the predators are doodlebugs.

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd