activity_main.xml
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="vertical"
android:paddingTop="16dp"
tools:context=".MainActivity">
android:layout_height="fill_parent"
android:orientation="vertical">
android:layout_height="wrap_content"
android:text="Nilai absen"
android:textStyle="bold"
android:layout_marginBottom="8dp"
android:textColor="#0000FF" />
android:layout_height="wrap_content"
android:id="@+id/nilaiabsen"
android:text="0"
android:inputType="number"/>
android:layout_height="wrap_content"
android:text="Nilai Tugas"
android:textStyle="bold"
android:layout_marginBottom="8dp"
android:textColor="#0000FF" />
android:layout_height="wrap_content"
android:id="@+id/nilaitugas"
android:text="0"
android:inputType="number"/>
android:layout_height="wrap_content"
android:text="Nilai UTS"
android:textStyle="bold"
android:layout_marginBottom="8dp"
android:textColor="#0000FF" />
android:layout_height="wrap_content"
android:id="@+id/nilaiuts"
android:text="0"
android:inputType="number"/>
android:layout_height="wrap_content"
android:text="Nilai UAS"
android:textStyle="bold"
android:layout_marginBottom="8dp"
android:textColor="#0000FF" />
android:layout_height="wrap_content"
android:id="@+id/nilaiuas"
android:text="0"
android:inputType="number"/>
MainActivity.java
package com.yusuf.dani.menghitungnilaisiswa; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class MainActivity extends AppCompatActivity { private EditText edtabsen, edttugas, edtuts, edtuas; private Button btnHitung; private TextView txtnilai; private TextView txtgrade; private TextView txtketerangan; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); edtabsen = (EditText) findViewById(R.id.nilaiabsen); edttugas = (EditText) findViewById(R.id.nilaitugas); edtuts = (EditText) findViewById(R.id.nilaiuts); edtuas = (EditText) findViewById(R.id.nilaiuas); btnHitung = (Button) findViewById(R.id.tombol); txtnilai = (TextView) findViewById(R.id.nilaiakhir); txtgrade = (TextView) findViewById(R.id.nilaigrade); txtketerangan = (TextView) findViewById(R.id.nilaiketerangan); btnHitung.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // String absen = edtabsen.getText().toString(); double a = Double.parseDouble(edtabsen.getText().toString()); double t = Double.parseDouble(edtuts.getText().toString()); double u = Double.parseDouble(edtuts.getText().toString()); double ua = Double.parseDouble(edtuas.getText().toString()); double nilai = (0.1 * a) + (0.2 * t) + (0.3 * u) + (0.4 * ua); txtnilai.setText("Nilai : " + nilai); if (nilai >= 80) { txtgrade.setText("Grade A"); } else if (nilai >= 70) { txtgrade.setText("Grade B"); } else if (nilai >= 60) { txtgrade.setText("Grade C"); } else if (nilai >= 45) { txtgrade.setText("Grade D"); } else { txtgrade.setText("Grade E"); } if (nilai >= 60) { txtketerangan.setText("Keterangan :LULUS"); } else { txtketerangan.setText("Keterangan :TIDAK LULUS"); } } }); } }
Comments