1. Listing Program Menghitung Nilai (xml)
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/yy"
tools:context=".MenghitungNilai" >
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginBottom="106dp"
android:layout_marginLeft="50dp" >
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:textColor="#FFFFFF"
android:text="Abdul Khair Tarigan"
android:textAppearance="?android:attr/textAppearanceSmall" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView2"
android:textColor="#FFFFFF"
android:text="STMIK BUDIDARMA MEDAN"
android:textAppearance="?android:attr/textAppearanceMedium" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView3"
android:layout_marginTop="26dp"
android:textColor="#FFFFFF"
android:text="Nilai UTS"
android:textAppearance="?android:attr/textAppearanceMedium" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView4"
android:layout_alignBottom="@+id/textView4"
android:layout_toRightOf="@+id/textView2"
android:ems="10" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/euts"
android:layout_below="@+id/euts"
android:layout_marginTop="14dp"
android:ems="10" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/euas"
android:layout_alignBottom="@+id/euas"
android:layout_alignParentLeft="true"
android:textColor="#FFFFFF"
android:text="Nilai UAS"
android:textAppearance="?android:attr/textAppearanceMedium" />
2. Listing Program Menghitung Nilai (Java)
package com.example.menghitungnilai;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.EditText;
public class MenghitungNilai extends Activity {
EditText xUTS, xUAS, xNA, xNH;
int nuts, nuas;
String xnh;
double hasil;
/**Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menghitungnilai);
}
public void myClickHandler(View view){
switch(view.getId()) {
case R.id.btnproses:
xUTS = (EditText)findViewById(R.id.euts);
xUAS = (EditText)findViewById(R.id.euas);
xNA = (EditText)findViewById(R.id.enilaiangka);
xNH = (EditText)findViewById(R.id.epredikathuruf);
nuts = Integer.parseInt(xUTS.getText().toString());
nuas = Integer.parseInt(xUAS.getText().toString());
hasil = 0.4 * nuts + 0.6 * nuas ;
xNA.setText(hasil+"");
if(hasil>= 80 && hasil <=100) xnh = "A";
else if(hasil>= 70 && hasil <=79) xnh = "B";
else if(hasil>= 60 && hasil <=69) xnh = "C";
else if(hasil>= 50 && hasil <=59) xnh = "D";
else if(hasil>= 0 && hasil <=49) xnh = "E";
xNH.setText(xnh);
break;
case R.id.btnhapus:
xUTS.setText("");
xUAS.setText("");
xNA.setText("");
xNH.setText("");
break;
}
}
}
Catatan:
* Bila di klik "Proses" maka secara otomatis Nilai Angka dan Predikat Huruf akan diproses
* Bila di klik "Hapus" maka secara otomatis semua kolom akan dihapus.
0 komentar:
Posting Komentar