Need Help with this Question or something similar to this? We got you! Just fill out the order form (follow the link below), and your paper will be assigned to an expert to help you ASAP.
The Assignment
In the Dice.Java file: create a class called Dice. Your class should have the following elements:
a class variable string array called DICENAME with the following different names dice:
Tetrahedron( 4 faces )
Cube( 6 faces )
Octahedron( 8 faces)
Pentagonal trapezohedron( 10 faces )
Dodecahedron( 12 faces )
Icosahedron( 20 faces)
Zocchihedron ( 100 faces) For the purposes of this exercise, assume that there is one number per face, even though 4 faced dice are often only 2 numbers. So if it has 4 faces, it represents numbers 1-4, if it has 100 faces, it represents numbers 1-100.
Make a second class variable array called FACES, this time an int array representing the number of faces for each die. Make sure the index number representing the faces in your FACES array matches with the corresponding dice name in your DICENAME array, for example if Tetrahedron is at DICENAME[0] then 4 should be at FACES[0].
Make two instance variables called diceType and lastRoll both int. diceType will store the index number in DICENAME of type of die the object represents and lastRoll will store the value of the die last time it was rolled.
Make two constructors. The first should be triggered when an object is created with no arguments and should set diceType and lastRoll. Note: lastRoll should have a plausible value, if the dicetype is Cube, which has only 6 faces, the last roll should not be 15. The second constructor should take two ints as arguments and allow the value of diceType and lastRoll to be passed in and set.
Make a non-static roll() method that takes no arguments and uses the value set in diceType in your object to look up the number of faces in FACES, then rolls a value with that number inclusive. Note: you’ll want to put a plus one outside of your random nextInt() to achieve this. It should then set lastRoll to that value.
Make getters and setters for diceType and lastRoll.
Make a toString() and equals() method for the class. For equals, both the type of die and the last roll must be the same for them to be equal. For toString, make sure to print the name of the die, not just the number of faces, and also the last roll. Reminder that toString() does not print a string, it returns it.
In the TestDice.java file: create the following JUnit tests:
Build an instance of the dice class with no arguments and check to make sure its instance variables are set to reasonable ranges (in other words, the roll does not exceed the faces)
Build an instance of the dice class and pass in reasonable ranges.
Test to make sure the .roll() method does indeed update the lastRoll variable
Test your getter methods
Test your setter methods
Test your toString() method
Test your equals method
You should absolutely be doing this work in eclipse not GitHub. Only upload to GitHub when you’re ready to go. Reminder that if you have any newlines and are working on windows you should use System.lineSeperator() in your JUnit tests to represent the newline, not n.
The tests in this repo will build and test your code to make sure your tests pass. NOTE: since you are running your own tests, you can make them pass for the wrong reasons, because of this, a green checkmark doesn’t mean you’re getting all your points.
(Links to an external site.)Tests
There are two tests being run against this code, one is gradle test, which will use Gradle’s infrastructure to do an output match against the JUnit test you looked at. It will pass if it both passes the JUnit test and gives expected output.
The second is an output match against separately compiled source code that independently verifies the output of the Java class.