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

  Build a student record managing system application

Build a student record managing system application

  Your english instructor realizing you are a programmer asks

your english instructor realizing you are a programmer asks you to write a grade book program for his class to help

  Write a c api program under mysql to solve database query

In earlier assignment, we created a database with the following three relation schemes, where the data type for the attributes s and p is Varchar(10) under the SQL-standard, the data type of the attribute c is Char(6) and the attribute sec is of type..

  List comprehension to return a list of all the numbers

Write a higher order function list To that takes a function f and a number n and uses list comprehension to return a list of all the numbers from 1 to n for which the function fevaluates to True.

  Determine total cost of order-display it in alert dialog box

After you determine the total cost of the order (purchase plus shipping and handling), display it in an alert dialog box.

  Write the function array_dup

Write the function array_dup(n, obj) that returns an array containing n copies of obj - Write a function count_occurrences(a, obj) that counts the number of items in array a that are equal to obj.

  Write the program to model simple calculator

Write the program to model the simple calculator. Each data line must consist of next operation to be performed from list below and right operand.

  Design a system for the organization

explain the main systems in place, discuss the integration, and explain how the data collected by these systems helps the organization make decisions and carry out the strategic plan.

  Create a math tutoring program

You are being contracted to create a math tutoring program for a local elementary school.  This tutoring software should ask children which operation they would like to work on

  Write program using while loop to output squares of integers

Write a program that uses while loop to perform the following steps:Output the sum of all the even numbers between firstnum and secondnum inclusive. Output all the numbers and their squares between firstnum and secondnum inclusive.

  Traditional versus object-oriented design

Compare the object-oriented approach to design to the traditional approach. Give your opinion on whether or not you believe there are certain projects where one design approach might be better that the other. If so, provide an example of one (1) s..

  Explain simple javascript event

Modify the body tag of your page to include the onLoad event handler. Within the event handler call the MyLoadFunction().

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