The Artima Developer Community
Sponsored Link

Java Answers Forum
Heck of a problem, please help

1 reply on 1 page. Most recent reply: Mar 9, 2003 1:05 PM by Charles Bell

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Steve

Posts: 1
Nickname: mighty2000
Registered: Mar, 2003

Heck of a problem, please help Posted: Mar 2, 2003 12:04 AM
Reply to this message Reply
Advertisement
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).

I am supposed to:
Write statements to printout the x-position of an GeoObj named myObj.
Write statements to set the y-position my myObj to 15
Write statements to set the type description of myObj to "rectangle"

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.


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);
}
}


Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: Heck of a problem, please help Posted: Mar 9, 2003 1:05 PM
Reply to this message Reply

package geoproject;
class GeoObj{

/** data members: */
Coordinate2D coord;
Type2D type;

public static void main(String[] args){
GeoObj myObj = new GeoObj();
myObj.coord = new Coordinate2D();
/** Write statements to set the y-position my myObj to 15*/
myObj.setCoord(33, 15);
myObj.type = new Type2D();

/** Write statements to printout the x-position of an GeoObj named myObj. */
System.out.println("x-position of an GeoObj named myObj: " + String.valueOf(myObj.getCoord().getXpos()));

/** Write statements to set the type description of myObj to "rectangle" */
myObj.type.setDescription("rectangle");

}

/** public method. */
public void setCoord(int x, int y){
if (coord == null) coord = new Coordinate2D();
coord.setXpos(x);
coord.setYpos(y);
}

/** public method. */
public Coordinate2D getCoord(){
return coord;
}
}

class Coordinate2D{
/** data members: */
int xpos =0;
int ypos = 0;

/** first public method.*/
public void setXpos(int xpos){
this.xpos = xpos;
}

/** second public method.*/
public int getXpos(){
return xpos;
}

/** third public method.*/
public void setYpos(int ypos){
this.ypos = ypos;
}

/** fourth public method.*/
public int getYpos(){
return ypos;
}
}


class Type2D{

String description = "";
/* No info given */

public String getDescription(){
return description;
}

public void setDescription(String description){
this.description = description;
}
}

Flat View: This topic has 1 reply on 1 page
Topic: RTF Editor / Writer and LoadRtf object. Previous Topic   Next Topic Topic: Issue using java.io.File

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use