Question: INTRO JAVA I have a starter code with 5 classes, please fill in the methods. import java.util.Random; public class Die { private int roll; private

INTRO JAVA I have a starter code with 5 classes, please fill in the methods.

import java.util.Random; public class Die { private int roll; private int numSides; /** * Default constructor for a Die * Initializes roll to 0 * and numSides to the standard 6 */ public Die() { } /** * Constructor for a Die * Initializes roll to 0 * and numSides to specified * number of sides * @param numSides the * number of sides to the die */ public Die(int numSides) { } /** * Assigns roll to a random value * from 1 to numSides */ public void makeRoll() { Random r = new Random(System.nanoTime()); } /** * Returns the roll number * @return the number generated * when die is rolled */ public int getRoll() {

return -1;

} }

Note 1: You are not allowed to implement any additional methods or alter the class in any other way than to write the given method bodies. Note 2: The default number of sides for one die is 6. However, some dice (polyhedral dice) contain a different number of sides. For this lab, we will assume that dice can have 6, 8, 10, or 12 sides only. Error checking for inappropriately sided dice will happen later in main. You do not need to test for this in the dice class. Note 3: to simulate a random roll, call methods from the Random class. For an appropriate seed, consider the nanoTime() method from the System class

public class Dice { private Die die1; private Die die2; /** * Default constructor * sets both dice to * be 6 sided */ public Dice() { } /** * Constructor to set * both dice to have the * same number of sides * @param sides the number * of sides of both dice */ public Dice(int sides) { } /** * Rolls both dice */ public void roll() { } /** * Returns the roll value * of Die1 * @return the roll value * of Die1 */ public int getDie1Roll() {

return -1;

} /** * Returns the roll value * of Die2 * @return the roll value * of Die2 */ public int getDie2Roll() {

return -1;

} /** * Returns the sum of the * roll values of Die1 * and Die2 * @return the sum of the rolls */ public int getSumRolls() {

return -1;

} } public class Player { private Dice dice; private int score; /** * Player constructor that * sets the number of sides * of the dice the player will * roll and gives the player * a default score of 0 * @param sides */ public Player(int diceSides) { } /** * Rolls the two player dice */ public void rollDice() { } /** * Prints the value of the the rolls * of the two dice to the console, with * each roll separated by a blank space */ public void printRoll() { } /** * Prints out whether a special roll was made * and updates the score accordingly * For snake eyes (two 1s) prints Snake Eyes! * and updates the score by 5 * When the two die rolls match otherwise, * prints out Matching! and updates the * score by 3 * For total of 3, prints out Total of 3! * and updates the score by 1 * For total of 5, prints out Total of 5! * and updates the score by 2 * For total of 7, prints out Oh no! Total of 7! * and resets the score back to 0 * For total of 9, prints out Total of 9! * and updates the score by 3 * For total of 11, prints out Total of 11! * and updates the score by 4 * For any other odd number, prints out Odd Roll! * and updates the score by 2 */ public void updateScore() { } /** * Returns the player's current score * @return the current score */ public int getScore() { return -1; } }

import java.util.Scanner; public class BattleDieGalactica { private Player player; private Player ai; /** * Prompts the user to input a number of die sides * Prints out the user choice and * Constructs a new player and ai based on the number * of sides of the dice * Note that the user input will be rounded up to 6, 8, 10 * or 12 and also rounded down to 12 if a higher number is * input. * @param input the Scanner */ private void gameSetUp(Scanner input) { System.out.print("Enter the number of sides (6, 8, 10 or 12): "); } /** * Prints out the current score for each opponent * to the console in the form: * Player: * Computer: * Note: no <> should be displayed */ public void printScore() { } /** * Determines whether any player has reached * 21 points, thus ending the game * @return whether the game is over */ private boolean gameOver() { return false; } public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("***Welcome to Battle Die Galactica!*** "); BattleDieGalactica game = new BattleDieGalactica(); input.close(); } } TEST CLASS: public class GameTest { public static void main(String[] args) { System.out.println("***Testing Die Class***"); Die d = new Die(6); d.makeRoll(); System.out.println("Die roll: " + d.getRoll()); System.out.println(" ***Testing Dice Class***"); Dice dice = new Dice(8); dice.roll(); System.out.println("Die 1 roll: " + dice.getDie1Roll()); System.out.println("Die 2 roll: " + dice.getDie2Roll()); System.out.println(" ***Testing Player Class***"); Player player = new Player(6); player.rollDice(); player.printRoll(); System.out.println("Score: " + player.getScore()); //add more method calls where needed } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!