Use a joptionpane to ask the user

Assignment Help Basic Computer Science
Reference no: EM13207891

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: EM13207891

Questions Cloud

Describe a dbms and its functions : Describe a DBMS and its functions. Name some of the popular DBMS software? You should search the Internet for the updated DBMS technology.
Formal disaster recovery plan : Describe at least five components that should be incorporated in a formal disaster recovery plan in order that MailMed Inc. can become operational within 72 hours after a disaster affects its computer operations capability
Explain oyster culture and restoration in the chesapeake bay : Some recent media attention about oyster culture and restoration in the Chesapeake Bay and other coastal areas intrigued some environmentally minded citizens in Chincoteague Island,
Which structure would be the best for the storyboard created : He would like his recipes to be displayed in very simple, step by step pages. Which structure would be the best for the storyboard created for one of his recipes?
Use a joptionpane to ask the user : 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.
How opportunity costs relate to japans cleanup efforts : Discuss how opportunity costs relate to Japan's cleanup efforts after the devastating earthquake/tsunami of March 2011. Begin the discussion by defining "opportunity costs." Then make a list of actions the Japanese government must accomplish to re..
Define aqueous the strongest ion-dipole attractions : Explain which of the following aqueous solutions has the strongest ion-dipole attractions: 0.3 M FeBr3, 0.6 M CaCl2, 0.5 M Ba(NO3)2, 0.2 M (NH4)2SO4, 0.9 M KOH
Discuss the us housing mortgage crisis that started in 2006 : Discuss the U.S. housing mortgage crisis that started in 2006. Perform a web search to gather information on the crises. The most generally accepted facts are: housing prices have decreased, many homeowners have lost their homes because they are u..
Exposure to bright light causes : Exposure to bright light causes the:

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Create table-balance on loan at end of month-visual basic

Using Visual basic a tv set is bought with the loan of 563 to be paid off with five monthly payments of 116 interest is 1% per month.

  Will autonation can continue to be successful

How have they responded to pressures from its competitive environment? How does it provide value to its customers? Do you think AutoNation can continue to be successful?

  Find monthly break-even volume for company

Variable cost per pound of fertilizer is $0.15. Evergreen sells fertilizer for $0.40 per pound. Find out the monthly break-even volume for company.

  You are a systems development consultant

You are a systems development consultant who has been approached by a client, a law firm, to develop an automated case tracking system. The first step is to negotiate the project scope

  How large video memory is required to store image

How large a video memory is required to store a 640 X 480 image during display? A 1600 X 900 image? A 1440 X 1080 image?

  Describe the five forces model

Describe the Five Forces Model. What role does the Five Forces Model play in decision making? Define a database management system and discuss each of the five important software components of a database management system.

  Write ethical issues involved in eliminating jobs in k-mart

Sears is losing market share, has been acquired by K-Mart, and is eliminating jobs; Wal-mart is gaining market share and hiring. Write ethical issues involved, and which firm has a more ethical position?

  Write sequence of statements-find first comma in string line

Write down sequence of statements which finds first comma in the string line, and assigns to variable clause portion of line up to, but not including comma.

  Kinds of support and tools are available with visual basic

What kinds of support and tools are available with Visual Basic? Sum-up your research, and make sure to reply to each of the questions.

  Know the industry in which a company operates

Getting to know the industry in which a company operates is a critical factor for leveraging information systems and gaining a competitive advantage.

  High-level descriptions of customer-s expectations

It needs to have high-level descriptions of the customer's expectations and the criteria for success. You need to describe why these are the best choices and why alternatives will not work as well.

  Create a quick wedding program in indesign

create a quick wedding program in Indesign. Are there any websites with templates for wedding programs for Indesign? I am using Indesign CC.

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