• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Heck of a problem, please help.

 
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Steve, welcome to JavaRanch.
Before we try to guide you in producing a solution to your assignment, would you please post the complete assignment specification/requirements.
This can save a lot of misunderstanding or false starts which we have had in similar cases recently.

Cheers, -Barry
 
Gabriel White
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No problem barry
Here is the entire code with all of the classes
Like I mentioned before I am to:
Write statements to printout the x-position of an GeoObj named myObj
Write statements to set the y-position of myObj to 15
Write statements to set the type description of myObj to "Rectangle"

 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Mighty2000,

Welcome to JavaRanch! Please adjust your display name to meet the JavaRanch Naming Policy.
You can change it here.

Thanks!
 
Gabriel White
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok Marilyn, I changed it. Thanks for the info.
Is there anyway that someone could look at my program and give me a clue as to what I am doing wrong. It will not go between classes, because I dont know if the main method statements are correct.
Thanks
 
Gabriel White
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have actually made some headway in this assignment. I have made some changes and I am posting my new code. Now I get a compile error in the main method that states:
"GeoObj.java": Error #: 300 : method setCoord(void) not found in class geoproject.GeoObj at line 33, column 11
the x-position println works great (getCoord). I just cannot include any setCoord commands without getting this compile error.
Thanks again for your time
Steve
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

In main() where you call setCoord(), it seems that the return value of the expression inside the parens is void (per the error message "GeoObj.java": Error #: 300 : method setCoord(void) not found .

Since your method declaration requires a Coordinate2D, void is unacceptable.

Let's look inside the parens for the problem. The call to the setYpos() returns void. Perhaps you meant to write

myObj.setCoord(coord1.getYpos());

or

myObj.setCoord(coord1.getYpos( coord1.setYpos(15)));

??
 
Gabriel White
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nope, sorry, either one returns the same error. It seems that I cannot include that new object along with a get or a set command inside the parens.
Thanks for taking a look though.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

That will allow your code to compile. (Mind you, that disregards Marilyn's suggestion - something I would never dare to do ) I'll take a closer look over a coffeebreak a bit later on today.
I can't see the real use of description in Type2D you can't get at it. Also is it not better to set description when the typeCode is set rather than when it is got?
[ March 03, 2003: Message edited by: Barry Gaunt ]
 
Gabriel White
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, the Type2D method doesn't really have to return anything. According to the assignment all I have to do is pass an integer, so the Type2D setType method is rather moot. A real test is for me to yank out the constructor in the Coordinate2D class and do a and then do the println with the getCoord. As it stands now, the works great. I was able to use the constructor to test it.
And you are right (obviously ) I can just type out/bypass the GeoObj class with my new object (coord1) or (typ1) and the compiler will run.
Thanks again for having a look.
I am going to have a look at some other forums to see if I can help out elsewhere.
As you may have noticed (maybe not) I put the code in to that solve this equation thread. That works great as well.
Thanks Marylin and Barry for all of your help
peace
Steve
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad to help. BTW Steve, when people ask for code it's not aways the "best-thing" to go right out and write the code for them. Mostly it is enough to guide or nudge them in the right direction. By all means try and solve and code the problem yourself, if you want, but then give hints and tips so the question asker solves the problem almost by him-/herself. One of the biggest problems is to get people to ask the right questions.
Cheers - Barry
 
Gabriel White
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You da man. Sorry, I just saw peeps giving out the tutorial, and I felt bad for the guy. I dont even know if he got the message anyway.
np, I will nudge.
But in my case, my code seems correct but it is just broke for some strange reason. I just need a better debugger than myself to come up with some reason for failure. I guess in instances like this you don't nudge? (perhaps a little)
Anyway, please dont put too much emphasis on my code. I have already come to grips with it. I am just going to stall some more and see if I can work out an answer to my problem. But if you happen to see something obvious, please let me know. If you have to rack your brain...dont.
Peace out.
 
Always look on the bright side of life. At least this ad is really tiny:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic