[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/RoyTien/Java-Programming-Exercises/master/DotCom.java [Back]  [Original]

import java.util.ArrayList;

public class DotCom{
	private ArrayList locationCells;
	private String name;

	public void setLocationCells(ArrayList loc){
		locationCells = loc;
	}

	public void setName(Stirng n){
		name = n;
	}

	public String checkYourself(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;
	}
}

/*import java.util.*;

public class DotCom{
	private ArrayList locationCells;
	private String name;
	
	public void setLocationCells(ArrayList loc){
		locationCells = loc;
	}
	
	public void setName(String n){
		name = n;
	}
	
	public String checkYourself(String userInput){
		String result = "miss";
		int index = locationCells.indexOf(userInput);
		if(index >= 0){
			locationCells.remove(index);
			
			if(locationCells.isEmpty()){
				result = "kill";
				System.out.println("You sunk " + name);
			}else{
				result = "hit";
			}
		}
		return result;
	}
}*/

Web Proxy Viewer  |  New URL  |  Original Page