1. Write a class named Coin. The Coin class should have the following field: • A String named sideUp. The side Up field will hold either "heads" or "tails" indicating the side of the coin that is facing up. The Coin class should have the following methods: • A no-arg constructor that randomly determines the side of the coin that is facing up ("heads" or "tails") and initializes the sideUp field accordingly. A void method named toss that simulates the tossing of the coin. When the toss method is called, it randomly determines the side of the coin that is facing up ("heads" or "tails") and sets the sideUp field accordingly. • A method named getSide Up that returns the value of the side Up field. Write a program that demonstrates the Coin class. The program should create an instance of the class and display the side that is initially facing up. Then, use a loop to toss the coin 20 times. Each time the coin is tossed, display the side that is facing up. The program should keep count of the number of times heads is facing up and the number of times tails is facing up, and display those values after the loop finishes.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Please help me with this using java. Include comments explaining each line of code
1. Write a class named Coin. The Coin class should have the following field:
• A String named sideUp. The sideUp field will hold either "heads" or "tails" indicating the
side of the coin that is facing up.
The Coin class should have the following methods:
• A no-arg constructor that randomly determines the side of the coin that is facing up
("heads" or "tails") and initializes the sideUp field accordingly.
• A void method named toss that simulates the tossing of the coin. When the toss method
is called, it randomly determines the side of the coin that is facing up ("heads" or "tails")
and sets the sideUp field accordingly.
• A method named getSide Up that returns the value of the side Up field.
Write a program that demonstrates the Coin class. The program should create an instance
of the class and display the side that is initially facing up. Then, use a loop to toss the coin
20 times. Each time the coin is tossed, display the side that is facing up. The program
should keep count of the number of times heads is facing up and the number of times
tails is facing up, and display those values after the loop finishes.
Transcribed Image Text:1. Write a class named Coin. The Coin class should have the following field: • A String named sideUp. The sideUp field will hold either "heads" or "tails" indicating the side of the coin that is facing up. The Coin class should have the following methods: • A no-arg constructor that randomly determines the side of the coin that is facing up ("heads" or "tails") and initializes the sideUp field accordingly. • A void method named toss that simulates the tossing of the coin. When the toss method is called, it randomly determines the side of the coin that is facing up ("heads" or "tails") and sets the sideUp field accordingly. • A method named getSide Up that returns the value of the side Up field. Write a program that demonstrates the Coin class. The program should create an instance of the class and display the side that is initially facing up. Then, use a loop to toss the coin 20 times. Each time the coin is tossed, display the side that is facing up. The program should keep count of the number of times heads is facing up and the number of times tails is facing up, and display those values after the loop finishes.
Expert Solution
steps

Step by step

Solved in 2 steps with 4 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY