-
Notifications
You must be signed in to change notification settings - Fork 1
/
ExceptionHandling.java
36 lines (31 loc) · 1.08 KB
/
ExceptionHandling.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package exceptionhandling;
import java.util.*;
public class ExceptionHandling
{
public static void main(String[] args)
{
GregorianCalendar today;
int age, thisYear, bornYr;
String answer;
Scanner scanner = new Scanner(System.in);
//AgeInputVer1 input = new AgeInputVer1( );
AgeInputVer2 input = new AgeInputVer2();
//AgeInputVer3 input = new AgeInputVer3();
age = input.getAge("How old are you? ");
today = new GregorianCalendar( );
thisYear = today.get(Calendar.YEAR);
bornYr = thisYear - age;
System.out.print("Already had your birthday this year? (Y or N) : ");
answer = scanner.next();
if (answer.equals("N") || answer.equals("n") )
{
bornYr--;
}
System.out.println("\nYou are born in " + bornYr);
}
}