Sabtu, 06 April 2019

uas mobile programing

Nama: muhammad faisal
Nim : 161011400141

UAS MOBILE PROGRAMING "REKENING LISTRIK"

1.sorce code
(mainactivity.java)
package com mfaisal 161011400141;


import android.os.Bundle;

import android.app.Activity;
import android.content.Intent;

import android.view.Menu;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.EditText;


public class MainActivity extends Activity implements OnClickListener{

private String[][] dataUser = {{"ADMIN","ADMIN","Administrator"},

{"user1","password1","Nama User 1"},                                   

{"user2","password2","Nama User 2"}};                 

private EditText userNameET, passwordET;           

private final int SUCCESS=1;


@Override

public void onCreate(Bundle savedInstanceState) {        

super.onCreate(savedInstanceState);        

setContentView(R.layout.activity_main);


userNameET = (EditText) findViewById(R.id.userNameEditText);       

passwordET = (EditText) findViewById(R.id.passwordEditText);


findViewById(R.id.loginButton).setOnClickListener(this);        

findViewById(R.id.tutupButton).setOnClickListener(this);

}


@Override

public boolean onCreateOptionsMenu(Menu menu) {        

getMenuInflater().inflate(R.menu.main, menu);        

return true;

}


public void onClick(View v) {

// TODO Auto-generated method stub

switch (v.getId()){                        

case R.id.loginButton:

int i=0;

boolean success=false;


while ((i<dataUser.length) && (!success)){

if
((userNameET.getText().toString().equals(dataUser[i][0])) && 


(passwordET.getText().toString().equals(dataUser[i][1]))){                                                                 
success=true;

} else {

i++;

}

}


Intent intent;

if (success){

intent = new Intent(this, MenuActivity.class);                                                       
intent.putExtra("namaUser", dataUser[i][2]);

startActivityForResult(intent,SUCCESS);

} else {

intent = new Intent(this, FailedActivity.class);

startActivity(intent);

}

startActivity(intent);

break;                           

case R.id.tutupButton:

System.exit(0);

}

}


@Override

public void onActivityResult(int requestCode, int resultCode, Intent data){

switch (requestCode) {                              

case SUCCESS:

userNameET.setText("");                                           

passwordET.setText("");

break;                           
}

}

}


 (Activity_main.xml)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"    
    android:layout_width="match_parent"    
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/linearLayout1"        
        android:layout_width="wrap_content"       
        android:layout_height="wrap_content"         
        android:layout_alignParentLeft="true"        
        android:layout_alignParentRight="true"        
        android:layout_alignParentTop="true" >

        <TextView
            android:id="@+id/textView1"            
            android:layout_width="match_parent"            
            android:layout_height="wrap_content"            
            android:gravity="center"            
            android:text="Form Login"
            android:textAppearance="?android:attr/textAppearanceMedium"
/>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout2"        
        android:layout_width="wrap_content"        
        android:layout_height="wrap_content"        
        android:layout_alignParentLeft="true"        
        android:layout_alignParentRight="true"        
        android:layout_below="@+id/linearLayout1"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView2"            
            android:layout_width="match_parent"            
            android:layout_height="wrap_content"            
            android:text="User Name" />

        <EditText
            android:id="@+id/userNameEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="User Name" >

            <requestFocus />
        </EditText>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout3"        
        android:layout_width="wrap_content"        
        android:layout_height="wrap_content"        
        android:layout_alignParentLeft="true"        
        android:layout_alignParentRight="true"        
        android:layout_below="@+id/linearLayout2"         
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView3"            
            android:layout_width="match_parent"            
            android:layout_height="wrap_content"            
            android:text="Password" />

        <EditText
            android:id="@+id/passwordEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Password"
            android:inputType="textPassword" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"        
        android:layout_height="wrap_content"        
        android:layout_alignParentLeft="true"        
        android:layout_alignParentRight="true"        
        android:layout_below="@+id/linearLayout3" >

        <Button
            android:id="@+id/loginButton"            
            android:layout_width="wrap_content"            
            android:layout_height="wrap_content"            
            android:layout_weight="3"            
            android:text="Login" />

        <Button
            android:id="@+id/tutupButton"            
            android:layout_width="wrap_content"            
            android:layout_height="wrap_content"            
            android:layout_weight="1"            
            android:text="Tutup" />

    </LinearLayout>
    </RelativeLayout>

(Menuactivity.java)
package com.mfaisal.materiactivity;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;

public class MenuActivity extends Activity implements
OnClickListener{
                Button lingkaran;

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

                      lingkaran = (Button)findViewById(R.id.button1);
                      lingkaran.setOnClickListener(new View.OnClickListener() {

                      @Override
                      public void onClick(View v) {
                      // TODO Auto-generated method stub
                         Intent i = new Intent(getApplicationContext(), LingkaranActivity.class);
                         startActivity(i);
                      }
                   
                   });
                      Button konversisuhu = (Button)findViewById(R.id.button2);
                      konversisuhu.setOnClickListener(new View.OnClickListener() {

                                      @Override
                                      public void onClick(View v) {
                                      // TODO Auto-generated method stub
                                         Intent i = new Intent(getApplicationContext(), KonversiSuhuActivity.class);
                                         startActivity(i);
                                      }
                                   
                                   });
                      Button rekeninglistrik = (Button)findViewById(R.id.button4);
                      rekeninglistrik.setOnClickListener(new View.OnClickListener() {

                                      @Override
                                      public void onClick(View v) {
                                      // TODO Auto-generated method stub
                                         Intent i = new Intent(getApplicationContext(), RekeningListrikActivity.class);
                                         startActivity(i);
                                      }
                                   
                                   });
                      Button konversimatauang = (Button)findViewById(R.id.button3);
                      konversimatauang.setOnClickListener(new View.OnClickListener() {

                                      @Override
                                      public void onClick(View v) {
                                      // TODO Auto-generated method stub
                                         Intent i = new Intent(getApplicationContext(), KonversiMataUangActivity.class);
                                         startActivity(i);
                                      }
                                   
                                   });
                      }
                   @Override
                   public boolean onCreateOptionsMenu(Menu menu) {
                   // Inflate the menu; this adds items to the action bar if it is present.
                      getMenuInflater().inflate(R.menu.menu, menu);
                      return true;
                   }

                @Override
                public void onClick(View v) {
                                // TODO Auto-generated method stub
                               
                }
                }

(Activity_menu.xml)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.lutfi.materiactivity.MenuActivity" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="18dp" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="18dp"
            android:text="Menu Bidang Datar"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/linearLayout1"
        android:layout_centerHorizontal="true"
        android:orientation="vertical" >

        <Button
            android:id="@+id/button1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="1. LINGKARAN" />

        <Button
            android:id="@+id/button2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="2. KONVERSI SUHU" />

        <Button
            android:id="@+id/button4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="3. REKENING LISTRIK" />

        <Button
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="4. KONVERSI MATA UANG" />

    </LinearLayout>

</RelativeLayout>

(Rekeninglistrik.activity.java)
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.view.View.OnClickListener;
public class RekeningListrikActivity extends Activity {
private EditText txtPelanggan,txtPelangganOut,txtTipe,txtMBL,txtMBI,txtPakai,txtTagihan;
private Button btProses;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rekening_listrik);
txtPelanggan = (EditText) findViewById(R.id.txtPelanggan);
txtPelangganOut = (EditText) findViewById(R.id.txtPelangganOut);
txtTipe = (EditText) findViewById(R.id.txtTipe);
txtMBL = (EditText) findViewById(R.id.txtMBL);
txtMBI = (EditText) findViewById(R.id.txtMBI);
txtPakai = (EditText) findViewById(R.id.txtPakai);
txtTagihan = (EditText) findViewById(R.id.txtTagihan);
btProses = (Button) findViewById(R.id.btProses);
btProses.setOnClickListener(new OnClickListener() {
 public void onClick(View v) {
 prosesHasil(v);
 }
 });
 }

 public void prosesHasil(View view){
 try{
 String namaOut=String.valueOf(txtPelanggan.getText().toString());
 String tipe=String.valueOf(txtTipe.getText().toString());
 Double mbl=Double.parseDouble(txtMBL.getText().toString());
 Double mbi=Double.parseDouble(txtMBI.getText().toString());
 Double pakai =mbi - mbl;

 Double tarif=0.00;
 Double beban=0.00;
 if (tipe.equals("R1")){
 tarif=100.00;
 beban=20000.00;
 }
 else if (tipe.equals("R2")){
 tarif=200.00;
 beban=30000.00;
 }
 else{
 tarif=300.0;
 beban=50000.00;
 }
 Double tagihan = (pakai * tarif) + beban;
 txtPelangganOut.setText(String.valueOf(namaOut));
 txtPakai.setText(String.valueOf(pakai));
 txtTagihan.setText("Tagihan : " + tagihan);
 }
 catch(Exception e){
 e.printStackTrace();
 }
 }
}
2.Hasilnya





                      

listview

Senin, 25 Maret 2019

uts mobile programing muahmmad faisal 161011400141



1.       1.Buka Eclipse
2.     2.  Buatlah Project baru dengan cara File > New > Android Aplication Project Silahkan beri nama Aplication Name RekeningListrik atau kamu ingin membuat dengan nama kamu sendiri juga bisa.
3.    3.   Buat lah Layout seperti gambar di atas yaitu hanya menggunakan TextView, Plain Text, dan Button.
3    4.from login
Activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"    
    android:layout_width="match_parent"    
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/linearLayout1"        
        android:layout_width="wrap_content"       
        android:layout_height="wrap_content"        
        android:layout_alignParentLeft="true"        
        android:layout_alignParentRight="true"        
        android:layout_alignParentTop="true" >

        <TextView
            android:id="@+id/textView1"            
            android:layout_width="match_parent"            
            android:layout_height="wrap_content"            
            android:gravity="center"            
            android:text="Form Login"
            android:textAppearance="?android:attr/textAppearanceMedium"
/>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout2"        
        android:layout_width="wrap_content"        
        android:layout_height="wrap_content"        
        android:layout_alignParentLeft="true"        
        android:layout_alignParentRight="true"        
        android:layout_below="@+id/linearLayout1"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView2"            
            android:layout_width="match_parent"            
            android:layout_height="wrap_content"            
            android:text="User Name" />

        <EditText
            android:id="@+id/userNameEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="User Name" >

            <requestFocus />
        </EditText>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout3"        
        android:layout_width="wrap_content"        
        android:layout_height="wrap_content"        
        android:layout_alignParentLeft="true"        
        android:layout_alignParentRight="true"        
        android:layout_below="@+id/linearLayout2"        
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView3"            
            android:layout_width="match_parent"            
            android:layout_height="wrap_content"            
            android:text="Password" />

        <EditText
            android:id="@+id/passwordEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Password"
            android:inputType="textPassword" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"        
        android:layout_height="wrap_content"        
        android:layout_alignParentLeft="true"        
        android:layout_alignParentRight="true"        
        android:layout_below="@+id/linearLayout3" >

        <Button
            android:id="@+id/loginButton"            
            android:layout_width="wrap_content"            
            android:layout_height="wrap_content"            
            android:layout_weight="3"            
            android:text="Login" />

        <Button
            android:id="@+id/tutupButton"            
            android:layout_width="wrap_content"            
            android:layout_height="wrap_content"            
            android:layout_weight="1"            
            android:text="Tutup" />

    </LinearLayout>

    </RelativeLayout>



4. 
66




   5.   Pastekan Kode Berikut di MainActivity.java
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

 android:layout_width="fill_parent"

 android:layout_height="fill_parent"

 android:orientation="vertical" >

 <TextView

 android:id="@+id/textView1"

 android:layout_width="wrap_content"

 android:layout_height="wrap_content"

 android:text="Nama Pelanggan" />

 <EditText

 android:id="@+id/txtPelanggan"

 android:layout_width="match_parent"

 android:layout_height="wrap_content"

 android:ems="10" >

 <requestFocus />

 </EditText>

 <TextView

 android:id="@+id/textView2"

 android:layout_width="wrap_content"

 android:layout_height="wrap_content"

 android:text="Tipe Meteran" />

 <EditText

 android:id="@+id/txtTipe"

 android:layout_width="match_parent"

 android:layout_height="wrap_content"

 android:ems="10" />

 <TextView

 android:id="@+id/textView3"

 android:layout_width="wrap_content"

 android:layout_height="wrap_content"

 android:text="Meter Bulan Lalu" />

 <EditText

 android:id="@+id/txtMBL"

 android:layout_width="match_parent"

 android:layout_height="wrap_content"

 android:ems="10" />

 <TextView

 android:id="@+id/textView4"

 android:layout_width="wrap_content"

 android:layout_height="wrap_content"

 android:text="Meter Bulan Ini" />

 <EditText

 android:id="@+id/txtMBI"

 android:layout_width="match_parent"

 android:layout_height="wrap_content"

 android:ems="10" />

 <Button

 android:id="@+id/btProses"

 android:layout_width="match_parent"

 android:layout_height="wrap_content"

 android:text="KALKULASI" />

 <TextView

 android:id="@+id/textView7"

 android:layout_width="wrap_content"

 android:layout_height="wrap_content"

 android:text="Nama Pelanggan" />

 <EditText

 android:id="@+id/txtPelangganOut"

 android:layout_width="match_parent"

 android:layout_height="wrap_content"

 android:ems="10" />

 <TextView

 android:id="@+id/textView5"

 android:layout_width="wrap_content"

 android:layout_height="wrap_content"

 android:text="Pemakaian" />

 <EditText

 android:id="@+id/txtPakai"

 android:layout_width="match_parent"

 android:layout_height="wrap_content"

 android:ems="10" />

 <TextView

 android:id="@+id/textView6"

 android:layout_width="wrap_content"

 android:layout_height="wrap_content"

 android:text="Tagihan" />

 <EditText

 android:id="@+id/txtTagihan"

 android:layout_width="match_parent"

 android:layout_height="wrap_content"

 android:ems="10" />

</LinearLayout>





5.       6.Selanjutnya Pastekan Kode berikut di Activity_main.xml

package com.faisal.rekeninglistrik;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.view.View.OnClickListener;
public class MainActivity extends Activity {
private EditText txtPelanggan,txtPelangganOut,txtTipe,txtMBL,txtMBI,txtPakai,txtTagihan;
private Button btProses;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtPelanggan = (EditText) findViewById(R.id.txtPelanggan);
txtPelangganOut = (EditText) findViewById(R.id.txtPelangganOut);
txtTipe = (EditText) findViewById(R.id.txtTipe);
txtMBL = (EditText) findViewById(R.id.txtMBL);
txtMBI = (EditText) findViewById(R.id.txtMBI);
txtPakai = (EditText) findViewById(R.id.txtPakai);
txtTagihan = (EditText) findViewById(R.id.txtTagihan);
btProses = (Button) findViewById(R.id.btProses);
btProses.setOnClickListener(new OnClickListener() {
 public void onClick(View v) {
 prosesHasil(v);
 }
 });
 }

 public void prosesHasil(View view){
 try{
 String namaOut=String.valueOf(txtPelanggan.getText().toString());
 String tipe=String.valueOf(txtTipe.getText().toString());
 Double mbl=Double.parseDouble(txtMBL.getText().toString());
 Double mbi=Double.parseDouble(txtMBI.getText().toString());
 Double pakai =mbi - mbl;

 Double tarif=0.00;
 Double beban=0.00;
 if (tipe.equals("R1")){
 tarif=100.00;
 beban=20000.00;
 }
 else if (tipe.equals("R2")){
 tarif=200.00;
 beban=30000.00;
 }
 else{
 tarif=300.0;
 beban=50000.00;
 }
 Double tagihan = (pakai * tarif) + beban;
 txtPelangganOut.setText(String.valueOf(namaOut));
 txtPakai.setText(String.valueOf(pakai));
 txtTagihan.setText("Tagihan : " + tagihan);
 }
 catch(Exception e){
 e.printStackTrace();
 }
 }
}

6.      7. Slesai.... Klik kanan pada project  dan Run As