Age Calculator

This is a discussion on Age Calculator within the Android Forum forums, part of the Android Discussions category; hi i make this app to calculte the age , but i still i have error can any one help me plz .. Code: package ...

Results 1 to 2 of 2

Thread: Age Calculator

  1. #1
    Android Lurker azizah's Avatar
    Join Date
    Apr 2012
    Posts
    1

    Age Calculator

    hi i make this app to calculte the age , but i still i have error
    can any one help me plz ..
    Code:
    package com.sa;
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;
    import android.widget.Toast;
    import java.util.*;
    public class XaozActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Button n=(Button)findViewById(R.id.sum);
    final EditText e=(EditText)findViewById(R.id.editText1);
    final EditText e2=(EditText)findViewById(R.id.editText2);
    final EditText e3=(EditText)findViewById(R.id.editText3);
    final TextView x=(TextView)findViewById(R.id.textView1);
    n.setText("push");
    n.setOnClickListener(new View.OnClickListener(){
    @Override
    public void onClick(View v){
    int year=Integer.parseInt(e.getText().toString());
    int day=Integer.parseInt(e2.getText().toString());
    int month=Integer.parseInt(e3.getText().toString());
    Calendar cd = Calendar.getInstance();
    if(year > cd.get(Calendar.YEAR)){
    x.setText("Invalid ");
    System.exit(0);}
    if(month < 1 || month > 12){
    x.setText("Please enter monthe between 1 to 12 ");}
    else{
    month--;
    if(year == cd.get(Calendar.YEAR)){
    if(month > cd.get(Calendar.MONTH)){
    x.setText("invalid month ");
    System.exit(0);
    }
    }
    }
    day = Integer.parseInt(in.readLine());
    if(month == 0 || month == 2 || month == 4 || month == 6 || month == 7 || 
    month == 9 || month == 11){
    if(day > 31 || day < 1){
    x.setText("Please enter monthe between 1 to 31 ");
    System.exit(0);
    }
    }
    else if(month == 3 || month == 5 || month == 8 || month == 10){
    if(day > 30 || day < 1){
    x.setText("Please enter monthe between 1 to 30 ");
    System.exit(0);
    }
    }
    else{
    if(new GregorianCalendar().isLeapYear(year)){
    if(day < 1 || day > 29){
    x.setText("Please enter monthe between 1 to 29 ");
    System.exit(0);
    }
    }
    else if(day < 1 || day > 28){
    x.setText("Please enter monthe between 1 to 28 ");
    System.exit(0);
    }
    }
    if(year == cd.get(Calendar.YEAR)){
    if(month == cd.get(Calendar.MONTH)){
    if(day > cd.get(Calendar.DAY_OF_MONTH)){
    x.setText("Invalid Date !");
    System.exit(0);
    }
    }
    }
    }
    Calendar bd = new GregorianCalendar(year, month, day);
    ageYears = cd.get(Calendar.YEAR) - bd.get(Calendar.YEAR);
    if(cd.before(new GregorianCalendar(cd.get(Calendar.YEAR), month, day))){
    ageYears--;
    ageMonths = (12 - (bd.get(Calendar.MONTH) + 1)) + (bd.get(Calendar.MONTH));
    if(day > cd.get(Calendar.DAY_OF_MONTH)){
    ageDays = day - cd.get(Calendar.DAY_OF_MONTH);
    }
    else if(day < cd.get(Calendar.DAY_OF_MONTH)){
    ageDays = cd.get(Calendar.DAY_OF_MONTH) - day;
    }
    else{
    ageDays = 0;
    }
    }
    else if(cd.after(new GregorianCalendar(cd.get(Calendar.YEAR), month, day))){
    ageMonths = (cd.get(Calendar.MONTH) - (bd.get(Calendar.MONTH)));
    if(day > cd.get(Calendar.DAY_OF_MONTH))
    ageDays = day - cd.get(Calendar.DAY_OF_MONTH) - day;
    else if(day < cd.get(Calendar.DAY_OF_MONTH)){
    ageDays = cd.get(Calendar.DAY_OF_MONTH) - day;
    }
    else
    ageDays = 0;
    }
    else{
    ageYears = cd.get(Calendar.YEAR) - bd.get(Calendar.YEAR);
    ageMonths = 0;
    ageDays = 0;
    }
    }
    }} );
    }
    [/CODE]
    Last edited by azizah; 04-23-2012 at 07:32 PM.

  2. Android.net is the premier Android Forum. Registered users do not see these ads. .

  3. #2
    Super Moderator cali's Avatar
    Join Date
    Sep 2011
    Posts
    4,830
    Thanked
    329 times
    Welcome to the site. Hope you can get this worked out.

Remove Ads

http://www.scramblerducati.org/

Sponsored Links

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Similar Threads

  1. Calculator App Problem :)
    By 0Ajax0 in forum Android Forum
    Replies: 0
    Last Post: 02-26-2012, 01:25 PM
  2. Tip Calculator
    By Mabelle71 in forum LG Ally Help
    Replies: 1
    Last Post: 05-15-2011, 06:06 PM

Search tags for this page

age calculater android
,

age calculater mobileheart.com

,

age calculator android

,

age calculator app

,
age calculator in android with app widget source code
,

age calculator in android with code

,

age calculator in android with source

,

age calculator in android with source code download

,
age calculator source in android
,

android age calculater

,

android age calculator

,

android age calculator code

,

android age calculator source code

,
code for age calculation in android app
,

download age calculator for android

Click on a term to search our sites for related topics.
Android Forum