I've got the program with no apparent errors, but am unable to run it due to three little problems.... On lines 25, 27, and 29 I am getting an error message that says "Cannot instantiate the type Health/Life/AutoInsurance" (each to their respective ones). Everything else is showing up as fine, so I'm not sure why this error is here, nor how to fix it. Is there something I've missed when trying to connect everything all together, or is there something else wrong? It's not offering any suggestions on how to fix it, so I'm stuck right at this final part.
Rachel Barnes wrote:I've got the program with no apparent errors...
Rob's basically covered your main problem, but there are several redundancies in your classes which may eventually come to bite you.
1. If you have a Monthly premium, you don't need an Annual one; and personally, I'd store the latter. This isn't just nitpicking; in the real world there's a distinct possibility that such a construct is illegal, since it could theoretically be used to implement a "penny-shaving" scam.
2. If your superclass already has an AnnualPremium, you don't need it in your subclasses.
Also: floating-point types are generally not what you want for values involving money; you're usually better off using BigDecimal. For more information, read this or (a slightly simpler version) this.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
posted 6 years ago
Rob Spoor wrote:You can't create instances of abstract classes or interfaces. You can use them as reference types or return types, but the actual value must be the instance of a non-abstract class.
Took care of the 'abstract' issue and it's running now. However, I'm not receiving the right output. The policy number and monthly premium are showing up as zero. The annual is fine. Can you help me locate where my problem is?
And for the other commenter, the Annual bit is required for the assignment for whatever reason, so I have to keep that.