+1443 776-2705 panelessays@gmail.com

 

Replication.

  1. For each of the reported bugs, generate a test case in UAT format that will reliably reproduce the buggy behaviour.
  2. Commit the test case documentation to version control.

2.Simplification.

  1. For each of the reported bugs, produce a simplified and automated test that reliably reproduces the bug.
  2. Commit the test code demonstrating the bug to version control.
  3. Record output from your test, demonstrating the buggy behaviour.

3.Tracing.

  1. For each of the reported bugs, trace back through the program from the point of failure to find the origin of the bug. Use a sequence of hypotheses and tests to support this search, and document this sequence in a debugging log.
  2. For each of the reported bugs, demonstrate that before the identified origin, variable values are ‘sane’ and that after the origin, at least one value is ‘infected’.
  3. Record screen shots demonstrating the origin of the bug.

4.Resolution.

  1. For each of the reported bugs, correct the bug.
  2. Commit the corrected code to version control.
  3. Record output listings from your automated test demonstrating that the buggy behaviour has been eliminated.
  4. Carry out the user test case with the specified data and show that the buggy behaviour has been eliminated.

import java.util.List; public class Round { public static int play(Punter punter, List<Die> dice, Face pick, int bet ) { if (punter == null) { throw new IllegalArgumentException("Punter cannot be null."); } if (pick == null) { throw new IllegalArgumentException("Pick cannot be null."); } if (bet < 0) { throw new IllegalArgumentException("Bet cannot be negative."); } punter.placeBet(bet); int matches = 0; for (Die d : dice) { d.roll(); if (d.getFace().equals(pick)) { matches += 1; } } int winnings = matches * bet; if (matches > 0) { punter.returnBet(); punter.receiveWinnings(winnings); } else { punter.loseBet(); } return winnings; } }

,

import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner console = new Scanner(System.in); String mainMenu = "n" + "Fish Prawn Crabnn" + "Please Select:nn" + "tP: Play interactivelyn" + "tB: Batch Modenn" + "tQ: Quitnn" + "Selection: "; Punter punter = null; List<Die> dice = setUpDice(); String ans = null; boolean stop = false; while (!stop) { System.out.print(mainMenu); ans = console.nextLine(); switch (ans.toUpperCase()) { case "P": punter = setUpPunter(console); InteractiveGame.play(punter, dice); break; case "B": punter = setUpPunter(console); BatchModeGame.play(punter, dice); break; case "Q": stop = true; break; default: System.out.println("Invalid selection"); } } console.close(); System.out.println("nTerminating"); } private static List<Die> setUpDice() { Die d1 = new Die(); Die d2 = new Die(); Die d3 = new Die(); List<Die> dice = new ArrayList<>(Arrays.asList(d1, d2, d3)); return dice; } private static Punter setUpPunter(Scanner console) { System.out.print("nEnter player name: "); String name = console.nextLine(); String ans = null; int initialBalance = 100; System.out.print(String.format("nEnter initial balance (default %d): ", initialBalance)); ans = console.nextLine(); try { initialBalance = Integer.parseInt(ans); } catch (NumberFormatException e) { System.out.println(String.format("Invalid entry, using default: %d.", initialBalance)); } int limit = 10; System.out.print(String.format("nEnter limit (default %d): ", limit)); ans = console.nextLine(); try { limit = Integer.parseInt(ans); } catch (NumberFormatException e) { System.out.println(String.format("Invalid entry, using default: %d.", limit)); } System.out.println(String.format("nInitialising player %s with balance $%d.00 and limit $%d.00", name, initialBalance, limit)); Punter punter = new Punter(name, initialBalance, limit); return punter; } }

,

import java.util.Random; public enum Face { FISH("Fish"), PRAWN("Prawn"), CRAB("Crab"), ROOSTER("Rooster"), GOURD("Gourd"), STAG("Stag"); private static Random random = new Random(); private final String name; private Face(String name) { this.name = name; } public static Face getByIndex(int index) { Face[] faces = Face.values(); Face face = faces[index]; return face; } public static Face getRandom() { Face[] faces = Face.values(); int len = faces.length – 1; int rand = random.nextInt(len); int index = rand % len ; Face face = faces[index]; return face; } String getName() { return name; } public String toString() { return name; } }

,

public class Punter { private static final int DEFAULT_LIMIT = 0; private static final int DEFAULT_BALANCE = 100; enum State { NOT_BETTING, BETTING, RECEIVING_WINNINGS }; State state; private String name; private int balance; private int limit; private int currentBet; public Punter(String name, int balance, int limit) { if (name == null || name .isEmpty()) { throw new IllegalArgumentException("Name cannot be null or empty"); } if (balance < 0) { throw new IllegalArgumentException("Balance cannot be negative"); } if (limit < 0 || limit > balance) { throw new IllegalArgumentException("Limit cannot be negative or greater than initial balance"); } this.name = name; this.balance = balance; this.limit = limit; this.state = State.NOT_BETTING; this.currentBet = 0; } public Punter(String name, int balance) { this(name, balance, DEFAULT_LIMIT); } public Punter(String name) { this(name, DEFAULT_BALANCE, DEFAULT_LIMIT); } public String getName() { return name; } public int getBalance() { return balance; } public int getLimit() { return limit; } public void setLimit(int limit) { if (limit < 0) { throw new IllegalArgumentException("Limit cannot be negative."); } if (limit > balance) { throw new IllegalArgumentException("Limit cannot be greater than balance."); } if (state.equals(State.BETTING)) { throw new RuntimeException("Cannot set limit while betting"); } this.limit = limit; } public boolean balanceExceedsLimitBy(int amount) { return (balance – amount > limit); } public void placeBet(int bet) { if (bet < 0) { throw new IllegalArgumentException("Bet cannot be negative."); } if (!balanceExceedsLimitBy(bet)) { throw new IllegalArgumentException("Placing bet would go below limit."); } if (state.equals(State.NOT_BETTING)) { balance = balance – bet; currentBet = bet; state = State.BETTING; } } public void returnBet() { if (state.equals(State.BETTING)) { balance = balance + currentBet; currentBet = 0; state = State.NOT_BETTING; } } public void receiveWinnings(int winnings) { if (state.equals(State.RECEIVING_WINNINGS)) { if (winnings < 0) { throw new IllegalArgumentException("Winnings cannot be negative."); } balance = balance + winnings; state = State.NOT_BETTING; } } public void loseBet() { if (state.equals(State.BETTING)) { balance = balance – currentBet; currentBet = 0; state = State.NOT_BETTING; } } public String toString() { return String.format("Player: %s, Balance: %d, Limit: %d", name, balance, limit); } }

,

import java.util.List; import java.util.Scanner; public class BatchModeGame { static Scanner console = new Scanner(System.in); public static void play(Punter punter, List<Die> dice) { System.out.println("nplayBatchMode"); int initialBalance = punter.getBalance(); String ans = null; System.out.print("nHow many games? (default 1000): "); ans = console.nextLine(); int numberOfGames = 1000; try { numberOfGames = Integer.parseInt(ans); } catch (NumberFormatException e) { System.out.println("Invalid entry, using default."); } int stdBet = 10; System.out.print(String.format("nEnter standard bet (default %d): ",stdBet)); ans = console.nextLine(); try { stdBet = Integer.parseInt(ans); } catch (NumberFormatException e) { System.out.println("Invalid entry, using default."); } boolean useStandardPick = false; Face pick = null; System.out.print(String.format("nUse standard pick or random (S/R): ")); ans = console.nextLine(); if (ans.equalsIgnoreCase("S")) { String betPrompt = "Select Symbol: 1 – Fish, 2 – Prawn, 3 – Crab, 4 – Rooster, 5 – Gourd, 6 – Stag"; System.out.println(betPrompt); ans = console.nextLine(); int selection; try { selection = Integer.parseInt(ans); if (selection < 1 || selection > 6) { throw new NumberFormatException(); } pick = Face.getByIndex(selection-1); System.out.println(String.format("Using standard pick %s.", pick)); useStandardPick = true; } catch (NumberFormatException e) { System.out.println(String.format("Invalid entry, using random pick.")); } } System.out.println(String.format("nStarting batch mode game for %s with initial balance %d, limit $%d, and standard bet %d.00", punter.getName(), initialBalance, punter.getLimit(), stdBet)); int roundCount = 0; while (roundCount != numberOfGames && punter.balanceExceedsLimitBy(stdBet)) { if (!useStandardPick) { pick = Face.getRandom(); } System.out.println(String.format("n%s bets %d on %s, starting with balance $%d", punter.getName(), stdBet, pick, punter.getBalance())); int winnings = Round.play(punter, dice, pick, stdBet); roundCount++; System.out.println(String.format("nRolled %s, %s, %s", dice.get(0).getFace(), dice.get(1).getFace(), dice.get(2).getFace())); if (winnings > 0) { System.out.println(String.format("n%s won %d, balance now %dnn", punter.getName(), winnings, punter.getBalance())); } else { System.out.println(String.format("n%s lost %d, balance now %dnn", punter.getName(), stdBet, punter.getBalance())); } } System.out.println(String.format("Player leaves game with $%d after %d rounds, having started with $%d", punter.getBalance(), roundCount, initialBalance)); } }

,

public class Die { private Face face; public Die() { face = Face.getRandom(); } public Face getFace() { return face; } public Face roll() { return Face.getRandom(); } public String toString() { return face.toString(); } }