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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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