You are on page 1of 9

UJIAN TENGAH SEMESTER

PEMROGRAMAN MOBILE

NAMA : IQBAL FATHURROHMAN


NPM : 43A87006180178

SEKOLAH TINGGI MANAJEMEN INFORMATIKA DAN


KOMPUTER STMIK BANI SALEH
2021/2022
Gambar 1.1 Hasil Akhir Tampilan Bilangan Genap
Gambar 1.2 Hasil Akhir Tampilan Bilangan Ganjil
Code Program

 Activity_main.xml
 <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<RelativeLayout
android:id="@+id/myRelativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:id="@+id/profile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#48B1F2"
android:padding="6dp"
android:orientation="horizontal">

<ImageView
android:id="@+id/imageView"
android:layout_width="78dp"
android:layout_height="72dp"
app:srcCompat="@drawable/icon" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#48B1F2"
android:padding="6dp"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Menampilkan bil. ganjil genap dari
deret
array" android:textSize="10sp"
android:textStyle="bold" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/npm"
android:textSize="10sp" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/nama"
android:textSize="10sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/kelas"
android:textSize="10sp" />

</LinearLayout>

</LinearLayout>

<TableLayout
android:id="@+id/body"
android:layout_below="@+id/profile"
android:layout_alignParentLeft="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="6dp"
android:paddingBottom="6dp">

<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:layout_width="85dp"
android:layout_height="wrap_content"
android:text="Bilangan: " />

<EditText
android:id="@+id/ViewArray"
android:layout_width="270dp"
android:layout_height="wrap_content"
android:textAlignment="textEnd" />

</TableRow>

<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:layout_width="85dp"
android:layout_height="wrap_content"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="6dp"
android:orientation="vertical">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="6dp"
android:orientation="vertical">

<RadioGroup
android:id="@+id/radio"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/radioGenap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bilangan Genap"
android:checked="true" />

<RadioButton
android:id="@+id/radioGanjil"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bilangan Ganjil" />

</RadioGroup>
<Button
android:id="@+id/btnArray"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginTop="12dp"
android:background="#F6F6F6"
android:text="Tampil Data"
android:padding="10dp"
android:layout_below="@+id/radio"
android:layout_alignRight="@+id/radio"
android:textColor="#000000" />
</RelativeLayout>
</LinearLayout>
</TableRow>

<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="85dp"
android:layout_height="wrap_content"
android:text="Hasil: " />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="6dp"
android:orientation="vertical">

<EditText
android:id="@+id/ResultArray"
android:layout_width="270dp"
android:layout_height="wrap_content"
android:textAlignment="textEnd" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="6dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Total Deret = " />

<TextView
android:id="@+id/TotalArray"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Null" />
</LinearLayout>
</LinearLayout>
</TableRow>
</TableLayout>
</RelativeLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

 MainActivity.java

package com.example.uts_iqbal;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public class MainActivity extends AppCompatActivity {


ArrayUTS Arrayuts = new ArrayUTS();
EditText ViewArray, ResultArray;
TextView TotalArray;
Button btnArray;
// RadioGroup radio;
// RadioButton radioGenap;
// RadioButton radioGanjil;
RadioGroup radioSexGroup;
RadioButton radioSexButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Menampilkan Array
ViewArray = findViewById(R.id.ViewArray);
String resultviewArray = Arrayuts.ArrayutsView();
ViewArray.setText(resultviewArray);

// Menampilkan hasil berupa data sesuai dengan index


radioSexGroup = (RadioGroup) findViewById(R.id.radio);
btnArray = findViewById(R.id.btnArray);
TotalArray = (TextView)findViewById(R.id.TotalArray);
btnArray.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int selectedId = radioSexGroup.getCheckedRadioButtonId();
radioSexButton = (RadioButton) findViewById(selectedId);

// Hasil
ResultArray = findViewById(R.id.ResultArray);
String hasilArray = Arrayuts.ArrayutsGet((String)
radioSexButton.getText());
ResultArray.setText(hasilArray);

// Jumlah
TotalArray = (TextView)findViewById(R.id.TotalArray);
String totalArray = Arrayuts.ArrayutsTotal((String)
radioSexButton.getText());
TotalArray.setText(totalArray);
}
});
}
}
 ArrayUTS
 package com.example.uts_iqbal;

public class ArrayUTS {


int[] ArrayList = {65, 14, 43, 6, 15, 8};
public String ArrayutsGet(String indexArray){
int i;
String hasilarray = "";
for (i = 0; i < ArrayList.length; i++) {
if (indexArray.equals("Bilangan Genap")){
if(ArrayList[i]% 2 ==0){
hasilarray = hasilarray + " " +
String.valueOf(ArrayList[i]) ;
}
}else {
if (ArrayList[i]% 2 !=0)
{ hasilarray = hasilarray + " "
+
String.valueOf(ArrayList[i]);
}
}
}
return hasilarray;

public String ArrayutsTotal(String indexArray){


int i;
int total = 0;
String hasilarray = "";
for (i = 0; i < ArrayList.length; i++) {
if (indexArray.equals("Bilangan Genap")){
if(ArrayList[i]% 2 ==0){
total = total + ArrayList[i];
hasilarray = String.valueOf(total);
}
}else {
if (ArrayList[i]% 2 !=0){
total = total + ArrayList[i];
hasilarray = String.valueOf(total);
}
}
}
return hasilarray;

}
public String ArrayutsView(){
int i;
String viewarray = "";
for (i = 0; i < ArrayList.length; i++) {
viewarray = viewarray + " " +
String.valueOf(ArrayList[i]);
}
return viewarray;
}

 Strings.xml

<resources>
<string name="app_name">UTS_IQBAL</string>
<string name="npm">NPM: 43A87006180178</string>
<string name="nama">NAMA: IQBAL FATHURROHMAN</string>
<string name="kelas">KELAS: S1/TI/07/K/P</string>
</resources>

You might also like