Question

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()    {...

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
       {
           turnScore += getDiceValue();
           isSkunk = false;
       }
   }
  
  
   public void programmedTurnRoll()
   {
       dice.roll();

       if (dice.getDie1Value() == 1 || dice.getDie2Value() == 1 && dice.getLastRoll() != 2)
       {
           turnScore = 0;
           isSkunk = true;
       }

       else if (dice.getLastRoll() == 2)
       {
           turnScore = 0;
           isSkunk = true;
}

       else
       {
           turnScore += dice.getLastRoll();
           isSkunk = false;
       }
   }
  
  
   public int getTurnScore()
   {
       return this.turnScore;
   }

   public boolean isSkunk()
   {
       return isSkunk;
   }

   public boolean isDoubleSkunk() {
       return isDoubleSkunk;
   }
  
   public int getDie1Value()
   {
       return dice.getDie1Value();
   }

   public int getDie2Value()
   {
       return dice.getDie2Value();
   }

   public int getDiceValue()
   {
       return getDie1Value() + getDie2Value();
   }

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1


Please let me know if you have any doubts or you want me to modify the answer. And if you find this answer useful then don't forget to rate my answer as thumps up. Thank you! :)

import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
public class TurnTest
{
    private Dice dice, dice2;
    private Die die1, die2, die3, die4;
    private int[] rollDie1, rollDie2, rollDie3, rollDie4;
    private int turnScore;

    @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);
        this.rollDie3 = new int[] { 3, 4, 5 };
        this.die3 = new Die(rollDie3);
        this.rollDie4 = new int[] { 4, 5, 6 };
        this.die4 = new Die(rollDie4);
        this.dice2 = new Dice(die3, die4);
    }

    @Test
    public void testIsSkunk() {
        Turn turn = new Turn(dice);
        turn.turnRoll();
        boolean testBol = turn.isSkunk();
        //assertTrue(testBol);
    }


    @Test
    public void testTurnScore() {
        Turn turn2 = new Turn(dice2);
        turn2.turnRoll();
        int expectedTurnScore = 7;
        int actualTurnScore = turn2.getTurnScore();
        //assertEquals(expectedTurnScore,actualTurnScore);
    }


    private void extracted(int expectedTurnScore, int actualTurnScore) {
        assertEquals(expectedTurnScore,actualTurnScore);
    }


    @Test
    public void testTurnScoreAfterSkunk() {
        Turn turn = new Turn(dice);
        turn.turnRoll();
        int expectedTurnScore = 0;
        int actualTurnScore = turn.getTurnScore();
        extracted(expectedTurnScore, actualTurnScore);
    }

    public int getTurnScore() {
        return turnScore;
    }

    public void setTurnScore(int turnScore) {
        this.turnScore = turnScore;
    }


}

----------------------------------------------------------------------------------------------------------------------------------------------
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.getDie1() == 1 || dice.getDie2() == 1 && dice.getLastRoll() != 2)
        {
            turnScore = 0;
            isSkunk = true;
        }

        else if (dice.getLastRoll() == 2)
        {
            turnScore = 0;
            isDoubleSkunk = true;
            // totalScore = 0;
        }

        else
        {
            turnScore += getDiceValue();
            isSkunk = false;
        }
    }


    public void programmedTurnRoll()
    {
        dice.roll();

        if (dice.getDie1() == 1 || dice.getDie2() == 1 && dice.getLastRoll() != 2)
        {
            turnScore = 0;
            isSkunk = true;
        }

        else if (dice.getLastRoll() == 2)
        {
            turnScore = 0;
            isSkunk = true;
            // totalScore = 0;
        }

        else
        {
            turnScore += dice.getLastRoll();
            isSkunk = false;
        }
    }


    public int getTurnScore()
    {
        return this.turnScore;
    }

    public boolean isSkunk()
    {
        return isSkunk;
    }

    public boolean isDoubleSkunk() {
        return isDoubleSkunk;
    }

    public int getDie1Value()
    {
        return dice.getDie1();
    }

    public int getDie2Value()
    {
        return dice.getDie2();
    }

    public int getDiceValue()
    {
        return getDie1Value() + getDie2Value();
    }

}
|삐 DiceTest [~/ldeaProjects/DiceTest] -../src/TurnTest.java [DiceTest] Project import static org.junit.Assert.assertEquals im

Add a comment
Know the answer?
Add Answer to:
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()    {...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write Junit test for the following class below: public class Player {       public int...

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

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

    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 += chips;    }       public int getRoundScore() {        return roundScore;    }       public void setRoundScore(int points) {        roundScore += points;    }       public int getTurnScore() {        return turnScore;   ...

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

    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();    }      ...

  • You only need to use Junit to test 3 methods of the Nurse class. public Nurse(int...

    You only need to use Junit to test 3 methods of the Nurse class. public Nurse(int a, float s) { ... } public boolean isBusy() {...} public void retire() {....} code: public class Nurse { private int numOfPatients; private float salary; // Helping function // private void trace(char* s) { cout << s << endl; } // Implementor function public Nurse(int a, float s) { numOfPatients =a; salary=s; } // Access function public int getNumOfPatients() { return numOfPatients; } public...

  • Consider the Automobile class: public class Automobile {    private String model;    private int rating;...

    Consider the Automobile class: public class Automobile {    private String model;    private int rating; // a number 1, 2, 3, 4, 5    private boolean isTruck;    public Automobile(String model, boolean isTruck) {       this.model = model;       this.rating = 0; // unrated       this.isTruck = isTruck;    }        public Automobile(String model, int rating, boolean isTruck) {       this.model = model;       this.rating = rating;       this.isTruck = isTruck;    }                public String getModel()...

  • Write JunitTest for the class below: public class Dice {    private Die die1;    private Die die2;    public Dice(int[] programmedRolls)    {        int[] programmableroll = programmedRolls;        th...

    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);    } }

  • Assignment (to be done in Java): Person Class: public class Person extends Passenger{ private int numOffspring;...

    Assignment (to be done in Java): Person Class: public class Person extends Passenger{ private int numOffspring; public Person() {    this.numOffspring = 0; } public Person (int numOffspring) {    this.numOffspring = numOffspring; } public Person(String name, int birthYear, double weight, double height, char gender, int numCarryOn, int numOffspring) {    super(name, birthYear, weight, height, gender, numCarryOn);       if(numOffspring < 0) {        this.numOffspring = 0;    }    this.numOffspring = numOffspring; } public int getNumOffspring() {   ...

  • This is my code for a TicTacToe game. However, I don't know how to write JUnit...

    This is my code for a TicTacToe game. However, I don't know how to write JUnit tests. Please help me with my JUnit Tests. I will post below what I have so far. package cs145TicTacToe; import java.util.Scanner; /** * A multiplayer Tic Tac Toe game */ public class TicTacToe {    private char currentPlayer;    private char[][] board;    private char winner;       /**    * Default constructor    * Initializes the board to be 3 by 3 and...

  • public class Date { private int month; private int day; private int year; /** default constructor...

    public class Date { private int month; private int day; private int year; /** default constructor * sets month to 1, day to 1 and year to 2000 */ public Date( ) { setDate( 1, 1, 2000 ); } /** overloaded constructor * @param mm initial value for month * @param dd initial value for day * @param yyyy initial value for year * * passes parameters to setDate method */ public Date( int mm, int dd, int yyyy )...

  • Write one JUnit test in Java for the following: Essay class: import java.util.Scanner; public class Essay implements IAn...

    Write one JUnit test in Java for the following: Essay class: import java.util.Scanner; public class Essay implements IAnswer{ private String question; public Essay(String q){ this.question = q; } //This function returns question text public String getQuestionText() {    return question; } //This function takes answer from user public void answer(String userAnswer) {    // Take care of answer } @Override public String getAnswer() { System.out.println(question); Scanner scan = new Scanner(System.in); System.out.print("Answer: "); String ans =scan.nextLine(); scan.close(); if(ans.length() <=140){ return ans; }else{ return...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT