You will write some unit test to test the provided code here: please, please, please, and please!!! and answer the above question.
First file:
Second file:
Third file:
fourth file:
fiveth file:
sixth file:
Objectives: 1. You will get some experience with using a debugger and fixing bad code. 2. You will write some unit tests to test the provided code. 3. You will learn about the Observer pattem. Additional Preparation You will need to use an IDE this assessment. If you are using Eclipse, then JUnit 5 is installed. I will start a discussion thread with what I did to install these components into Java. Write Unit Tests . . Write unit tests using JUnit for the DiceBag class. Write the following unit tests: Add an Order Die to the DiceBag. Verify that the Order Die object is in the DiceBag! Test the toString method of the DiceBag class. Verify that the returned string is correct! Add 3 blue Order Die object and add 2 red Order Die objects. Verify that those 5 Order Die objects are in the DiceBag! Fix the Code! Use the Java debugger to find bugs in the given code. Document the bugs that you found in the above files HW Report The first draft of my code for the DiceDraw app will be in the following code. You will create the hw6 package in your IDE, and move the code files into the hw6 package. Make sure that the application compiles and runs. Next, use JUnit to write unit tests described above. Fix any coding errors that you find. You are free to change the code to make it easier to test, but no data member may be made public'. are expected to find out why player "Steve' gets assigned all the dice that are drawn. Fix the coding errors so that the order dice are drawn and assigned to the correct player. Answer these questions: 1. How many bugs did you find in the unit testing? What were they? 2. Did you find any bugs when using the debugger? What were they? 3. Are there any unit tests that could have found the bugs you found in the debugger? Describe one of those tests. I package hw6; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ThreadLocalRandom; // This class holds the dice(or tokens) to be drawn. // public class DiceBag { private List
bag = new ArrayList(); public void addToken(Token t) { bag.add(t); } public Token drawToken() { int upper Range = bag.size(); Token t = null; int die = ThreadLocalRandom.current() .nextInt(1, upper Range); if (upper Range > 1 ) { t = bag.remove(die); } return t; } public String toString() { String ret = "Dice left: " + bag.size() + " "; for (Token t:bag) { ret += t.toString() + " "; } return ret; } } package hw6; import static java.lang. System.out; // This class uses the other classes to produce the desired output public class GameController { public static void main(String[] args) { DiceBag d = new DiceBag(); Player player1 = new Player ("Tom"); Player player2 = new Player ("Steve"); Token t; addPlayeriTokens(playeri, d); addPlayer 2Tokens(player2, d); out.println("Drawing tokens for turn one"); // Handy syntax to assign a value and test in one statement while ((t = d.drawToken()) != null) { out.println("Token drawn: " + t.toString(); if (t.toString().contains("red")) { player1.addToken(t); out.println("Player + player1.getName() + " gets the token!"); } else { player2.addToken(t); out.println("Player " + player2.getName() + " gets the token!"); } out.println("Left in the DiceBag: + d.toString(); out.println("Next draw! "); } out.println("Bye!"); 3 private static void addPlayer1Tokens (Player P. Dicebag d) { for (int i = 0; i } package hw6; // This represents the order diedrawn from the bag. // Really, the only thing that matters is the color of the die. public class OrderDie extends Token { private String color; public OrderDie(String desc, String c) { super(desc); color = c; } public String toString() { String d = super.toString() + return super.toString(); } "" + color; } package hw6; import java.util.ArrayList; import java.util.List; // objects from this class will be used to keep track of the 1/ Order Dice(Tokens) that the player has drawn so far. // Other data members added for other anticipated user stories. public class Player { private String name; private int maxNumDice; private int returnNumDice; private List diceDrawn = new ArrayList(); public player (String name ) { this.name = name; } public String getName() { return name; } public void setMaxDice(int n) { maxNumDice = n; } public void setReturnNumDice(int n) { returnNumDice = n; } public void returnDiceToDiceBag(DiceBag d) { for (int i = 0; i