• Post Reply Bookmark Topic Watch Topic
  • New Topic

Attribute of other class question  RSS feed

 
Matt Matthews
Greenhorn
Posts: 18
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
I am currently at University and studying computer science / software engineering and currently working on some coursework with my first classes in Java.
We have to create two objects based on the real world so I have chosen Dancer and tangoDance as mine. We shouldn't be using inheritance, as one class needs to be an attribute of the other.

I have created the two classes and currently working on the 'dancer' class. I have started declaring the instance variables for this and so far have,

public class dancer
{
private String name;
private int position;
private int age;
private int yearsDancing;
private int ableToTango;
private tangoDancer tangoDancer;

//constructors and methods to follow
}

I think I have gotten myself abit confused and probably over complicating this question about how the classes will interact with each other. Are they able to work together without using 'extends'.
I just need a clue that points me in the correct direction. Going over my books now and writing some code to find the solution. I hope I have even made my question here clear

Thanks


 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

dancer, Dancer, tangoDance, tangoDancer. You've used all these class names but they are not interchangeable. Be consistent!

Firstly, class names start with a capital letter; so Dancer not dancer.

Secondly, why no inheritance? Is a TangoDancer a Dancer? If so, maybe inheritance is the right approach. You haven't really done much to tell us the relationship between these classes.
 
Matt Matthews
Greenhorn
Posts: 18
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Welcome to the Ranch.

dancer, Dancer, tangoDance, tangoDancer. You've used all these class names but they are not interchangeable. Be consistent!

Firstly, class names start with a capital letter; so Dancer not dancer.

Secondly, why no inheritance? Is a TangoDancer a Dancer? If so, maybe inheritance is the right approach. You haven't really done much to tell us the relationship between these classes.


Sorry I really messed up my first post.

We have to select two classes and we have to think of one class as an attribute of the other. Dancer and tangoDance are what I have chosen.
We were explicitly told that one of our classes must be an attribute of the other. Our example is "'Singer' class has an attribute, 'song' of class singer which fulfills that requirment".
Then says that we will also have to develop the class that is an attribute of the other class. Such classes would allow us to create Singer and Song objects.

I was told by my teacher that using the 'extends' keyword would not be suitable for this particular question.



 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is where being precise is important. The class name TangoDance and TangoDance (once again, not capitalization) have very different connotations.

Yes, having a type of dance associated with a Dancer makes sense.

So, post your code again with the appropriate corrections, and ask your question once more; perhaps with more detail. I'm not sure exactly what your confusion is at this point.
 
nick woodward
Ranch Hand
Posts: 382
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm pretty new to all this, but what is it you want to do?

TangoDancer extends Dancer makes sense.

Dancer having the object variable 'TangoDance' doesn't imo. Not in the same way that the class 'Singer' would be related to 'Song'.

Dancer having the object variable 'Dance' would be more appropriate - the class 'Dance' could have attributes such as danceName, danceTempo etc etc. Or the Dance variable could hold an array of extended Dance objects. Like 'TangoDancer', 'Waltzer', 'Breakdancer'..... lol.

You can't do that with TangoDance imo.

*NB I could be very wrong
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nick woodward wrote:TangoDancer extends Dancer makes sense.

Yes, but I think we've established that there isn't a TangoDancer, just a TangoDance.

Dancer having the object variable 'Dance' (an array?) would be more appropriate

I think that's beyond the scope of the current assignment which is just to create a simple member.
 
nick woodward
Ranch Hand
Posts: 382
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
nick woodward wrote:TangoDancer extends Dancer makes sense.

Yes, but I think we've established that there isn't a TangoDancer, just a TangoDance.

Dancer having the object variable 'Dance' (an array?) would be more appropriate

I think that's beyond the scope of the current assignment which is just to create a simple member.


ahh. still. The relationship he is surely after is a Dancer class with a 'dance' object variable, no? This in turn can have attributes that detail the type of dance. That would seem more appropriate than Dancer having a TangoDance variable in which you can only store TangoDance objects.

Its surely like his example of Singer only having the variable 'RapSong'. It doesn't make much sense to me, but like i said i'm no expert!!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nick woodward wrote:Its surely like his example of Singer only having the variable 'RapSong'. It doesn't make much sense to me, but like i said i'm no expert!!

You are losing sight of the objective -- which is not to create a real-world model of perfect abstraction and complexity. Please be sure to take the level of the OP and the purpose of the question into account when posting.
 
Matt Matthews
Greenhorn
Posts: 18
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankfully got most of this corrected and been developing the program. My teacher told me I was looking in the wrong direction and overcomplicating things. On the right track now. Will post up my code when finished. We are currently only using BlueJ IDE before we advance into Netbeans. One poster above mentioned arrays. We have not yet start on arrays. Only 6 weeks into our software engineering class.
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't really buy the Dancer has a TangoDance relationship. Seems tenuous to me. Were there no other choices or did you have to come up with these yourself? Things from the real world that make more sense:
Computer has a Processor
Bicycle has a Wheel
Car has an Engine
Ship has a HomePort
Shipment has a Destination
Class has a Teacher
Phone has an Owner
Owner has a Phone
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!