I do not know what is wrong. But my code will not run. And I do not know why. Thanks! The error was "Error: Could not find or load main class undefined" Because I was trying to answer this question from my java book:
The Harrison Group Life Insurance company computes annual policy premiums based on the age the customer turns in the current calendar year. The premium is computed by taking the decade of the customer’s age, adding 15 to it, and multiplying by 20. For example, a 34 year old would pay $360, which is calculated by adding the decades (3) to 15, and then multiplying by 20.
Write an application that prompts a user for the current year and a birth year. Pass both to a method that calculates and returns the premium amount, and then display the returned amount.
My code:
import java.util.Scanner;
class calculatePremium
{
public static int calculatePremium(int currentYear, int birthYear)
{
int decade = currentYear - birthYear;
decade = ((decade / 10) + 15) * 20;
return decade;
}
public static void main(String args[])
{
Scanner scan = new Scanner(System.in);
System.out.print("Enter current year : ");
int currentYear = scan.nextInt();
System.out.print("Enter birth year : ");
int birthYear = scan.nextInt();
int amt = calculatePremium(currentYear, birthYear);
System.out.println("Premium amount is : $" + amt);
}
}