Hello,
I'm in the middle of creating a simple java-based game (in the mold of the old "Battleship" board game). I have built several class files within a package called "maritime" that determine the names and locations of the ships and islands that will lay over a grid (based on x and y coordinates). For the most part, I think my code is correct but I seem to have a symbol conflict between a couple of the classes I've produced. I have a class called "Location" that simply takes in an x and a y coordinate and returns a string in the mold of "(x,y)". High up in my class hierarchy, I have a class called "SimObject" which generally takes in a name and location for the object to be produced (island or ship). But when I try to create a location class object within the SimObject class file, I get a compile-time error that says "cannot resolve symbol" and lists "class Location" and "class maritime.SimObject" as the culprits. The Location.java file compiles just fine (though it's outside the class hierarchy) but the other files don't and it all seems to stem from Location.java. Does anyone have any ideas? I have my code posted below.
Thanks,
Jisoo22
Location.java
simObject.java
I'm in the middle of creating a simple java-based game (in the mold of the old "Battleship" board game). I have built several class files within a package called "maritime" that determine the names and locations of the ships and islands that will lay over a grid (based on x and y coordinates). For the most part, I think my code is correct but I seem to have a symbol conflict between a couple of the classes I've produced. I have a class called "Location" that simply takes in an x and a y coordinate and returns a string in the mold of "(x,y)". High up in my class hierarchy, I have a class called "SimObject" which generally takes in a name and location for the object to be produced (island or ship). But when I try to create a location class object within the SimObject class file, I get a compile-time error that says "cannot resolve symbol" and lists "class Location" and "class maritime.SimObject" as the culprits. The Location.java file compiles just fine (though it's outside the class hierarchy) but the other files don't and it all seems to stem from Location.java. Does anyone have any ideas? I have my code posted below.
Thanks,
Jisoo22
Location.java
Code:
package maritime;
public class Location
{
int co1;
int co2;
public Location (int x, int y)
{
co1 = x;
co2 = y;
}
public String toString()
{
String temp = "(" + co1 + ", " + co2 + ")";
return temp;
}
}//class Location
simObject.java
Code:
package maritime;
abstract public class SimObject
{
protected String name;
protected Location loc = new Location(0,0);
public SimObject(String name, Location location)
{
name = name;
loc = location;
System.out.println("SimObject " + name + " constructed");
}
abstract public String toString();
}//class SimObject