Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Help with Extra credit!

Ben Jakuben

At the last of the interactive story course you give some extra credit.Third extra credit is age calculator.Where I have to convert the user age into month,minute and second. So how I convert the age of user into month,minute and second.

MainActivity.java
package com.almass.niyamat.agecalculator;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;


public class MainActivity extends Activity {
    private EditText mEditText;
    private Button mButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mEditText = (EditText)findViewById(R.id.editText);
        mButton = (Button)findViewById(R.id.button);
        mButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String age = mEditText.getText().toString();
            }
        });
    }
    private void newActivity (String age) {
        Intent intent = new Intent(this, AgeActivity.class);
        intent.putExtra("age", age);
        startActivity(intent);

    }

}
AgeActivity.java
package com.almass.niyamat.agecalculator;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import com.almass.niyamat.agecalculator.R;

public class AgeActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_age);
        Intent intent = getIntent();
        int age = Integer.parseInt(intent.getStringExtra("age"));

    }

}

Think of breaking down age into smaller units, such as days. Age * 365 gives me how many days equals an age. I could use the product of that and multiple by how many seconds in a day (86400) to get the age of the user in seconds. Continue to work your way through months.