import java.util.*; import javax.swing.JOptionPane; public class DotComTestDrive { public static void main(String[] args) { int numOfGuesses = 0; DotCom dot = new DotCom(); int random = (int)(Math.random() * 5); int[] locations = {random,random + 1,random + 2}; dot.setLocationCells(locations); boolean isAlive = true; while(isAlive == true) { String guess = JOptionPane.showInputDialog(null,"Enter the Number"); String result = dot.checkGuess(guess); } } } public class DotCom { private ArrayList<String> locationCells; public void setLocationCells(ArrayList<String> loc) { locationCells = loc; } public String checkGuess(String userInput) { String result = "miss"; int index = locationCells.indexOf(userInput); if(index >= 0) { locationCells.remove(index); if(locationCells.isEmpty()) { result = "kill"; } else result = "hit"; } return result; } }