0% found this document useful (0 votes)
70 views12 pages

Tugas 1 Praktikum Piranti Bergerak User Interface 2

This document contains code for an Android application that calculates the area and perimeter of basic shapes. It includes XML code to design the user interface, Java code for the application logic, and string resources. The UI allows the user to enter dimensions for a rectangle or triangle and select whether to calculate the area or perimeter. The code samples calculate the outputs and display the results.

Uploaded by

qwerty
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)
70 views12 pages

Tugas 1 Praktikum Piranti Bergerak User Interface 2

This document contains code for an Android application that calculates the area and perimeter of basic shapes. It includes XML code to design the user interface, Java code for the application logic, and string resources. The UI allows the user to enter dimensions for a rectangle or triangle and select whether to calculate the area or perimeter. The code samples calculate the outputs and display the results.

Uploaded by

qwerty
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/ 12

TUGAS 1

PRAKTIKUM PIRANTI BERGERAK


USER INTERFACE 2

Nama : Nabil Fitrah Abdullah


NIM : 16/400979/SV/11483
Kelas : Praktikum B
Asisten Dosen : Imam Syuhada
Tanggal : 27 Agustus 2018

LABORATORIUM TEKNOLOGI INSTRUMENTASI


DEPARTEMEN TEKNIK ELEKTRO DAN INFORMATIKA
SEKOLAH VOKASI
UNIVERSITAS GADJAH MADA
YOGYAKARTA
2018
NOMOR 1

CODING N XML
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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">

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

<TextView
android:id="@+id/namaa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/nama"
android:textSize="20sp"
android:visibility="visible" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textSize="20sp"
android:id="@+id/nama"
android:hint="@string/input_nama"
android:inputType="" />
<TextView
android:id="@+id/textView"
android:layout_marginTop="10sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/nim"
android:textSize="20sp"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textSize="20sp"
android:id="@+id/nim"
android:inputType="number"
android:hint="@string/input_nim"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/foto"
android:textSize="20sp"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="@+id/buttonfoto"
android:onClick="foto"
android:text="@string/fotoo"
/>
<Button
android:id="@+id/button"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/coba"
android:onClick="sendMessage"
android:layout_marginTop="20dp"
/>

<TextView
android:id="@+id/senddd"
android:layout_width="157dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text=""
android:textSize="20sp"
android:layout_marginTop="20dp"/>
<TextView
android:id="@+id/senddd2"
android:layout_width="157dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text=""
android:layout_marginTop="10sp"
android:textSize="20sp" />

<ImageView
android:id="@+id/imageView"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:contentDescription="@string/TODO" />

</LinearLayout>
</ScrollView>

CODING N java

package com.example.useronly.n;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

EditText namaa;
TextView tampil;
TextView tampil2;
EditText nimm;
ImageView image;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
namaa = (EditText)findViewById(R.id.nama);
tampil = (TextView)findViewById(R.id.senddd);
nimm = (EditText)findViewById(R.id.nim);
tampil2 = findViewById(R.id.senddd2);
image = (ImageView) findViewById(R.id.imageView);

}
public void sendMessage(View view) {
tampil.setTextColor(Color.BLACK);
tampil.setText(namaa.getText());
tampil2.setTextColor(Color.DKGRAY);
tampil2.setText(nimm.getText());

public void foto(View view) {


image.setImageResource(R.drawable.fotoformal);
}

CODING N string

<resources>
<string name="app_name">app_name</string>
<string name="input_nama">Input nama</string>
<string name="input_nim">input NIM</string>
<string name="nama">Nama</string>
<string name="nim">NIM</string>
<string name="foto">Foto</string>
<string name="coba">coba</string>
<string name="fotoo">fotoo</string>
<string name="TODO">TODO</string>
</resources>
Hasil Screenshoot

Nomor 2

CODING N2 xml

<?xml version="1.0" encoding="utf-8"?>


<ScrollView 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=".BangunruangActivity">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="@string/persegi_panjang"
android:textSize="20sp"
android:textStyle="bold" />
<EditText
android:id="@+id/ipanjang"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/ppanjang"
android:layout_marginBottom="5dp"
android:textSize="20sp" />

<EditText
android:id="@+id/ilebar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/plebar"
android:layout_marginBottom="5dp"
android:textSize="20sp" />

<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<RadioButton
android:id="@+id/radioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rluas"
tools:layout_editor_absoluteX="26dp"
tools:layout_editor_absoluteY="75dp" />

<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rkeliling"
tools:layout_editor_absoluteX="26dp"
tools:layout_editor_absoluteY="115dp" />
</RadioGroup>

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hitung"
tools:layout_editor_absoluteX="44dp"
tools:layout_editor_absoluteY="157dp"
android:layout_marginBottom="5dp"/>

<EditText
android:id="@+id/ohasil"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hasil"
android:textSize="20sp"
android:layout_marginBottom="5dp"/>

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20sp"
android:layout_marginTop="20sp"
android:text="@string/segitiga"
android:textSize="20sp"
android:textStyle="bold" />
<EditText
android:id="@+id/ialas"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5sp"
android:hint="@string/masukkan_alas"
android:textSize="20sp" />

<EditText
android:id="@+id/itinggi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/masukkan_tinggi"
android:layout_marginBottom="5dp"
android:textSize="20sp" />

<RadioGroup
android:id="@+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp">
<RadioButton
android:id="@+id/sluas"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rluas"
android:textSize="20sp" />

<RadioButton
android:id="@+id/skeliling"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rkeliling"
android:textSize="20sp" />
</RadioGroup>

<Button
android:id="@+id/shitung"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="@string/hitung"
/>

<EditText
android:id="@+id/ohasil2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/hasil" />
</LinearLayout>
</ScrollView>

CODING N2 java

package com.example.useronly.n2;

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.RadioButton;

public class BangunruangActivity extends AppCompatActivity {

EditText iipanjang;
EditText iilebar;
EditText oohasil;
Button hitung;
RadioButton rluas;
RadioButton rkeliling;
EditText iialas;
EditText iitinggi;
EditText oohasil2;
Button sshitung;
RadioButton rluas2;
RadioButton rkeliling2;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bangunruang);
iipanjang = (EditText)findViewById(R.id.ipanjang);
iilebar = (EditText) findViewById(R.id.ilebar);
oohasil = (EditText) findViewById(R.id.ohasil);
rluas = (RadioButton) findViewById(R.id.radioButton);
rkeliling = (RadioButton) findViewById(R.id.radioButton2);
hitung = (Button) findViewById(R.id.button);
hitung.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
double panjang = Double.parseDouble(String.valueOf(iipanjang.getText()));
double lebar = Double.parseDouble(String.valueOf(iilebar.getText()));
if (rluas.isChecked()) {
double luas = panjang * lebar;
oohasil.setText(String.valueOf(luas));
}else {
double keliling = (2*panjang)+(2*lebar);
oohasil.setText(String.valueOf(keliling));
}

}
});
iialas = (EditText)findViewById(R.id.ialas);
iitinggi = (EditText)findViewById(R.id.itinggi);
rluas2 = (RadioButton)findViewById(R.id.sluas);
rkeliling2 = (RadioButton)findViewById(R.id.skeliling);
oohasil2 = (EditText) findViewById(R.id.ohasil2);
sshitung = (Button)findViewById(R.id.shitung);
sshitung.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
double alas = Double.parseDouble(String.valueOf(iialas.getText()));
double tinggi = Double.parseDouble(String.valueOf(iitinggi.getText()));
if (rluas2.isChecked()){
double luas = (alas*tinggi)/2;
oohasil2.setText(String.valueOf(luas));
}else{
double s = Math.sqrt((alas*alas)+(tinggi*tinggi));
double keliling = s+alas+tinggi;
oohasil2.setText(String.valueOf(keliling));
}
}
});
}
}

CODING N2 str

<resources>
<string name="app_name">n2</string>
<string name="persegi_panjang">PERSEGI PANJANG</string>
<string name="ppanjang">masukkan panjang</string>
<string name="plebar">masukkan lebar</string>
<string name="rluas">Luas</string>
<string name="rkeliling">Keliling</string>
<string name="hitung">Hitung!</string>
<string name="hasil">Hasil</string>
<string name="segitiga">SEGITIGA</string>
<string name="masukkan_alas">masukkan alas</string>
<string name="masukkan_tinggi">masukkan tinggi</string>
</resources>

HASIL SCREENSHOOT

Nomor 3
CODING MyApps XML

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout 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"
android:orientation="vertical"
tools:context=".N3Activity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/perhitungan_resistor"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginBottom="5sp"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/r1"
android:hint="@string/masukkan_r1"
android:layout_marginTop="5sp"
android:layout_marginBottom="5sp"
android:textSize="20sp"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5sp"
android:layout_marginTop="6sp"
android:id="@+id/r2"
android:hint="@string/masukkan_r2"
android:textSize="20sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5sp"
android:id="@+id/r3"
android:layout_marginTop="6sp"
android:hint="@string/masukkan_r3"
android:textSize="20sp"/>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/rpar"
android:layout_marginTop="5sp"
android:layout_marginBottom="5sp"
android:textSize="20sp"
android:text="@string/paralel"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_marginTop="5sp"
android:layout_marginBottom="5sp"
android:text="@string/seri"
android:id="@+id/rseri"
/>
</RadioGroup>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5sp"
android:layout_marginBottom="5sp"
android:id="@+id/button"
android:text="@string/hitung"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/hasil"
android:hint="@string/hasil"
android:textSize="20sp"
android:layout_marginTop="5sp"
android:layout_marginBottom="5sp"
/>

</LinearLayout>

CODING MyApps Java

package com.example.useronly.myapplication;

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.RadioButton;

public class N3Activity extends AppCompatActivity {


EditText ir1;
EditText ir2;
EditText ir3;
RadioButton rrseri;
RadioButton rrpar;
Button ibutton;
EditText ohasil;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.n3);
ir1 = (EditText)findViewById(R.id.r1);
ir2 = (EditText) findViewById(R.id.r2);
ir3 = (EditText) findViewById(R.id.r3);
rrseri = (RadioButton)findViewById(R.id.rseri);
rrpar = (RadioButton)findViewById(R.id.rpar);
ohasil = (EditText)findViewById(R.id.hasil);
ibutton = (Button) findViewById(R.id.button);
ibutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
double R1 = Double.parseDouble(String.valueOf(ir1.getText()));
double R2 = Double.parseDouble(String.valueOf(ir2.getText()));
double R3 = Double.parseDouble(String.valueOf(ir3.getText()));
if (rrseri.isChecked()){
double seri = R1+R2+R3;
ohasil.setText(String.valueOf(seri));
}else{
double paralel = 1/R1 + 1/R2 + 1/R3;
ohasil.setText(String.valueOf(paralel));
}
}
});
}

CODING MyApps String

<resources>
<string name="app_name">My Application</string>
<string name="perhitungan_resistor">PERHITUNGAN RESISTOR</string>
<string name="ires">Input resistror</string>
<string name="hasil">Hasil</string>
<string name="hitung">Hitung!</string>
<string name="seri">Seri</string>
<string name="paralel">Paralel</string>
<string name="masukkan_r3">Masukkan R3</string>
<string name="masukkan_r2">Masukkan R2</string>
<string name="masukkan_r1">Masukkan R1</string>
</resources>

HASIL SCREENSHOOT

You might also like