my dog learned polymorphism*
The moose likes Beginning Java and the fly likes abstract class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "abstract class" Watch "abstract class" New topic
Author

abstract class

Nancy Bradley
Ranch Hand

Joined: Feb 25, 2004
Posts: 32
I have an assignment where an abstract class Reward should be created.There will be a competition between girls,boys, women and men. They will acumulate points base on # of cans collected, books read and volunteer work, but the formula to calculate the points is different for each group.
This is what I have so far. Can anyone tell me what I am missing, and why the test program does not compile without errors?
I know this is long I appreciate any help.
Thanks
Nancy
Julie de Wet
Greenhorn

Joined: Apr 04, 2004
Posts: 17

You could also choose to have cans, lwork and bksread as instance variables in the superclass Rewards with setter methods, then calculate wouldn't have to have them as paramteres.
In the code you wrote points wasn't used even though you sent it in as a parameter to setPoints, you then overwrote the value it contained with 0, as you sat the PARAMETER points equal to cans * etc. but these variables are all 0. You never sat the instance variable points equal to anything i.e. this.points, so even if cans, etc, had contained values other than 0, when you called calculate you still would have received 0 as a result.
The toString method in each class i unneccessary as it just calls the super, this will be done anyway, if you don't provide a toString method.
Finally when you write new...then it has to be followed by a class name, i.e. Boy or Girl. Rewards Boy doesn't make any sense. A boy object is also a Rewards object, because Boy is a subclass of Rewards.
Dave Montalvo
Greenhorn

Joined: Sep 17, 2003
Posts: 5
public String toString()
{
return firstName + ' ' + lastName;
}
try changing that to:
public String toString()
{
return firstName + " " + lastName;
}
I think those single quotes should be ""
-dave
[ April 16, 2004: Message edited by: Dave Montalvo ]
 
wood burning stoves
 
subject: abstract class
 
Similar Threads
can I use an array?, how to create vertical lines?
synchronization issue
!Help! Error: Exception in thread "main" java.lang.ClassCastException
Please Help I am lost!!!
Thanks anyway