Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Heck of a problem, please help. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Heck of a problem, please help." Watch "Heck of a problem, please help." New topic
Author

Heck of a problem, please help.

Gabriel White
Ranch Hand

Joined: Mar 02, 2003
Posts: 233
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.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
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


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Gabriel White
Ranch Hand

Joined: Mar 02, 2003
Posts: 233
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"

Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
Hi, Mighty2000,

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

Thanks!


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Gabriel White
Ranch Hand

Joined: Mar 02, 2003
Posts: 233
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

Joined: Mar 02, 2003
Posts: 233
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

Joined: Jul 22, 2000
Posts: 9044
    
  10

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

Joined: Mar 02, 2003
Posts: 233
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

Joined: Aug 03, 2002
Posts: 7729

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

Joined: Mar 02, 2003
Posts: 233
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

Joined: Aug 03, 2002
Posts: 7729
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

Joined: Mar 02, 2003
Posts: 233
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Heck of a problem, please help.
 
Similar Threads
From the office.
garbage collection
Using ResultSet - which is a more effecient code?
From main method to contractor, it is possible?
Accessing default class methods in other packages (Bug??)