File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Creating classes for entity names, has-a relationships Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Creating classes for entity names, has-a relationships" Watch "Creating classes for entity names, has-a relationships" New topic

Creating classes for entity names, has-a relationships

Tia Rambaran

Joined: Feb 24, 2010
Posts: 1
Hi there! I'm very confused over java right now. I'm a beginner and (my prof hardly speaks English). In our assignment, we need to take some entities and create a java class/constructor and show how to instantiate them.

Here are two entities I'm currently stuck on.

For the Coordinate class, I've written:

This was following an example given to us.
However, I'm pretty sure something about it is incorrect in the instantiation..

I did a similar thing with the circle class, but something tells me I have to use a "has-a" relationship?
Or maybe I would use "has-a" only for another entity (Cat [head {Circle}, body {Rectangle}, feet {Line[4]}, tail {Line}]). which probably makes more sense...
And even then, I don't know how to go about doing that.

A little guidance would be much appreciated Thanks in advanced.
David Newton

Joined: Sep 29, 2008
Posts: 12617

I'm not sure what your instructor is aiming for here, and the constructs used to give you your requirements may be tripping you up.

The first step is to get code to compile--does your Coordinate class compile? If not, that'd be the first step.

The second step is to determine what you're actually trying to do--and where/when. When do you want to instantiate a coordinate? Are x and y ints, or floats? Does the Circle class exist yet? What might it look like?

One step at a time :)
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46353
Welcome to the Ranch

Have a look at the instructions given; they tell you what type x and y should be. You have actually declared them twice, so that will cause problems. You will have to keep only one x and one y.
I agree. Here's the link:
subject: Creating classes for entity names, has-a relationships
It's not a secret anymore!