This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please Help I am lost!!!

 
Nancy Bradley
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an assignment where I should write a Java abstract class which will be the base to calculate some points of a competition. The points are assign different depending on weather the person is a boy,girl,man or woman.
I wrote the abstract class and then a class for each one of the groups. When I tried to write the test I get error messages for each of the groups that says:
cannot resolve symbol
constructor Girl(java.lang. String, java.lang.String)
This piece is not finish yet, I just do not know what to do.
If anyone knows where I can find a good reading on abstract class that will be helpful too. I do not have the concept clear.
Any help will be gratly appreciated.
Thanks,
Nancy
This is the code I wrote:
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming you know the type of object you will be dealing with at compile time, you could have something like this:
- an abstract Rewards class, with an abstract calculate method
- four implementations of this class, one for each type of person.
- an abstract class (or interface) Person
- four implementations of this class
If you have this you can write:

If you don't know which type of person you will be dealing with till run time, you'll need a factory class as well. The you can write:

All you need to remember about abstract classes is they are basically templates - they don't necessarily do anything, but they do force all subclasses to do something - in this case implement a calculate method.
 
Mathias Nilsson
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you declare a class "abstract" then it cannot be instantiated. That is you can't make an instance of it.
The diffrence between an abstract class and a interface is that an abstract class can have none abstract methods.
If you should make a abstract class of a man,woman,boy,etc then you should try to locate something that they all have incommon.
Ears, Eyes, head, neck, body, and so on.
In an abstract class you can return values in a method

if you had a abstract method in the abstract class then you would force the Girl class to include the method.


Here you would have a compile error because the Girl class didn't include the getName method. It's up to the Girl class to supply the implementation of the getName() method.
Hope this make sence. There are probably experienced java programmers that would explain this more clearly.
// Mathias
 
Nancy Bradley
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I will try again
Nancy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic