VB icon

Age Calculator

Email
Submitted on: 7/30/2015 1:20:32 PM
By: Jake R. Pomperada  
Level: Beginner
User Rating: Unrated
Compatibility: Java (JDK 1.1), Java (JDK 1.2), Java (JDK 1.3), Java (JDK 1.4), Java (JDK 1.5)
Views: 4552
author picture
 
     I have wrote a simple program that will ask the user its birth month, birth day and birth year and then the program will check and determine the present age of the user. The code uses calendar libraries in Java programming language. If you have some questions about programming, about my work please send mu an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com. People here in the Philippines can contact me at my mobile number 09173084360. Thank you very much and Happy Programming.

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Age Calculator
// Description:I have wrote a simple program that will ask the user its birth month, birth day and birth year and then the program will check and determine the present age of the user. The code uses calendar libraries in Java programming language.
If you have some questions about programming, about my work please send mu an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com. People here in the Philippines can contact me at my mobile number 09173084360.
Thank you very much and Happy Programming.
// By: Jake R. Pomperada
//**************************************

// age_calculator.java
// Programmer : Mr. Jake R. Pomperada, MAED-IT
// Date: July 30, 2015
// Tools : Netbeans 8.0.2
// Email : jakerpomperada@yahoo.com and jakerpomperada@gmail.com
// Write a program that will determine the age of the person.
 import java.util.Scanner; 
 import java.util.GregorianCalendar; 
 import java.util.Calendar; 
 public class age_calculator { 
private static int age_checker(int y, int m, int d) { 
 Calendar cal = new GregorianCalendar(y, m, d); 
 Calendar now = new GregorianCalendar(); 
 
 int age_result = now.get(Calendar.YEAR) - cal.get(Calendar.YEAR); 
 if((cal.get(Calendar.MONTH) > now.get(Calendar.MONTH)) 
|| (cal.get(Calendar.MONTH) == now.get(Calendar.MONTH) 
&& cal.get(Calendar.DAY_OF_MONTH) > now.get(Calendar.DAY_OF_MONTH))) 
 { 
age_result--; 
 } 
 return age_result; 
} 
public static void main(String [] args) { 
 Scanner input = new Scanner(System.in); 
char ch;
do {
 int month=0,day=0,year=0;
 System.out.println();
 System.out.print("\t Age Checker Program ");
 System.out.println("\n");
 System.out.print("Enter Birth Month : "); 
 month = input.nextInt();
 System.out.print("Enter Birth Day: "); 
 day = input.nextInt();
 System.out.print("Enter Birth Year : "); 
 year = input.nextInt();
 System.out.println("Your present age is " 
 + age_checker(year,month,day)+ " years old.");
 System.out.println();
 System.out.print("\nDo you want to continue (Type y or n) : ");
 ch = input.next().charAt(0);
 } while (ch == 'Y'|| ch == 'y'); 
 System.out.println();
 System.out.print("\t THANK YOU FOR USING THIS PROGRAM");
 System.out.println("\n\n");
}
 }


Other 53 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.