Create Junit tests for the following classes
public class Dice
{
private Die die1;
private Die die2;
public Dice()
{
this.die1 = new Die();
this.die2 = new Die();
}
public Dice(int[] programmedRolls)
{
int[] programmableroll =
programmedRolls;
this.die1 = new
Die(programmableroll);
this.die1 = new
Die(programmableroll);
}
public Dice(Die die1, Die die2)
{
this.die1 = die1;
this.die2 = die2;
}
public void roll() {
die1.roll();
die2.roll();
}
public int getDie1Value() {
return die1.getLastRoll();
}
public int getDie2Value() {
return die2.getLastRoll();
}
public int getDiceValue()
{
return die1.getLastRoll() +
die2.getLastRoll();
}
public int getLastRoll() {
return die1.getLastRoll() +
die2.getLastRoll();
}
}
public class SkunkDice extends Dice{
public SkunkDice() {
}
public boolean isSkunk()
{
return (getDie1Value() == 1 ||
getDie2Value() == 1 && getDiceValue() != 2);
}
public boolean isDoubleSkunk() {
return (getDiceValue() == 2);
}
}
import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; //-------------------------TP 1.1 changes--------------------------------------------------// public class DiceTest { private Dice dice; private Die die1, die2; private int[] rollDie1, rollDie2; @Before public void setUp() throws Exception { this.rollDie1 = new int[] { 1, 2, 3 }; this.die1 = new Die(rollDie1); this.rollDie2 = new int[] { 1, 2, 3 }; this.die2 = new Die(rollDie2); this.dice = new Dice(die1, die2); } @Test public void test_Init_PredictableDie() { dice.roll(); int value = dice.getLastRoll(); // adds rollDie1's position1 + rollDie2's position1 assertEquals(2, value); } @Test public void test_Predictable_Roll_2() { dice.roll(); dice.roll(); int value = dice.getLastRoll(); // adds rollDie1's position2 + rollDie2's position2 assertEquals(4, value); } @Test public void test_Predictable_Roll_3() { dice.roll(); dice.roll(); dice.roll(); int value = dice.getLastRoll(); assertEquals(6, value); // adds rollDie1's position3 + rollDie2's position3 } @Test public void test_toString() { dice.toString(); assertEquals("Dice with last roll: => + ", "Dice with last roll: => + "); } }
Create Junit tests for the following classes public class Dice { private Die die1; private Die die2; public Dice() { this.die1 = new Die(); this.die2 = new Die(); } pu...
Write JunitTest for the class below: public class Dice { private Die die1; private Die die2; public Dice(int[] programmedRolls) { int[] programmableroll = programmedRolls; this.die1 = new Die(programmableroll); this.die1 = new Die(programmableroll); } }
Write Junit Test for the following class below: public class Turn { private int turnScore; private Dice dice; private boolean isSkunk; private boolean isDoubleSkunk; public Turn() { dice = new Dice(); } public Turn(Dice dice) { this.dice = dice; } public void turnRoll() { dice.roll(); if (dice.getDie1Value() == 1 || dice.getDie2Value() == 1 && dice.getLastRoll() != 2) { turnScore = 0; isSkunk = true; } else if (dice.getLastRoll() == 2) { turnScore = 0; isDoubleSkunk = true; } else { ...
Hello, Could you please help me code this program in Java? It is important that all rules are carefully followed. Using the PairOfDice class from PP 4.9, design and implement a class to play a game called Pig. In this game, the user competes against the computer. On each turn, the current player rolls a pair of dice and accumulates points. The goal is to reach 100 points before your opponent does. If, on any turn, the player rolls a...
I am currently doing homework for my java class and i am getting an error in my code. import java.util.Scanner; import java.util.Random; public class contact { public static void main(String[] args) { Random Rand = new Random(); Scanner sc = new Scanner(System.in); System.out.println("welcome to the contact application"); System.out.println(); int die1; int die2; int Total; String choice = "y";...
I need help with these Java programming assignements. public class Die { //here you declare your attributes private int faceValue; //operations //constructor - public Die() { //body of constructor faceValue=(int)(Math.random()*6)+1;//instead of 1, use random approach to generate it } //roll operation public void roll() { faceValue=(int)(Math.random()*6)+1; } //add a getter method public int getFaceValue() { return faceValue; } //add a setter method public void setFaceValue(int value) { faceValue=value; } //add a toString() method public String toString() { String...
Write Junit test for the following class below: public class Player { public int turnScore; public int roundScore; public int lastTurnScore; public String name; public int chipPile; public Player (String name) { this.name = name; this.turnScore = 0; this.chipPile = 50; } public int getChip() { return chipPile; } public void addChip(int chips) { chipPile...
How to create a constructor that uses parameters from different classes? I have to create a constructor for the PrefferedCustomer class that takes parameters(name, address,phone number, customer id, mailing list status, purchase amount) but these parameters are in superclasses Person and Customer. I have to create an object like the example below....... PreferredCustomer preferredcustomer1 = new PreferredCustomer("John Adams", "Los Angeles, CA", "3235331234", 933, true, 400); System.out.println(preferredcustomer1.toString() + "\n"); public class Person { private String name; private String address; private long...
Using the Die class defined in this chapter, design and implement a class called PairOfDice, composed of two Die objects. Include methods to set and get the individual die values, a method to roll the dice, and a method that returns the current sum of the two die values. Create a driver class called RollingDice2 to instantiate and use a PairOfDice object. I need the main method or test class public class Die { private final int MAX = 6;...
In Java, create several JUnit 4 Tests for the Illegal State Exception in the following private method : private void updateGear(int currentSpeed) { if (currentSpeed > 120){ throw new IllegalStateException("Cannot be greater than 120"); } if (currentSpeed <= 20) { currentGear = 1; } if (currentSpeed <= 40) { currentGear = 2; } if (currentSpeed <= 80) { currentGear = 3; } if (currentSpeed <= 120) { currentGear = 4; } else { currentGear = 5; } }
Consider the following Java classes: class A{ public int foo () { return 1; } public void message () { System.out.println( "A" + foo()); } } class B extends A { public int foo() {return 2; } } class C extends B { public void message () { System.out.println( "C" + foo()); } } (i) What are the outputs of the following code? (ii) What would be the outputs if Java used static dispatching rather than dynamic dispatching? B b...