Write a java program to simulate a die

Assignment Help JAVA Programming
Reference no: EM13926503

1. Write a Java program to simulate a die. A die has values of either 1, 2, 3, 4, 5 or 6 on the face. You should use the Math.Random() or the java.util.Random() class to generate the values on the die. The program should prompt the user to enter how many times the die should be rolled. The output should show the results of each roll along with the total number of times 1, 2, 3, 4, 5 or 6 occurred for all rolls and the total sum comprised of the sum of all rolls. Here is a sample run:

How many times do you want to roll the die? 10

Thank you! The die roll results for 10 rolls were: 2 3 4 5 3 2 6 2 1 6 The number of occurrences of each face were as follows:

1: 1 2: 3 3: 2 4: 1 5: 1 6: 2

The sum of die rolls was: 34

2. Design a Java class named Polygon that contains:

A private int data field named numSides that defines the number of sides of the polygon. The default value should be 4.
A private double data field named sideLength that defines the length of each side. The default value should be 10.0.
A private double data field named xCoord that defines the x-coordinate of the center of the polygon. The default value should be 0.0.
A private double data field named yCoord that defines the y-coordinate of the center of the polygon. The default value should be 0.0.
A no argument constructor that creates a Polygon using the default number of sides, default side length and default x- and y-coordinates.
A constructor that creates a Polygon using a specified number of sides, side length and x- and y-coordinates.
Getter and setter methods for all data fields

A getPerimeter() method that returns a double value representing the sum of all sides.

A toString() method that displays the number of sides, side length, x-coordinate and y-coordinate values in String format.

Be sure your code compiles. (In the next question, you will create a TestPolygon class and test each of the methods)

Write a Java test program, named TestPolygon, to create five different polygons. When creating the five polygons, create one using the no argument constructor. For the remaining four, feel free to use any number of sides, side length and x-, and y-coordinates that are not equal to the default values and not equal to each other. For each of the five polygons, call all of the methods and display the results. For example for a Polygon with 3 sides, side length of 2.0 and x-coordinate and y-coordinates of 1.0, the following output may be appropriate.

toString() results: (3, 2.0, 1.0,1.0) getNumSides() results: 3 getSideLength() results: 2.0 getXCoord() results: 0.0 getYCoord() results: 0.0 getPerimeter() results: 6.0 setNumSides(4) results: 4 setSideLength(3) results: 3.0 setXCoord(2.0) results: 2.0 setYCoord(2.0) results: 2.0

Keep in mind, for five Polygons, you will have five different output results. Also, note there is no requirement to actually draw a Polygon.

Reference no: EM13926503

Questions Cloud

Where did you place on the ideology matrix : Where did you place on the ideology matrix? Where you surprised by the results or did you place about where you thought that you would? What do you think has been the largest influence on your ideology and why
Computer maintenance and training guide : This computer maintenance guide will help clients to install new hardware to a computer or substitute the present hardware. It will also give safety guidelines to avoid unnecessary problems with the computer hardware. This training guide informs t..
Performance evaluation-the illusion of objectivity : You are a store manager for a large, regional department store chain. Company headquarters has asked you to submit an evaluation of your assistant managers performance.
Which sentence is preferable : My brother must have had the angels watching over him yesterday. As he ________ from branch to branch like a monkey in a tree, he ________ thirty feet and all he got was a scratched toe.
Write a java program to simulate a die : Write a Java program to simulate a die. A die has values of either 1, 2, 3, 4, 5 or 6 on the face. You should use the Math.Random() or the java.util.Random() class to generate the values on the die.
Development in the various modes of transportation : The Hub and Spoke Concept continues its development in the various modes of transportation (Maritime, Air, Truck, and Rail). Describe some of the key advantages this concept brings to the various modes of transportation.
Identify and briefly summarize the federalist paper : Identify and briefly summarize the Federalist Paper you selected. Explain the key ideas that were discussed in that paper. Explain why the key ideas in the Federalist Paper you selected did or did not become part of U.S. law
Processes for developing the client solution : As a consultant, you bring to the table standard methods and processes for developing the client solution. Your solution may be a general one with special emphasis on at least two TCOs addressed in the course.
Tributary lateral load problem : What is the maximum allowable drift (inches) at the top of the ground/first story - Calculate the service load.

Reviews

Write a Review

JAVA Programming Questions & Answers

  What is printed out by the following code

What is printed out by the following code

  Write a method called drawspokes to draw the spokes

Write a method drawForest that draws the trees using the method drawTree from Part B. The method takes as a parameter the number of trees to draw

  Write a portion of a program for a church website

Write a portion of a program for a church's website. The program will be used for a chatting feature, which should include an Input Box that requests the user's name.  The message box should include the user's name and the Scripture of the Day (ch..

  Assume an ideal gas mixture is in contact with water

Assume an ideal gas mixture is in contact with water. Determine the equilibrium concentration of the contaminant in the liquid is the gas stream is composed of 200 ppm of benzene in air

  Prepare a java program to play pig

Pig is a two player game where the players take turns repeatedly rolling a single 6 sided die. A player repeatedly rolls the die until one of two events happen:

  Calculate payback period and net present value

Calculate payback period (PBP), net present value (NPV), and internal rate of return (IRR). Which project do you recommend for development? Support your recommendation.

  Implement bounded partial queue using signaling mechanism

Can you explain the reason? You can run the experiments on ecen5033.colorado.edu. Submit the code as well as experimental results - Implement both these schemes in Java. Each of the methods foo() and bar() just sleeps for 20 milliseconds.

  Calculates the total annual compensation of a salesperson

Write a Java application using NetBeans Integrated Development Environment (IDE) that calculates the total annual compensation of a salesperson. Consider the following factors: A salesperson will earn a fixed salary of $35,750

  E-marketing-e-commerce consultant

You are an e-marketing and e-commerce consultant. Mary and Joe Johnson, the owners of Book Bunker, have hired you to help them improve their sales both online and in their store.

  Create an application that keeps tracks of the information

Create an application that keeps tracks of the information in such a simple social network. More specifically, your application will allow for user profiles to be added to, deleted from, or looked-up in the social network.

  Write program that can be used to read an extract from a log

Write a program that can be used to read an extract from a log for one elevator and print the following statistics: the total \uptime", that is the total time the elevator was in service, Σ(tdown - tup) (in years).

  Implement a recursive method that returns xn

implement a recursive method that returns xn - Suppose we want methods that compute the value of a double precision number raised to an integer power.

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