PROBLEM: 40. After hit(100), hit(100) and hit(250), score should be 3-0. Message: 40.…
- User
PROBLEM: 40. After hit(100), hit(100) and hit(250), score should be 3-0. Message: 40. After hit(100), hit(100) and hit(250), score should be 3-0. Team 0 score: expected:<3> but was:<1>
package hw2;
/**
- Models a simplified baseball-like game called Fuzzball.
- @author YOUR_NAME_HERE
/
public class FuzzballGame {
/*
- Number of strikes causing a player to be out. */ public static final int MAX_STRIKES = 2;
/**
- Number of balls causing a player to walk. */ public static final int MAX_BALLS = 5;
/**
- Number of outs before the teams switch. */ public static final int MAX_OUTS = 3;
private int numInnings; private int currentInning; private boolean topOfInning; private int team0Score; private int team1Score; private int ballCount; private int calledStrikesCount; private int currentOuts; private boolean runnerOnFirst; private boolean runnerOnSecond; private boolean runnerOnThird;
/**
- Constructs a game that has the given number of innings and starts at the top of inning 1.
- @param givenNumInnings number of innings for the game */ public FuzzballGame(int givenNumInnings) { numInnings = givenNumInnings; currentInning = 1; topOfInning = true; team0Score = 0; team1Score = 0; ballCount = 0; calledStrikesCount = 0; currentOuts = 0; }
/**
- Returns true if the game is over, false otherwise.
- @return true if the game is over, false otherwise */ public boolean gameEnded() { return currentInning > numInnings; }
/**
- Returns true if there is a runner on the indicated base, false otherwise.
- Returns false if the given argument is anything other than 1, 2, or 3.
- @param which base number to check
- @return true if there is a runner on the indicated base */ public boolean runnerOnBase(int which) { if (which == 1) { return runnerOnFirst; } else if (which == 2) { return runnerOnSecond; } else if (which == 3) { return runnerOnThird; } else { return false; } }
/**
- Returns the current inning. Innings are numbered starting at 1.
- When the game is over, this method returns the game's total number of innings, plus one.
- @return current inning, or the number of innings plus one in case the game is over */ public int whichInning() { if (gameEnded()) { return numInnings + 1; } else { return currentInning; } }
/**
- Returns true if it's the first half of the inning (team 0 is at bat).
- @return true if it's the first half of the inning, false otherwise */ public boolean isTopOfInning() { return topOfInning; }
- Assistant