用java里面的异常语句写保险公司编写程序计算保险金
发布网友
发布时间:2024-09-28 17:17
我来回答
共1个回答
热心网友
时间:2024-09-29 15:33
public class Premium {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Premium premium = new Premium();
double premiumCost = premium.calcPremium(1989);
System.out.println(premiumCost);
}
// 输入人员出生年份
public double calcPremium(int birthYear) {
double premiumCost = 0;// 每年需要支付的保险费用
int age = 2010 - birthYear;
if (age < 16) {
try {
throw new AgeException("年龄小于16岁,无需支付保险费!");
} catch (AgeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
int driveAge = age - 16;
if (driveAge < 4) {
premiumCost = 1000;
} else {
premiumCost = 600;
}
}
return premiumCost;
}
class AgeException extends Exception {
public AgeException(String msg) {
super(msg);
}
}
}