PROGRAM STATEMENT:DICE ROLL SIMULATOR: Write a class named Dice . The Dice class should have the following field: A String named sideUp . The sideUp field will hold either a 1, 2, 3, 4, 5, or 6...


PROGRAM STATEMENT:DICE ROLL SIMULATOR:

Write a class namedDice. TheDiceclass should have the following field: A String namedsideUp. ThesideUpfield will hold either a 1, 2, 3, 4, 5, or 6 indicating the side of the dice that is facing up.


TheDiceclass should have the following methods:


A no-argument constructor that calls thetossmethod, described next…


A void method namedrollthat simulates rolling the dice. When therollmethod is called, it generates a random number in the range of 1 through 6 (remember we covered how to generate random numbers in the lectures). The random number result sets thesideUpfield to that number.


A method namedgetSideUpthat returns the value of thesideUp.


A method namedshowPastRunthat opens the file named
myoutput.txt
(explained in next section)and displays on the screen its content.


Write adriverclass calledDriverthat demonstrates theDiceclass:


The program should start by asking the user if the past program run needs to be displayed. If yes, display the past program run using theshowPastRun.


Next, the program should display the following message: “New Dice-Roll Simulator Run:”


Next, create an instance of the Dice class and display the side that is initially facing up. Then, use a loop to roll the dice 10 times. Each time the dice is rolled, display the side that is facing up with a message to the user (e.g. "The dice rolled a 6").


The program should keep count of the number of times a 6 is shown up, then display that value after the loop finishes (e.g. "Number of 6 rolls: 5").


The programmustalso store all its output in a text file named
myoutput.txt ,
as shown in the lectures.


Write a header message on the text filebeforeeach program run with the current date and time. For example: *** Program Output of XXXXXXXXXXat 13:44 *** (check our textbook orhttps://www.w3schools.com/java/java_date.asp(Links to an external site.)for details).


The new outputmust overwritethe older one in the text file.


Run your program several times to test it.



Important Note:Assignments without text file operations will lose 50% of the grade.



SUBMISSION INSTRUCTIONS & REMINDERS:


Remember to:


Add all necessary comments to your code, including the header comment.


Test your program several times and paste the testing output shown in the console as a comment at the bottom of your source code in the driver/main class program file.


Add all necessary explaining comments in the body of the code.


Correctly name your classes, methods, and variables.



May 18, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here