mighty2000
IS-IT--Management
Hey all!!
I am new to Java. I am supposed to create 3 classes under one project/package, and I am to access thoes classes using the specific methods and data members that my wacked out instructor gave me.
Here is the question: (I am only going to show the part that I am having trouble with)
Create the following classes:
Class GeoObj
data members:
Coordinate2D coord;
Type2D type;
public methods:
public void setCoord
public Coordinate2D getCoord
I know how to go between the main method and interface the methods in a class using any object that I create. But how do you write a Method like the two above that actually go into another class and get and set what the Coordinate2D class is getting and setting? I am only allowed to use one object called myObj to access all of the other classes including the Coordinate2D class.
By the way the Coordinate2D class:
data members:
int xpos, int ypos;
public methods:
public void setXpos;
public int getXpos;
public void setYpos;
public int getXpos;
I have no trouble with this class because I tested it with new objects in the main method(basically bypassing the GeoObj class methods).
anyway, here is my code sample from the GeoObj class.
It is incomplete in the main method, because that is where I am stuck. I dont know if I need to change the main method pointers or to change the get and set methods in the GeoObj class.
Please Help if you can...
Thanks.
I am new to Java. I am supposed to create 3 classes under one project/package, and I am to access thoes classes using the specific methods and data members that my wacked out instructor gave me.
Here is the question: (I am only going to show the part that I am having trouble with)
Create the following classes:
Class GeoObj
data members:
Coordinate2D coord;
Type2D type;
public methods:
public void setCoord
public Coordinate2D getCoord
I know how to go between the main method and interface the methods in a class using any object that I create. But how do you write a Method like the two above that actually go into another class and get and set what the Coordinate2D class is getting and setting? I am only allowed to use one object called myObj to access all of the other classes including the Coordinate2D class.
By the way the Coordinate2D class:
data members:
int xpos, int ypos;
public methods:
public void setXpos;
public int getXpos;
public void setYpos;
public int getXpos;
I have no trouble with this class because I tested it with new objects in the main method(basically bypassing the GeoObj class methods).
anyway, here is my code sample from the GeoObj class.
It is incomplete in the main method, because that is where I am stuck. I dont know if I need to change the main method pointers or to change the get and set methods in the GeoObj class.
Please Help if you can...
Thanks.
Code:
package geoproject;
public class GeoObj
{
Coordinate2D coord;
Type2D type;
public void setCoord()
{
this.coord=coord;
}
public Coordinate2D getCoord()
{
return coord;
}
public void setType()
{
this.type=type;
}
public Type2D getType()
{
return this.getType();
}
public static void main(String[] args)
{
GeoObj myObj = new GeoObj();
myObj.setCoord();
System.out.println("The X position is: " + myObj.getCoord());
myObj.getCoord();
myObj.getType().setType(1);
}
}