Senin, 03 Desember 2018


Selamat malam soba blogger kali ini saya akan berbagi aplikasi sederhana penjualan menggunakan android studio. Aplikasi ini sangat penting untik menghitung uang kembalian dan diskon yang diperoleh. Aplikasi ini pun masih banyak kekurangannya, bagi teman-teman yang masih pemula menggunakan android studio mungkin ini bisa menjadi referensi untuk belajar.

Langkah 1# Masukkan kode MainActivity.java
1    package com.example.andiabidzarmakkasau.tokolawan; 
2     
3    import android.support.v7.app.AppCompatActivity; 
4    import android.os.Bundle; 
5     
6    import android.view.View; 
7    import android.widget.Button; 
8    import android.widget.EditText; 
9    import android.widget.TextView; 
10   import android.widget.Toast; 
11    
12   public class MainActivity extends AppCompatActivity { 
13       private EditText edtnamapel, edtid, edtnamabar, edtjumlahbel, edtharga, edtuangbay; 
14       private Button btnproses; 
15       private Button btnhapus; 
16       private Button btnexit; 
17       private TextView txtnamapel; 
18       private TextView txtid; 
19       private TextView txtnamabar; 
20       private TextView txtjumlahbel; 
21       private TextView txtharga; 
22       private TextView txtuangbay; 
23       private TextView txtbonus; 
24       private TextView txttotalbelanja; 
25       private TextView txtuangkembali; 
26       private TextView txtketerangan; 
27    
28       @Override 
29       protected void onCreate(Bundle savedInstanceState) { 
30           super.onCreate(savedInstanceState); 
31           setContentView(R.layout.activity_main); 
32    
33           getSupportActionBar().setTitle("Toko Arman"); 
34    
35           edtnamapel = (EditText) findViewById(R.id.namapelanggan); 
36           edtid = (EditText) findViewById(R.id.idbarang); 
37           edtnamabar = (EditText) findViewById(R.id.namabarang); 
38           edtjumlahbel = (EditText) findViewById(R.id.jumlahbeli); 
39           edtharga = (EditText) findViewById(R.id.harga); 
40           edtuangbay = (EditText) findViewById(R.id.uangbayar); 
41           btnproses = (Button) findViewById(R.id.tombol1); 
42           btnhapus = (Button) findViewById(R.id.tombol2); 
43           btnexit = (Button) findViewById(R.id.tombol3); 
44           txtnamapel = (TextView) findViewById(R.id.namapelanggan); 
45           txtid = (TextView) findViewById(R.id.idbarang); 
46           txtnamabar = (TextView) findViewById(R.id.namabarang); 
47           txtjumlahbel = (TextView) findViewById(R.id.jumlahbeli); 
48           txtharga = (TextView) findViewById(R.id.harga); 
49           txtuangbay = (TextView) findViewById(R.id.uangbayar); 
50           txtbonus = (TextView) findViewById(R.id.bonus); 
51           txttotalbelanja = (TextView) findViewById(R.id.totalbelanja); 
52           txtuangkembali = (TextView) findViewById(R.id.uangkembali); 
53           txtketerangan = (TextView) findViewById(R.id.keterangan); 
54    
55           btnproses.setOnClickListener(new View.OnClickListener() { 
56               @Override 
57               public void onClick(View view) { 
58                   String namapelanggan = edtnamapel.getText().toString().trim(); 
59                   String idbarang = edtid.getText().toString().trim(); 
60                   String namabarang = edtnamabar.getText().toString().trim(); 
61                   String jumlahbeli = edtjumlahbel.getText().toString().trim(); 
62                   String harga = edtharga.getText().toString().trim(); 
63                   String uangbayar = edtuangbay.getText().toString().trim(); 
64    
65                   double jb = Double.parseDouble(jumlahbeli); 
66                   double h = Double.parseDouble(harga); 
67                   double ub = Double.parseDouble(uangbayar); 
68                   double total = (jb * h); 
69                   txttotalbelanja.setText("Total Belanja : " + total); 
70    
71    
72    
73    
74    
75                   if (total >=200000){ 
76                       txtbonus.setText("Bonus : Mie"); 
77                   } else if (total >=50000){ 
78                       txtbonus.setText("Bonus : Pepsodent"); 
79                   } else  if (total >=40000){ 
80                       txtbonus.setText("Bonus : Permen"); 
81                   } else { 
82                       txtbonus.setText("Bonus : Tidak Ada"); 
83                   } 
84                   double uangkembalian = (ub - total); 
85    
86                   if (ub < total){ 
87                       txtketerangan.setText("Keterangan : uang bayar kurang Rp " + (-uangkembalian)); 
88                       txtuangkembali.setText("Uang Kembali : Rp 0" ); 
89                   }else{ 
90                       txtketerangan.setText("Keterangan : TUNGGU KEMBALIANNYA"); 
91                       txtuangkembali.setText("Uang Kembali : " + uangkembalian); 
92                   } 
93    
94    
95               } 
96           }); 
97           btnhapus.setOnClickListener(new View.OnClickListener() { 
98               @Override 
99               public void onClick(View view) { 
100                  txtnamapel.setText(" "); 
101                  txtid.setText(" "); 
102                  txtnamabar.setText(" "); 
103                  txttotalbelanja.setText(" Total Belanja : Rp 0"); 
104                  txtharga.setText(" "); 
105                  txtuangbay.setText(" "); 
106                  txtuangkembali.setText("Uang Kembali : Rp 0"); 
107                  txtbonus.setText("Bonus : - "); 
108                  txtjumlahbel.setText(" "); 
109                  txtketerangan.setText("Keterangan : - "); 
110   
111                  Toast.makeText(getApplicationContext(),"data sudah direset", Toast.LENGTH_LONG).show(); 
112   
113              } 
114          }); 
115          btnexit.setOnClickListener(new View.OnClickListener() { 
116              public void onClick(View view) { 
117   
118                  moveTaskToBack(true); 
119              } 
120          }); 
121      } 
122  } 
Langkah 2# Masukkan Kode Activity_main.xml

1    <?xml version="1.0" encoding="utf-8"?> 
2    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
3        xmlns:app="http://schemas.android.com/apk/res-auto" 
4        xmlns:tools="http://schemas.android.com/tools" 
5        android:layout_width="match_parent" 
6        android:layout_height="match_parent" 
7        android:paddingBottom="16dp" 
8        android:paddingLeft="16dp" 
9        android:paddingRight="16dp" 
10       android:orientation="vertical" 
11       android:paddingTop="16dp" 
12       tools:context="com.example.andiabidzarmakkasau.tokolawan.MainActivity"> 
13    
14       <LinearLayout 
15           android:layout_width="fill_parent" 
16           android:layout_height="fill_parent" 
17           android:orientation="vertical"> 
18           <LinearLayout 
19               android:layout_width="match_parent" 
20               android:layout_height="wrap_content" 
21               android:orientation="horizontal"> 
22               <TextView 
23                   android:layout_width="wrap_content" 
24                   android:layout_height="wrap_content" 
25                   android:text="Nama Pelanggan :  " 
26                   android:textStyle="bold" 
27                   android:textColor="#1E90FF"/> 
28               <EditText 
29                   android:layout_width="match_parent" 
30                   android:layout_height="wrap_content" 
31                   android:id="@+id/namapelanggan" 
32                   android:text="" /> 
33           </LinearLayout> 
34           <LinearLayout 
35               android:layout_width="match_parent" 
36               android:layout_height="wrap_content" 
37               android:orientation="horizontal"> 
38               <TextView 
39                   android:layout_width="wrap_content" 
40                   android:layout_height="wrap_content" 
41                   android:text="ID Barang :  " 
42                   android:textStyle="bold" 
43                   android:textColor="#1E90FF"/> 
44               <EditText 
45                   android:layout_width="match_parent" 
46                   android:layout_height="wrap_content" 
47                   android:id="@+id/idbarang" 
48                   android:text="" /> 
49           </LinearLayout> 
50           <LinearLayout 
51               android:layout_width="match_parent" 
52               android:layout_height="wrap_content" 
53               android:orientation="horizontal"> 
54               <TextView 
55                   android:layout_width="wrap_content" 
56                   android:layout_height="wrap_content" 
57                   android:text="Nama Barang :  " 
58                   android:textStyle="bold" 
59                   android:textColor="#1E90FF"/> 
60               <EditText 
61                   android:layout_width="match_parent" 
62                   android:layout_height="wrap_content" 
63                   android:id="@+id/namabarang" 
64                   android:text="" /> 
65           </LinearLayout> 
66           <LinearLayout 
67               android:layout_width="match_parent" 
68               android:layout_height="wrap_content" 
69               android:orientation="horizontal"> 
70               <TextView 
71                   android:layout_width="wrap_content" 
72                   android:layout_height="wrap_content" 
73                   android:text="Jumlah Beli:  " 
74                   android:textStyle="bold" 
75                   android:textColor="#1E90FF"/> 
76               <EditText 
77                   android:layout_width="match_parent" 
78                   android:layout_height="wrap_content" 
79                   android:id="@+id/jumlahbeli" 
80                   android:text="" 
81                   android:inputType="number"/> 
82           </LinearLayout> 
83           <LinearLayout 
84               android:layout_width="match_parent" 
85               android:layout_height="wrap_content" 
86               android:orientation="horizontal"> 
87               <TextView 
88                   android:layout_width="wrap_content" 
89                   android:layout_height="wrap_content" 
90                   android:text="Harga : Rp " 
91                   android:textStyle="bold" 
92                   android:textColor="#1E90FF"/> 
93               <EditText 
94                   android:layout_width="match_parent" 
95                   android:layout_height="wrap_content" 
96                   android:id="@+id/harga" 
97                   android:text="" 
98                   android:inputType="number" 
99                   android:layout_marginBottom="8dp" /> 
100          </LinearLayout> 
101   
102
103   
104          <LinearLayout 
105              android:layout_width="match_parent" 
106              android:layout_height="wrap_content" 
107              android:orientation="horizontal"> 
108              <TextView 
109                  android:layout_width="wrap_content" 
110                  android:layout_height="wrap_content" 
111                  android:text="Uang Bayar: Rp  " 
112                  android:textStyle="bold" 
113                  android:textColor="#1E90FF"/> 
114              <EditText 
115                  android:layout_width="match_parent" 
116                  android:layout_height="wrap_content" 
117                  android:id="@+id/uangbayar" 
118                  android:text="" 
119                  android:inputType="number"/> 
120          </LinearLayout> 
121          <Button 
122              android:layout_width="match_parent" 
123              android:layout_height="wrap_content" 
124              android:id="@+id/tombol1" 
125              android:text="PROSES" 
126              android:textStyle="bold" 
127              android:textColor="#1E90FF" 
128              android:layout_marginBottom="8dp" /> 
129          <TextView 
130              android:layout_width="wrap_content" 
131              android:layout_height="wrap_content" 
132              android:text="Total Belanja " 
133              android:textColor="#1E90FF" 
134              android:id="@+id/totalbelanja" 
135              android:textStyle="bold" 
136              android:textSize="18dp" 
137              android:layout_marginBottom="8dp" /> 
138          <TextView 
139              android:layout_width="wrap_content" 
140              android:layout_height="wrap_content" 
141              android:text="Uang Kembali " 
142              android:textColor="#1E90FF" 
143              android:id="@+id/uangkembali" 
144              android:textStyle="bold" 
145              android:textSize="18dp" 
146              android:layout_marginBottom="8dp"/> 
147          <TextView 
148              android:layout_width="wrap_content" 
149              android:layout_height="wrap_content" 
150              android:text="Bonus" 
151              android:textColor="#1E90FF" 
152              android:id="@+id/bonus" 
153              android:textStyle="bold" 
154              android:textSize="18dp" 
155              android:layout_marginBottom="8dp"/> 
156          <TextView 
157              android:layout_width="wrap_content" 
158              android:layout_height="wrap_content" 
159              android:text="Keterangan " 
160              android:textColor="#1E90FF" 
161              android:id="@+id/keterangan" 
162              android:textStyle="bold" 
163              android:textSize="18dp" 
164              android:layout_marginBottom="8dp"/> 
165          <LinearLayout 
166              android:layout_width="match_parent" 
167              android:layout_height="wrap_content" 
168              android:orientation="horizontal"> 
169   
170              <Button 
171                  android:layout_width="wrap_content" 
172                  android:layout_height="wrap_content" 
173                  android:id="@+id/tombol2" 
174                  android:text="CLEAR" 
175                  android:textStyle="bold" 
176                  android:textColor="#1E90FF"/> 
177              <Button 
178                  android:layout_width="wrap_content" 
179                  android:layout_height="wrap_content" 
180                  android:id="@+id/tombol3" 
181                  android:text="EXIT" 
182                  android:textColor="#1E90FF" 
183                  android:textStyle="bold"/> 
184          </LinearLayout> 
185      </LinearLayout> 
186  </ScrollView> 

image Program
Sekian postingan kali ini semoga bisa bermanfaat bagi teman-teman semua, wassalam😑

0 komentar:

Posting Komentar