Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please create a new Java (ANT) Project in NetBeans, called Final220 followed by your first name. For example, my project would be named Final220_Samuel .

Please create a new Java (ANT) Project in NetBeans, called Final220 followed by your first name.

For example, my project would be named Final220_Samuel.

In the same package as the generated Final220... class, please create a new Java class called PlayingDie.

Purpose: Simulate a Playing Die with any number of sides

Constants/Fields: As needed

Methods: getNumberOfSides - returns how many sides are in this PlayingDie object getCurrentSideUp - returns the visible value of what side is currently face-up (e.g. 1) rollDie (declare this method to be final) - using a random number, sets the current side up to a random number within the range of possible sides. For example, a two or three is fine for a four-sided PlayingDie but nine would not work.

Constructors: 1. No-Arg - Calls the one-arg constructor (using keyword this) to set the number of sides of the PlayingDie to a class default value of 6. 2. One-Arg - a) set number of sides of PlayingDie to value of argument (from user) If that value is valid, as follows: If the value passed in to the constructor is an even number, then set the number of sides of the PlayingDie object to that number. Otherwise, set the number of sides of the object to one more than what the user specified. For example, if the user specifies 11 sides, then set the number of sides in the PlayingDie to 12.

b) make sure the PlayingDie starts out on any valid random side.

c) any other initialization tasks, as needed.

In your main method:

1. Please create one instance (object) of this PlayingDie class using the one-arg constructor with however number of sides you wish to specify. Please also create a second PlayingDie with the default number of sides using the no-arg constructor. You can create these in either order (one-arg then no-arg or no-arg then one-arg).

2. Please output the current (i.e. starting) value of both dice's number of sides and their side up.

3. Please use a loop to roll both dice four times and to output each PlayingDie's side up at each iteration.

Sample output:

d1 Number of sides: 6 d2 Number of sides: 12 d1 Initial side up: 6 d2 Initial side up: 11 d1 side up: 5 d2 side up: 1 d1 side up: 4 d2 side up: 11

....

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

Seven NoSQL Databases In A Week Get Up And Running With The Fundamentals And Functionalities Of Seven Of The Most Popular NoSQL Databases

Authors: Aaron Ploetz ,Devram Kandhare ,Sudarshan Kadambi ,Xun Wu

1st Edition

1787288862, 978-1787288867

More Books

Students also viewed these Databases questions

Question

11. Define these terms: browser, URL, search tool.

Answered: 1 week ago

Question

Explain the forces that influence how people handle conflict

Answered: 1 week ago