Senin, 25 Maret 2019

UTS MOBILE PROGRAMMING APLIKASI PEMESANAN KOPI

PEMESANAN KOPI 

1.      DESKRIPSI PROJECT
Kali ini saya akan membuat aplikasi android pemesanan kopi sederhana dimana aplikasi ini berfungsi layaknya Cafe yang terinspirasi ingin menggunakan aplikasi tersebut.Contohnya adalah saat kita  memesan coffee akan disodorkan menu yang dimana didalam nya terdapat beberapa menu coffee dari cafe tersebut,maka dengan menggunakan aplikasi ini kemungkinan bisa memudahkan pemesanan dan transaksinya sekaligus.

2.      SOURCE CODE XML
·         LoginActivity.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"
    tools:context=".LoginActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:gravity="center"
        android:text="FROM LOGIN"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textSize="35sp" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="14dp"
        android:text="User Name" />

    <EditText
        android:id="@+id/userNameEditText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView2"
        android:ems="10" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/userNameEditText"
        android:layout_marginTop="21dp"
        android:text="Password" />

    <EditText
        android:id="@+id/passwordEditText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView3"
        android:ems="10"
        android:inputType="textPassword" />

    <Button
        android:id="@+id/tutupButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/loginButton"
        android:layout_alignBottom="@+id/loginButton"
        android:layout_marginLeft="27dp"
        android:layout_toRightOf="@+id/loginButton"
        android:layout_weight="1"
        android:text="Tutup"
        android:textSize="30sp" />

    <Button
        android:id="@+id/loginButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/passwordEditText"
        android:layout_marginLeft="22dp"
        android:layout_marginTop="44dp"
        android:layout_weight="3"
        android:text="Login"
        android:textSize="30sp" />

</RelativeLayout>
·         MenuActivity.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"
    tools:context=".MenuActivity" >

    <Button
        android:id="@+id/btnlogout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="Logout" />

    <Button
        android:id="@+id/btnjus"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/btnlogout"
        android:layout_marginBottom="61dp"
        android:layout_toRightOf="@+id/btnlogout"
        android:text="JUS"
        android:textSize="25sp" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/btnjus"
        android:layout_marginBottom="27dp"
        android:layout_toRightOf="@+id/btnkopi"
        android:text="MENU "
        android:textSize="30sp" />

    <Button
        android:id="@+id/btnkopi"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/btnjus"
        android:layout_alignBottom="@+id/btnjus"
        android:layout_toLeftOf="@+id/btnlogout"
        android:text="KOPI"
        android:textSize="25sp" />

</RelativeLayout>
·         KopiActivity.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"
    tools:context=".KopiActivity" >
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/GroupCoffee"
        android:layout_toRightOf="@+id/GroupCoffee"
        android:text="Menu kopi yang akan dipesan"
        android:textSize="20sp" />

    <RadioGroup
        android:id="@+id/radioGroup1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_toRightOf="@+id/GroupCoffee" >

        <RadioButton
            android:id="@+id/cafe"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="Indocafe" />

        <RadioButton
            android:id="@+id/Mocca"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Moccacino" />

        <RadioButton
            android:id="@+id/Cappu"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Cappucino" />
    </RadioGroup>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/radioGroup1"
        android:text="Tambahan apa yang akan dimasukan kedalam kopi" />

    <CheckBox
        android:id="@+id/KRIM"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView2"
        android:text="CREAMER" />

    <CheckBox
        android:id="@+id/GUL"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/KRIM"
        android:text="GULA" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/GUL"
        android:layout_below="@+id/GUL"
        android:layout_marginTop="31dp"
        android:text="TOTAL" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView3"
        android:layout_alignBottom="@+id/textView3"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/TTL"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/editText1"
        android:layout_marginTop="29dp"
        android:text="TOTAL" />

    <Button
        android:id="@+id/KEM"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/TTL"
        android:layout_alignBottom="@+id/TTL"
        android:layout_marginLeft="24dp"
        android:layout_toRightOf="@+id/radioGroup1"
        android:text="KEMBALI" />

   

</RelativeLayout>
3.      XML Graphic
·         ActivityLogin




·         ActivityMenu



·         ActivityKopi


4.       Source coding java

package com.example.gitafitriani;


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

public class LoginActivity extends Activity {
            EditText userNameTxt;
            EditText passwordTxt;
            Button loginBtn;
            Button tutupBtn;

            @Override
            protected void onCreate(Bundle savedInstanceState) {
                        super.onCreate(savedInstanceState);
                        setContentView(R.layout.activity_login);
                        userNameTxt = (EditText) findViewById(R.id.userNameEditText);
        passwordTxt = (EditText) findViewById(R.id.passwordEditText);
        loginBtn = (Button) findViewById(R.id.loginButton);
        tutupBtn = (Button) findViewById(R.id.tutupButton);
       
        loginBtn.setOnClickListener(new View.OnClickListener() {
            
             public void onClick(View v) {
                                                // TODO Auto-generated method stub
                                                Intent i = new Intent(LoginActivity.this, MenuActivity.class);
                                                i.putExtra("pesan", "Sukses Login");
                                                startActivity(i);
                                    }
                        });
       
tutupBtn.setOnClickListener(new View.OnClickListener() {
                                   
                                    public void onClick(View v) {
                                                // TODO Auto-generated method stub
                                                moveTaskToBack(true);
                                                android.os.Process.killProcess(android.os.Process.myPid());
                                                System.exit(0);
                                    }
                        });
    }
       

            @Override
            public boolean onCreateOptionsMenu(Menu menu) {
                        // Inflate the menu; this adds items to the action bar if it is present.
                        getMenuInflater().inflate(R.menu.activity_login, menu);
                        return true;
            }

}
·         Source code menu
package com.example.gitafitriani;

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

public class MenuActivity extends Activity {
                Button kopi;
                Button jus;
                Button logout;


                @Override
                protected void onCreate(Bundle savedInstanceState) {
                                super.onCreate(savedInstanceState);
                                setContentView(R.layout.activity_menu);
                                kopi = (Button) findViewById(R.id.btnkopi);
        jus= (Button) findViewById(R.id.btnjus);
        logout = (Button) findViewById(R.id.btnlogout);
       
        kopi.setOnClickListener(new View.OnClickListener() {
              
               public void onClick(View v) {
                                                                // TODO Auto-generated method stub
                                                                Intent i = new Intent(MenuActivity.this, KopiActivity.class);
                                                                i.putExtra("pesan", "Sukses Login");
                                                                startActivity(i);
                                                }
                                });
       
        logout.setOnClickListener(new View.OnClickListener() {
              
               public void onClick(View v) {
                                                                // TODO Auto-generated method stub
                                                                Intent i = new Intent(MenuActivity.this, LoginActivity.class);
                                                                i.putExtra("pesan", "Sukses Login");
                                                                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.activity_menu, menu);
                                return true;
                }

}
·         Source code Kopi
package com.example.gitafitriani;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;


public class PemesananActivity extends Activity {
                RadioButton Rcafe;
                RadioButton Rmocca;
                RadioButton Rcappu;
                RadioGroup Rkopi;
                CheckBox cream;
                CheckBox gul;
                Button ttl;
                Button kem;
                EditText EditText1;
                int indocafe = 3000;
                int moccacino = 4000;
                int harga ;
               

                @Override
                protected void onCreate(Bundle savedInstanceState) {
                                super.onCreate(savedInstanceState);
                                setContentView(R.layout.activity_pemesanan);
                                Rcafe = (RadioButton) findViewById(R.id.cafe);
                                Rmocca = (RadioButton) findViewById(R.id.Mocca);
                                Rcappu = (RadioButton) findViewById(R.id.Cappu);
                                Rkopi = (RadioGroup) findViewById(R.id.GroupCoffee);
                                cream = (CheckBox) findViewById(R.id.KRIM);
                                gul = (CheckBox) findViewById(R.id.GUL);
                                EditText1 = (EditText) findViewById(R.id.editText1);
                                ttl = (Button) findViewById(R.id.TTL);
                                kem = (Button) findViewById(R.id.KEM);
                               
                                ttl.setOnClickListener(new View.OnClickListener() {
                                               
                                                @Override
                                                public void onClick(View arg0) {
                                                                // TODO Auto-generated method stub
                                                                String Pilihan = " kopi";
                                                                String ket ="Yang Harus di bayar =";
                                                                TextView pesanan;
                                                                int ps = Integer.parseInt(pesanan.getText().toString());
                                                                int radioId = Rkopi.getCheckedRadioButtonId();
                                                                if(Rkopi.getId()==radioId){
                                                                                int totalHarga = harga*ps;
                                                                Jenis = Jenis + " cafe " + " " + ket + " " + totalHarga;
                                                                } else if(Rcappu.isChecked()){
                                                                Jenis = Jenis + " mocca" + " " + ket + " " + totalHarga;
                                                                }else{
                                                                Jenis = Jenis + " cappu " + " " + ket + " " + totalHarga;
                                                                }
                                                                if (cream.isChecked()){
                                                                Jenis += " tambah KRIM " + " " + ket + " " + totalHarga;        
                                                                } if (gul.isChecked()) {
                                                                Jenis += " tambah KRIM " + " " + ket + " " + totalHarga;        
                                                                }
                                                                Toast.makeText(getApplicationContext(), Jenis, Toast.LENGTH_LONG).show();
                                                               
                }
                               
                               
                                                                Kembali.setOnClickListener(new View.OnClickListener(){
                                                                               
                                                                                @Override
                                                                                public void onClick(View argO){
                                                                                                //TODO Auto-generated method stub
                                                                                                Intent i = new Intent(MenuActivity.this,PemesananActivity.class);
                                                                                                i.putExtra("Pesan", "Menu kopi");
                                                                                                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.activity_pemesanan, menu);
                                return true;
                }

}

1.      Hasil RUN
·         LOGIN




·         MENU


·         KOPI





Tidak ada komentar:

Posting Komentar