编写类InsuranceCheck和自定义异常类AgeException。用2010年减去某人的出生年份计算其年龄。然后用年龄减去16计算其驾龄。如果驾龄少于4年的驾驶员,每年需缴纳2000元的保险费,其他人则交付1000元,如果未满16周岁,则不需要保险,并且引发异常(年龄太小,不用保险);

解决方案 »

  1.   


    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();
    }
    }
    }
      

  2.   

    编写类InsuranceCheck和自定义异常类AgeException。用2010年减去某人的出生年份计算其年龄。然后用年龄减去16计算其驾龄。如果驾龄少于4年的驾驶员,每年需缴纳2000元的保险费,其他人则交付1000元,如果未满16周岁,则不需要保险,并且引发异常(年龄太小,不用保险);
      

  3.   


    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);
    }}
      

  4.   

    编写类InsuranceCheck和自定义异常类AgeException。用2010年减去某人的出生年份计算其年龄。然后用年龄减去16计算其驾龄。如果驾龄少于4年的驾驶员,每年需缴纳2000元的保险费,其他人则交付1000元,如果未满16周岁,则不需要保险,并且引发异常(年龄太小,不用保险);
      

  5.   


    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);
    }}能不能给我解释下
      

  6.   


    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。
      

  7.   


    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。
    求分