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...

1 answer below »


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.



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.


Answered Same DayNov 06, 2021

Answer To: PROGRAM STATEMENT: DICE ROLL SIMULATOR: Write a class named Dice . The Dice class should have the...

Aditya answered on Nov 06 2021
143 Votes
DiceRoleSimulator/.classpath

    
        
            
        
    
    
    
DiceRoleSimulator/.project

     DiceRoleSimulator
    
    
    
    
        
             org.eclip
se.jdt.core.javabuilder
            
            
        
    
    
         org.eclipse.jdt.core.javanature
    
DiceRoleSimulator/.settings/org.eclipse.jdt.core.prefs
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=14
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=14
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=14
DiceRoleSimulator/bin/Dice.class
DiceRoleSimulator/bin/Driver.class
DiceRoleSimulator/myoutput.txt
****Program Output of 2020-11-07 at: 01:39:51.493898300****
Initail value 2
The dice rolled a 2
The dice rolled a 2
The dice rolled a 5
The dice rolled a 4
The dice rolled a 3
The dice rolled a 4
The dice rolled a 2
The dice rolled a 3
The dice rolled a 4
The dice rolled a 4
Number of 6 rolls:...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here