编写类InsuranceCheck和自定义异常类AgeException。用2010年减去某人的出生年份计算其年龄。然后用年龄减去16计算其驾龄。如果驾龄少于4年的驾驶员,每年需缴纳2000元的保险费,其他人则交付1000元,如果未满16周岁,则不需要保险,并且引发异常(年龄太小,不用保险);
解决方案 »
- 求解~~
- 菜鸟求救页面自动注册问题 无验证码 是一个交友网站的。
- 原来JAVA...
- 自己做的FCKeditor2.6.2 for java例子
- 怎样能使打印的时候按照默认的设置进行打印,而不出现打印设置的对话框?
- 咋就没人回呢?????
- 小弟不才,无奈求解
- 我想把信誉值减到50分。。帮帮忙啦。。。
- 请问java web start知识?网页如何设置,client端能通过浏览器用application java应用程序?????
- Jframe, Jpanel, Jcomponent动态绘图后添加到Jframe中,绘制的图形无法显示
- 通过IP获取局域网内手机的NetworkInterface时总返回null
- String s = "a" + "b" + "c" 到底创建了几个对象?
class MyException extends Exception{
public MyException(String msg){
super(msg);
}
}public class Test { public static void execute() throws MyException {
if (true) {
throw new MyException("MyException......");
}
} public static void main(String[] args) {
try {
execute();
} catch (MyException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package com.test;import java.util.Date;public class InsuranceCheck {
public Double check(Date birthday) throws AgeException{
if(birthday==null){
throw new AgeException("生日为空");
}
int year = birthday.getYear();
int temYear=2010-year;
if(temYear<16){
throw new AgeException("年龄太小,不用保险");
}else if((temYear-16)<4){
return 2000.0d;
}else{
return 1000.0d;
}
}}
public class AgeException extends Exception{
/**
*
*/
private static final long serialVersionUID = 164570123780291206L;
public AgeException(String string) {
super(string);
}}
package com.test;import java.util.Date;public class InsuranceCheck {
public Double check(Date birthday) throws AgeException{
if(birthday==null){
throw new AgeException("生日为空");
}
int year = birthday.getYear();
int temYear=2010-year;
if(temYear<16){
throw new AgeException("年龄太小,不用保险");
}else if((temYear-16)<4){
return 2000.0d;
}else{
return 1000.0d;
}
}}
public class AgeException extends Exception{
/**
*
*/
private static final long serialVersionUID = 164570123780291206L;
public AgeException(String string) {
super(string);
}}能不能给我解释下
package com.test;import java.util.Date;public class InsuranceCheck {
public Double check(Date birthday) throws AgeException{
if(birthday==null){
throw new AgeException("生日为空");
}
int year = birthday.getYear();
int temYear=2010-year;
if(temYear<16){
throw new AgeException("年龄太小,不用保险");
}else if((temYear-16)<4){
return 2000.0d;
}else{
return 1000.0d;
}
}}
public class AgeException extends Exception{
/**
*
*/
private static final long serialVersionUID = 164570123780291206L;
public AgeException(String string) {
super(string);
}}能不能给我解释下就是按照你的需求写的逻辑 AgeException 是一个异常类,出异常了throw。
package com.test;import java.util.Date;public class InsuranceCheck {
public Double check(Date birthday) throws AgeException{
if(birthday==null){
throw new AgeException("生日为空");
}
int year = birthday.getYear();
int temYear=2010-year;
if(temYear<16){
throw new AgeException("年龄太小,不用保险");
}else if((temYear-16)<4){
return 2000.0d;
}else{
return 1000.0d;
}
}}
public class AgeException extends Exception{
/**
*
*/
private static final long serialVersionUID = 164570123780291206L;
public AgeException(String string) {
super(string);
}}能不能给我解释下就是按照你的需求写的逻辑 AgeException 是一个异常类,出异常了throw。
求分