Created
April 29, 2015 15:42
-
-
Save julia81/ca4aa5b9eeb67dd404be to your computer and use it in GitHub Desktop.
Age calculator which will tell the user how old they are after the input their age. Programming in Java AgeCalculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import javax.swing.*; | |
public class AgeCalculator | |
{ | |
public static void main(String[] args) | |
{ | |
GregorianCalendar now = new GregorianCalendar(); | |
int nowYear; // Current Year "nowYear" | |
int birthYear; //User inputs their birthYear | |
int yearsOld; // Stores age as yearsOld | |
birthYear = Integer.parseInt(JOptionPane.showInputDialog(null, | |
"In what year were you born?")); //Ask the user to input their birthYear | |
nowYear=now.get(GregorianCalendar.YEAR);//Finds birthYear in the GregorianCalendar | |
yearsOld= nowYear - birthYear;//Does the math to find your age | |
JOptionPane.showMessageDialog(null, | |
"This is the year you become " + yearsOld + " years old");//Outputs to the user how old they are | |
} | |
} | |
//Julia MacDonald 2015 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment