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

  Make a program that show the sales amount

You have to make a program that show the sales amount. Be sure to include comments. Comments should be included in the program to explain your calculations and program.

  Write a program that takes 10 values representin

Using a loop, write a program that takes 10 values representin exam grades (between 0 and 100) from the keyboard and outputs the minimum value, maximum value, and average value of all the values entered. Your program should not accept less than 0 ..

  Write a computer program that prompts the user for a number

Write a computer program that prompts the user for a number, creates an array for that number of random integers, and then uses the sophisticated form of bubble sort to order the array

  Method named isallvowels that returns

Write a method named isAllVowels that returns whether a String consists entirely of vowels (a, e, i, o, or u, case-insensitively). If every character of the String is a vowel, your method should return true. If any character of the String is a non-vo..

  Create java application which creates random phone number

Create and implement Java application which creates and prints a random phone number of the form xxx-xxx-xxxx. Include the dashes in the output.

  Create blackjack program in java

Create Blackjack program in Java following the instructions below must be in NetBEans

  Projectyou will design and deliver a website foes fictional

projectyou will design and deliver a website foes fictional client. the project is split into two partspart a website

  Your taskbullthe auction system should allow the user to

your taskbullthe auction system should allow the user to participate in a number of items and for the user to be able

  Each instance of this class will represent one book a book

each instance of this class will represent one book. a book consists of the title of the book a string and the authors.

  Develop a one player java multiple choice math game

Display a suitable welcome message to the player and a comprehensive description regarding the rules of the game - You have been asked to develop a one player java multiple choice math game that tests children, between ages 8 to 13 years old, abilit..

  Write a java method that perform a recursive descent parse

Determine whether the following grammar is an LL grammar by performing the pairwise disjointness test, showing the FIRST sets of each RHS of each nonterminal - Write a Java method that perform a recursive descent parse of the production.

  Implement an iterative method with a for loop

Different scientists have developed Predator-Prey models to try to understand the interactions and foresee the evolution of the populations.

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