Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Die Write a 'Die' (singular form of dice) class that defines the behavior of a single die. Your class must have the following methods. Use

Die

Write a 'Die' (singular form of dice) class that defines the behavior of a single die. Your class must have the following methods. Use the template below as a starting point.

  • A constructor that accepts an integer representing the number of sides on the die. For example 20 for a 20-sided die, 6 for a 6-sided die and so on.
  • roll - returns a random number representing the result of rolling the die. For example; for a 6-sided die; 1, 2, 3, 4, 5 or 6
  • rollMultiple(number) - Rolls the die number of times and returns a list object containing the resulting numbers
  • getSides() - returns the number of sides on the die

Coin

Augment your previous submission with a new class named 'Coin'. Coin should inherit from Die, with the following modifications;

  • The constructor should not take any arguments; a coin always has two sides
  • add a flip() method that uses the roll() method from the parent class. If roll returns 1; flip should return "HEADS". If roll returns a 2, flip should return "TAILS"
  • Do not override the roll or rollMultiple methods from the parent class

image text in transcribed

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

Step: 3

blur-text-image

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

Learning PostgreSQL

Authors: Salahaldin Juba, Achim Vannahme, Andrey Volkov

1st Edition

178398919X, 9781783989195

More Books

Students also viewed these Databases questions

Question

How do manufacturing companies differ from merchandising companies?

Answered: 1 week ago

Question

Understand the purpose and methods of cross-cultural training

Answered: 1 week ago