Loading src/main/java/ch6/Startup.java +15 −14 Changes for src/main/java/ch6/Startup.java: 15 added lines, 14 removed lines. Original line number Diff line number Diff line package ch6; class Startup { private int[] locationCells; private int numOfHits = 0; import java.util.ArrayList; public void setLocationCells(int[] locs) { public class Startup { private ArrayList<String> locationCells; // private int numOfHits = 0; // don't need to track this now public void setLocationCells(ArrayList<String> locs) { locationCells = locs; } public String checkYourself(int guess) { public String checkYourself(String userInput) { String result = "miss"; for (int cell : locationCells) { if (guess == cell) { result = "hit"; numOfHits++; break; } // end if } // end for if (numOfHits == locationCells.length) { int index = locationCells.indexOf(userInput); if (index >= 0) { locationCells.remove(index); if (locationCells.isEmpty()) { result = "kill"; } else { result = "hit"; } // end if System.out.println(result); } // end outer if return result; } // end method } // close class No newline at end of file Loading
src/main/java/ch6/Startup.java +15 −14 Changes for src/main/java/ch6/Startup.java: 15 added lines, 14 removed lines. Original line number Diff line number Diff line package ch6; class Startup { private int[] locationCells; private int numOfHits = 0; import java.util.ArrayList; public void setLocationCells(int[] locs) { public class Startup { private ArrayList<String> locationCells; // private int numOfHits = 0; // don't need to track this now public void setLocationCells(ArrayList<String> locs) { locationCells = locs; } public String checkYourself(int guess) { public String checkYourself(String userInput) { String result = "miss"; for (int cell : locationCells) { if (guess == cell) { result = "hit"; numOfHits++; break; } // end if } // end for if (numOfHits == locationCells.length) { int index = locationCells.indexOf(userInput); if (index >= 0) { locationCells.remove(index); if (locationCells.isEmpty()) { result = "kill"; } else { result = "hit"; } // end if System.out.println(result); } // end outer if return result; } // end method } // close class No newline at end of file