编写类InsuranceCheck和自定义异常类AgeException。用2010年减去某人的出生年份计算其年龄。然后用年龄减去16计算其驾龄。如果驾龄少于4年的驾驶员,每年需缴纳2000元的保险费,其他人则交付1000元,如果未满16周岁,则不需要保险,并且引发异常(年龄太小,不用保险);
解决方案 »
- Annotation的一个小问题
- [求助]Junit测试时遇到一个奇怪的问题:FileNotFoundException
- J2SE综合问题
- 华为公司 java 面试题 大家一起来讨论
- 关于嵌套类的问题???
- j2se j2ee ejb jms之间是怎么个关系呢??
- 用java拨打手机号码
- 数据库相关
- 连接数据库!!!
- 要过年了!我的分太多了,给大家送点分!如果是斑竹作弊自己给自己加分,那我也没办法了!让作弊者生个儿子没屁眼,呵呵!大家监督一下,看斑竹这次还是否故技重演!我给大家送分!希望大家买个面子哦!
- 通过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。
求分