public class IntTuple{
public int first;
public int second;
public IntTuple(int one, int two){
this.first = one;
this.second = two;
}
}
public class IntTuple{
public int first;
public int second;
public IntTuple(int one, int two){
this.first = one;
this.second = two;
}
}
public class IntTuple{
public int first;
public int second;
public IntTuple(int one, int two){
this.first = one;
this.second = two;
}
}
public class IntTuple{
public int first;
public int second;
public IntTuple(int one, int two){
this.first = one;
this.second = two;
}
}
public class IntTuple{
public int first;
public int second;
public IntTuple(int one, int two){
this.first = one;
this.second = two;
}
}
public class IntTuple{
public int first;
public int second;
public IntTuple(int one, int two){
this.first = one;
this.second = two;
}
@Override
public String toString(){
return String.format("(%d, %d)", this.first, this.second);
}
}
public class IntTuple{
public int first;
public int second;
public IntTuple(int one, int two){
this.first = one;
this.second = two;
}
@Override
public String toString(){
return String.format("(%d, %d)", this.first, this.second);
}
@Override
public boolean equals(Object obj){
// code here
}
}
@Override
public boolean equals(Object obj){
}
@Override
public boolean equals(Object obj){
//check of obj is null
if(obj == null){
return false;
}
}
@Override
public boolean equals(Object obj){
//check of obj is null
if(obj == null){
return false;
}
// check if they are the same instance
if(this == obj){
return true;
}
}
@Override
public boolean equals(Object obj){
//check of obj is null
if(obj == null){
return false;
}
// check if they are the same instance
if(this == obj){
return true;
}
// check if obj is same type
if(!(obj instanceof IntTuple)){
return false;
}
}
@Override
public boolean equals(Object obj){
//check of obj is null
if(obj == null){
return false;
}
// check if they are the same instance
if(this == obj){
return true;
}
// check if obj is same type
if(!(obj instanceof IntTuple)){
return false;
}
// cast to same type
IntTuple tuple = (IntTuple)obj;
}
@Override
public boolean equals(Object obj){
//check of obj is null
if(obj == null){
return false;
}
// check if they are the same instance
if(this == obj){
return true;
}
// check if obj is same type
if(!(obj instanceof IntTuple)){
return false;
}
// cast to same type
IntTuple tuple = (IntTuple)obj;
// check if all fields are the same
return tuple.first == this.first && tuple.second == this.second;
}
When a player makes a guess, the program should respond with one of the four cardinal directions: "North", "South", "East", "West", indicating the direction of the hidden item from the guess. For simplicity, the program will only respond "North" or "South" if the player's guess is not on the same row, or x coordinate, as the location, and "East" or "West" only if the player's guess is on the same row as the location. If the player guesses correctly, simply print "Found!" and terminate the program. If the player repeats a guess, the program should print "Repeat!" instead of a cardinal direction.
The hidden location should be randomly generated and stored in an instance of the IntTuple class defined above as a global variable, and the program should maintain a global list of IntTuples representing the locations already guessed.
import java.util.Random;
import java.util.List;
import java.util.LinkedList;
public class TupleExample{
public static List<IntTuple> guesses;
public static Random random;
public static IntTuple location;
public static String makeGuess(int x, int y){
}
}
import java.util.Random;
import java.util.List;
import java.util.LinkedList;
public class TupleExample{
public static List<IntTuple> guesses;
public static Random random;
public static IntTuple location;
public static String makeGuess(int x, int y){
if(guesses == null){
guesses = new LinkedList<IntTuple>();
}
}
}
import java.util.Random;
import java.util.List;
import java.util.LinkedList;
public class TupleExample{
public static List<IntTuple> guesses;
public static Random random;
public static IntTuple location;
public static String makeGuess(int x, int y){
if(guesses == null){
guesses = new LinkedList<IntTuple>();
}
if(random == null){
random = new Random();
}
}
}
import java.util.Random;
import java.util.List;
import java.util.LinkedList;
public class TupleExample{
public static List<IntTuple> guesses;
public static Random random;
public static IntTuple location;
public static String makeGuess(int x, int y){
if(guesses == null){
guesses = new LinkedList<IntTuple>();
}
if(random == null){
random = new Random();
}
if(location == null){
location = new IntTuple(random.nextInt(10), random.nextInt(10));
}
}
}
import java.util.Random;
import java.util.List;
import java.util.LinkedList;
public class TupleExample{
public static List<IntTuple> guesses;
public static Random random;
public static IntTuple location;
public static String makeGuess(int x, int y){
if(guesses == null){
guesses = new LinkedList<IntTuple>();
}
if(random == null){
random = new Random();
}
if(location == null){
location = new IntTuple(random.nextInt(10), random.nextInt(10));
}
// MORE CODE GOES HERE
}
}
IntTuple guess = new IntTuple(x, y);
IntTuple guess = new IntTuple(x, y);
if(guess.equals(location)){
return "Found!";
}
IntTuple guess = new IntTuple(x, y);
if(guess.equals(location)){
return "Found!";
}
if(guesses.contains(guess)){
return "Repeat!";
}
IntTuple guess = new IntTuple(x, y);
if(guess.equals(location)){
return "Found!";
}
if(guesses.contains(guess)){
return "Repeat!";
}
guesses.add(guess);
IntTuple guess = new IntTuple(x, y);
if(guess.equals(location)){
return "Found!";
}
if(guesses.contains(guess)){
return "Repeat!";
}
guesses.add(guess);
if(guess.first > location.first){
return "North";
}
if(guess.first < location.first){
return "South";
}
IntTuple guess = new IntTuple(x, y);
if(guess.equals(location)){
return "Found!";
}
if(guesses.contains(guess)){
return "Repeat!";
}
guesses.add(guess);
if(guess.first > location.first){
return "North";
}
if(guess.first < location.first){
return "South";
}
if(guess.second > location.second){
return "West";
}else{
return "East";
}