Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a class called Coin. It should consist of: - a boolean called isheads (true means heads, false means tails) - a Random object, random,

image text in transcribed

Create a class called Coin. It should consist of: - a boolean called isheads (true means "heads," false means "tails") - a Random object, random, constructed from Java's Random class. - No explicit constructor: instead, initialize the instance variables outside the constructor. is Heads should be true and random should use Java's no-argument constructor. If "initializing the instance variables outside the constructor" doesn't make sense, please re-watch Recording Two (Constructor Details) from minute 3:30 to 4:27. Otherwise, only two methods: - flip (), which should set isHeads to a randomly chosen boolean value, which then gets returned - tostring (), which should return "HEADS" if isheads is heads, and "TAILS" otherwise. Driver.java Create a class called Driver. It should use a Scanner object to create the following interactions with the user on the command line (you can assume a perfect user who does not enter bad information, like "head" instead of "HEADS"): $ java Driver Player one, please enter your name: Kristin Thank you, Kristin. Player two, please enter your name: Andrew Kristin, do you guess HEADS or TAILS? HEADS Kristin, you win! The coin says HEADS \$ java Driver Player one, please enter your name: Kristin Thank you, Kristin. Player two, please enter your name: Andrew Kristin, do you guess HEADS or TAILS? HEADS

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions