This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I'm working on a project that has been going well but I have one snag that I can't figure out. I have an application that has an App class , a Person class , an Employee class that extends Person , a Customer class that extends Person and implements Billable , and a Billable interface. I have created a vector that contains Person objects in which some are Customer objects and others are Employee objects. I'm trying to get at the amountDue of these objects as you can see in the code below but I'm not sure if the problem is somewhere else in the code (possibly in the other classes) so I will include all of the code in my project.
The code for the entire application is here:
If someone could give me some insight on this it would be great. If you're still reading this long post I'm eternally greatful and thankful. thanks, -Scott Edited to try to stop horizontal scrolling - barry [ May 04, 2003: Message edited by: Barry Gaunt ]
So Scott, you didn't actually say what your problem was. What exactly do you need help with?
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Joined: Apr 01, 2003
I'm getting a compile error when I try to using my amountDue method. As I wrote in my comment when I try to use the amountDue method of the objects in the loop I get a "cannot resolve symbol : method getAmount ()" . It should be able to work because if they pass through the if statement then they must be Customer objects. I also tried using an instanceof statement to test this. I know it must be hard for you guys to understand what I'm getting at it's just kind of hard to explain because I'm pretty sure my problem has to do with one of my custom classes. thanks for the help, -Scott
Joined: Jan 30, 2002
Person consumer = (Customer) people.get(i); Bit by polymorphism! If I read your first post correctly, the Customer is a Billable, but Person is not. So casting to the more general class will cause a compile time error because Person does not have a getAmount() method. You have the right idea, it's just that you should cast to the interface instead (or Customer). Try this instead:
On editing my post I noticed that you had System.out.prinln instead of System.out.println. Maybe that was the problem? [ May 03, 2003: Message edited by: Michael Morris ]
Joined: Apr 01, 2003
Yeah the System.out.println was a typo I made at the last second and not the root of the problem. I took your advice and change the Billable stuff but I still get the same compile error that I did before. Quite strange. thanks for the help though, -Scott
I've scanned through this post and would like to help if I can. However, I don't have the time to go through every line of code that you posted. Will you please post the line that gives the compiler error (and a few lines before and after to give it some context), along with the exact compiler error. This should help clear things up so that we can point out the exact changes you need to make to fix the problem. Cheers! Layne
After the suggestion from Michael and Irene I changed the the one statement to Customer consumer = (Customer) people.get(i) which is the line before where I still get the same compile error that I did originally. The compile error is: cannot resolve symbol : method getAmount () . thanks again for the help, -Scott