• 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

Creating classes for entity names, has-a relationships

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 :)
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic