Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

useing Java Program to simplify and clarify The primary purpose of these exercises is to illastrate the usefulness of sinmple methods your programs 1. A

useing Java Program

image text in transcribed

to simplify and clarify The primary purpose of these exercises is to illastrate the usefulness of sinmple methods your programs 1. A polygonal number is a namber represented as dots or pebbles that can be arranged in the shape of a regular polygon. (The most familiar of these are the square numbers, which can be arranged in the shape of a square and the triangular numbers, exemplified by the 15 balls in the rack for a game of billiards.) If n is the number of sides of the regular polygom and k is the number of dots (or pebbles or balls) along one side of the polygon formula for the polygonal number p'n, k) is: k2 (n-2)-kn-4) You are to write first a method with the following signature and which will return the value of p public static long polygonalNumber(long n, Jong Then write a main peogram that asks the user for the number of sides on the polygons and how many of the corresponding polygonal numbers the user wants to see. The peogram should then output those numbers, 10 numbers per line Here is a sample output What is the nunber of sides of your polygon? How many of these would you iike to see7 3 3 610 15 23 28 36 45 66 78 91 105 120 136 353 371 390 230 31 253 276 300 325 353 378 406 43546 496 528 561 595630 666 2. In this program, you will play a little dice game. It's a rather simple game. You just roll two dice and look at their sum. If the sum is 1,2,3,4,7, 10, 11, or 12, you win. Otherwise, you lose. What are the chances of winning this game? To try and find out, we will simulate playing the game. You are to write three methods with the following signatures: public static int throwDieO I simalates throwing a single die public static int throwTwoDiceO simulates throwing two dice (returning their sum) publie static boolean winO lsimulates a single play of the game described above Then write a main program that asks the user how many repetitions of the game heshe would like to try and then simulate the playing of that many games, keeping track of how many are won. Then it should output single line as shown in the sample nun: How many ropetitione? 10b There were 513 wins out of 1000 tries Note: each run of the program is likely to end up with a different answer because of the randomness involved Hint: Use a random integer taking on one of the values 1,2,3,4,5,6 to simulate the throw of a single die

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MongoDB Applied Design Patterns Practical Use Cases With The Leading NoSQL Database

Authors: Rick Copeland

1st Edition

1449340040, 978-1449340049

More Books

Students also viewed these Databases questions

Question

Who or what is affected by this situation?

Answered: 1 week ago

Question

Question Can a Keogh plan fund be reached by the owners creditors?

Answered: 1 week ago

Question

Question What happens to my plan if I die?

Answered: 1 week ago