-
Android Lurker
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 06:32 PM.
-
04-23-2012 06:29 PM
# ADS
Google Advertisement
-
Super Moderator
Welcome to the site. Hope you can get this worked out.