Java application-tests random number generation abilities

Assignment Help JAVA Programming
Reference no: EM13924069

Write a Java application which tests the random number generation abilities of Java. Random number generation is explained below.Your application should simulate rolling a pair of dice some number of times. Use a JOptionPane to ask the user how many times the dice should be rolled. Each dice roll can be a value between 1 and 6, so rolling 2 dice will result in values between 2 and 12. You need to generate a random number between 1 and 6 to simulate rolling each dice. Keep track of the result of each roll using an array that is indexed by the sum of the roll of the two dice. Output your result in a table which shows each value (ie. 2 - 12) and the number of times that value was rolled. The program must have the following structure:

1. The main function declares the counting array and gathers input from the user.

2. A separate function is called which takes an integer array parameter as well as the number of dice rolls to execute. This function rolls the dice the required number of times and uses the array provided to count the number of times each value is rolled.

3. The main program takes the count data from the array, formats it and displays it as described above. For output, you should build a formatted string which includes tabs and new lines to represent your table.

JOptionPanes by themselves are not capable of properly formatting tabs. However, there is another Java class which can be used with JOptionPanes to correctly display a formatted string. The JTextArea class understands all string formatting instructions. The following illustrates how to use the JTextArea class with a JOptionPane to display a formatted string. import javax.swing.JOptionPane; import javax.swing.JTextArea; String output = "This t is t a t formatted t string. n"; // Create a new JTextArea object JTextArea area = new JTextArea( ); // Place a formatted string into the JTextArea area.setText( output ); // Place the text area into the JOptionPane JOptionPane.showMessageDialog( null, area, "Title for dialog box", JOptionPane.INFORMATION_MESSAGE ); For each of the two programming problems, create an Eclipse project and develop a Java program to solve the problem. Make sure to capture a sample of your program's output. The best way to do this is to click on the console window you want to capture and then press the Alt and PrintScreen keys at the same time. Then paste your captured screen image into a Word document. For each of the two programs, put the screen capture followed by a copy of your source code into your Word document. Random Numbers in Java There are two different classes available to generate random numbers in Java. The static method random from the Math class can be used to generate a random floating point number from 0 up to but not including 1. This number can be scaled to whatever range of random numbers is desired. (int)(Math.random( ) * 10); //results in an integer between 0 and 9 The Random class from the java.util package can also be used to get random numbers. The nextInt method returns an integer from 0 up to but not including the argument value provided to the nextInt method. Random rand = new Random( ); int number = rand.nextInt(10); //results in an integer between 0 and 9 minimumValue + differenceBetweenValues * rand.nextInt( scalingFactor ) The formula shown above is used to generate a range of random numbers starting at some minimum value and generating some specified number of random values. The scalingFactor determines how many different random values will be generated by the call to nextInt, starting with the value 0. The difference between values is usually 1.

Reference no: EM13924069

Questions Cloud

Calculate the expected utility of each prospective portfolio : Calculate the expected utility of each prospective portfolio for each of the two clients. Explain why there is a difference in these two outcomes.
Five step planning process : Resources: The Five Step Planning Process covered in class and the Sample Business Proposal at the Center for Writing Excellence
How the patriot act increased federal powers for search : Explain how the Patriot Act increased Federal powers for search, seizure, surveillance and detention. Please also discuss concerns voiced by privacy and civil rights advocates regarding the law's different provisions
Karmazyn hospital bases its budgets : Karmazyn Hospital bases its budgets on patient-visits. The hospital's static budget for October appears below:
Java application-tests random number generation abilities : Write a Java application which tests the random number generation abilities of Java. Random number generation is explained below.
The five number summary of a data set : What's the shape of this distribution (A) Symmetric (B)Left Skewed (C) Right Skewed
Describe and derive a expression for the marginal cost curve : Discuss whether or not Paradise Shoes should expand its output further beyond 1200 pairs per week. State all assumptions and qualifications that underlie your recommendation.
Calculate tracking error for each manager relative to index : Calculate the tracking error for each manager relative to the index. Which manager did a better job of limiting his or her client's unsystematic risk exposure? Explain.
Would you increase or decrease user fees : Consider the following questions: would you make any changes to individual and corporate income tax rates, property taxes, or sales taxes? Would you increase or decrease user fees

Reviews

Write a Review

JAVA Programming Questions & Answers

  Java program to read line of text which ends with period

Write down the java program which will read the line of text which ends with the period, which serves as sentinel value. Show all the letters which occur in the text.

  Explore how to throw and rethrow and exception

We will explore how to throw and rethrow and exception, and how to handle events in a program.  Please respond to all of the following prompts:Discuss whether it is it possible

  Develop the game using the concepts of cohesion

Develop the game using the concepts of Cohesion, Coupling and RDD, i.e., responsibility-driven design.

  Determine the length of a string

Determine the length of a string. The first version should use array subscripting, and the second version should use pointer arithmetic

  Reads in up to 1000 non-negative integers

Write a program that reads in up to 1000 non-negative integers and displays distinct numbers (i.e., if a number appears multiple times, it is displayed only once). (Hint: Read each number and store it in an array if it is new. If the number is alread..

  Construct 4 instances of your instrument

Create a Java test class that simulates using your MusicalInstrument class.  In your test class you should at a minimum construct 4 instances of your instrument,

  Splits the word into a unicode character array

Write methods that take a word input by the user and then- splits the word into a unicode character array. determines if the input word is a palindrome - the same frontwards and backwards.

  Allows the user to enter a temperature and whether

Write a program that allows the user to enter a temperature and whether the temperature is stated in Celsius or Fahrenheit...or whethe

  Define a static max method in the geometricobject class

Modify the GeometricObject class to implement the Comparable interface, and define a static max method in the GeometricObject class for finding the larger of two GeometricObject objects

  Write jvm program which accepts rpn expression

Write down the IJVM program which accepts RPN expression, with each operand and operator entered line by line. As each number (operand) is entered, push it on stack.

  The new class has the attributes of: name - type string age

Here is my current assignment I got the cat file to work I'm just having trouble with the driver file. You must create two Java files called LastNameFirstNameUnit6Prog.java, and Cat.java. Ensure you include ALL files required to make your program com..

  Using joptionpanes to handle your input and output

Using JOptionPanes to handle your input and output, produce a Java program which, given three sides of a triangle, determines whether the triangle is.

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