0% found this document useful (0 votes)
36 views3 pages

Week 3 Convert Celcius To Farenheit: Button

This document provides steps to create two Android mobile applications. The first application converts Celsius to Fahrenheit and includes steps to set up the layout, add a button click function, and write Java code to perform the conversion. The second application calculates BMI based on a user's weight and height input. It describes adding interfaces for input/output, image handling, and Java code to calculate BMI and determine the status.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views3 pages

Week 3 Convert Celcius To Farenheit: Button

This document provides steps to create two Android mobile applications. The first application converts Celsius to Fahrenheit and includes steps to set up the layout, add a button click function, and write Java code to perform the conversion. The second application calculates BMI based on a user's weight and height input. It describes adding interfaces for input/output, image handling, and Java code to calculate BMI and determine the status.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

DFP 6223 MOBILE APPLICATION DEVELOPMENT

--------------------------------------------------------------------------------------------------------------------------------------
WEEK 3

CONVERT CELCIUS TO FARENHEIT

Step 1 File ->New ->Android Application Project

Step 2

Step 3 Letakkan function onClick

<Button
android:id="@+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/editText1"
android :onClick="convert"
android:text="Convert to Farenheit" />
Step 4
Letak header

import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

BY: PN FARIHAN ELYANA BT ZAHARI


DFP 6223 MOBILE APPLICATION DEVELOPMENT
--------------------------------------------------------------------------------------------------------------------------------------
Step 5 File *.java

public void convert(View v) {


EditText inputTeks = (EditText) findViewById(R.id.editText1);
String teks = inputTeks.getText().toString();

float celcius = Float.parseFloat(teks);


float faren = ((celcius * 9)/5)+32;

TextView label1 = (TextView) findViewById(R.id.textView2);


label1.setText(celcius + " celcius is equal to " + faren + " Farenheit");

CALCULATE BMI

Step 1 Create android application : CalBMI


Step 2

Step 3 File *.xml

< Button
android:onClick="kiraBMI"

<EditText
pada edit text -> tukar kotak color

put ImageView
Step 4
Put image into folder
CalBMI > res > drawable-ldpi

BY: PN FARIHAN ELYANA BT ZAHARI


DFP 6223 MOBILE APPLICATION DEVELOPMENT
--------------------------------------------------------------------------------------------------------------------------------------
Step 5 File *.java

public void kiraBMI(View v){

EditText att_weight = (EditText) findViewById(R.id.editText2);


double weight = Double.parseDouble(att_weight.getText().toString());

EditText att_height = (EditText) findViewById(R.id.editText1);


double height = Double.parseDouble(att_height.getText().toString());

double bmi = weight / (height * height);

ImageView imej = (ImageView) findViewById(R.id.imageView1);

String status;

if(bmi <18.5) {
status = "Underweight";
imej.setImageResource(R.drawable.kurus);
}
else if (bmi < 25)
{
status = "ok sahaja";
imej.setImageResource(R.drawable.kurus);
}
else
{
status = "Gemuk dah tu";
imej.setImageResource(R.drawable.gemuk);
}

TextView att_status = (TextView) findViewById(R.id.textView3);


att_status.setText("your BMI is " + bmi + ". Your are " + status);

BY: PN FARIHAN ELYANA BT ZAHARI

You might also like