• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Please Help I am lost!!!

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I will try again
Nancy
 
I don't even know how to spell CIA. But this tiny ad does:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic