I have nearly all of the code figured out, but the instructions make getting the output and variables to match up. If anyone can assist in seeing what the instructor intends for us to do, I would greatly appreciate it.
This is a multi-class program where an abstract class implements a class and is extended by three sub-classes.
the instructions are:
Problem Definition
Create a console application in a Java Package named UseInsurnace
Create an abstract Insurance class
Create Health and Life subclasses to display different types of insurance polices and the cost per month.
Create Auto Insurance class
Add the property VIN ( Vehicle Identification Number)
Add appropriate Set and get methods for VIN
Add Constructor that calls the super class constructor and initializes VIN
Use constructors in each of the classes with appropriate arguments.
Include get and set methods, at least one of which is abstract.
Prompt the user for the type of Insurance to be displayed, and then create the appropriate object.
Also create an interface for a print() method and use this interface with both subclasses.Implement Insurance class with the following properties and methods.
public abstract class Insurance implements Print// class variables
int PolicyNumber;
double MonthlyPremium;// public methods
Insurance(int n, double b)
int getPolicyNumber()
double getMonthlyPremium()
double getAnnualPremium()
void setPolicyNumber(int n)
abstract void setMonthlyPremium(double r);
Test for the following Input
//I input the underscores to space out to make easier to read. //whitespace wasn't showing for some reason.Insurance Policy Type______Health___Life____Auto
Policy Number____________3233___1234____3333
Monthly Premium__________$200___$100____$50
VIN_____________________N/A_____N/A___…
output should appear as :
What type of insurance do you wish?
Enter 1 for Health
2 for Life
3 for Auto
2
Life Insurance Policy number is 1234
Monthly Premium is $100.00
Annual Premium is $1,200.00
I'm only getting one error in the Auto Insurance class that says that the Annual Premium Variable can not be resolved. I believe it has a lot to do with the variable declarations in the Insurance class, but it's difficult to follow the logic that instructor requires using variable names the way he does.
My output right now is close and has the same error no matter which type of insurance I choose:
What type of insurance do you wish?
Enter 1 for Health
2 for Life
3 for Auto
2
Life
Policy number is 0
Monthly Premium is .00
Annual Premium is 1,200.00
Here is the class that "uses" the others. (the class that is ran)
package useInsurnace;
import java.util.*;
public class UseInsurance
{
public static void main(String [] str) throws Exception
{
Insurance item;
char inputChar;
Scanner keyboard = new Scanner(System.in);
System.out.println("What type of insurance do you wish?");
System.out.println("Enter 1 for Health ");
System.out.println(" 2 for Life ");
System.out.println(" 3 for Auto ");
inputChar = keyboard.next().charAt(0);
if(inputChar == '1')
item = new HealthInsurance(3233,200,2400);
else if(inputChar == '2')
item = new LifeInsurance(1234,100,1200);
else if(inputChar == '3')
item = new AutoInsurance(3333, 50, 600, "987654321A2008B");
else
{
System.out.println("Invalid Insurance Choice");
return;
}
item.print();
}
}
The abstract Insurance class
package useInsurnace;
public abstract class Insurance implements Print
{
int PolicyNumber;
double MonthlyPremium;
public Insurance(int n,double b)
{
n = PolicyNumber;
b = MonthlyPremium;
}
public int getPolicyNumber()
{
return PolicyNumber;
}
public double getMonthlyPremium()
{
return MonthlyPremium;
}
public double getAnnualPremium()
{
return MonthlyPremium;
}
public void setPolicyNumber(int n)
{
PolicyNumber = n;
}
public void setAnnualPremium(double b)
{
MonthlyPremium = b;
}
public abstract void setMonthlyPremium(double r);
}
Auto Insurance class
package useInsurnace;
import java.text.DecimalFormat;
public class AutoInsurance extends Insurance
{
private String VIN;
public AutoInsurance(int n, double b, int i, String vin)
{
super(n, b);
VIN = vin;
}
public void setAnnualPremium(int i)
{
AnnualPremium = i;
}
public double getAnnualPremium()
Additional Details
The variables for monthly premium are hard coded with all the other variable values in the "UseInsurance" class and so I would just need to figure out how to get the variables to match up and then multiply the variable for monthly by 12 to get the annual. I understand the concept, but I'm working via modifying an example (quite much so), and I can't seem to follow why the instructor requires us to use the variables n and b nor how any other variables link in with the hard coded numbers.
Any ideas?
If this were a forum, it would make things much easier.