package yichang;
import java.sql.Date;
import java.util.Calendar;
import java.util.Scanner;
public class InsuranceCheck {
public static void BornYear(int bornyear)throws AgeException{
//why this way cannot use source with the file?
int years = 2016 - bornyear;
if(years-16<0){
throw new AgeException("年齡太小,不用保險!");
}
if(years-16<4){
throw new AgeException("需要繳納2000元保險費!");
}
else{
throw new AgeException("需要支付1000元保險費!");
}
}
public static void main(String[] args) throws AgeException {
Scanner sc=new Scanner(System.in);
// System.out.println("請輸入出生年份:");
// String bornyear=sc.next();
try{
Calendar calendar = Calendar.getInstance();
Date dates = (Date) calendar.getTime();
BornYear(1996);
} catch(AgeException e){
System.out.println(e.getMessage());
}
}
}
public class InsuranceCheck {
public static void main(String[] args) throws Exception {
Calendar calendar = Calendar.getInstance();
Date dates = (Date) calendar.getTime();//Thu May 05 20:49:55 CST 2016
SimpleDateFormat sdf = new SimpleDateFormat("yyyy");//yyyy-MM-dd
String year = sdf.format(dates);
System.out.println(year);//2016
}
}