Program Penjualan Stationery
cBarang
package
pkgPenjualanATK;
public
class CBarang {
private String nama;
private String kode;
private int satuan;
private int harga;
private int stock;
private int hargabeli;
CBarang(){
nama=""; kode="";
satuan=0; harga=0; stock=0; hargabeli=0;
}
CBarang(String nm, String kd, int sa, int
ha, int hb, int st){
nama=nm; kode=kd; satuan=sa; harga=ha;
hargabeli =hb; stock=st;
}
public void setNama(String n){
nama=n;
}
public void setKode(String n){
kode=n;
}
public void setSatuan(int k){
satuan=k;
}
public void setHarga(int k){
harga=k;
}
public void setHargaBeli(int h){
hargabeli=h;
}
public void setStock(int k){
stock=k;
}
public String getNama(){
return nama;
}
public String getKode(){
return kode;
}
public int getSatuan() {
return satuan;
}
public int getHarga(){
return harga;
}
public int getHargaBeli() {
return hargabeli;
}
public int getStock(){
return stock;
}
//method query
public String Tostring(){
return nama+" "+kode+"
"+satuan+" "+harga+" "+stock;
}
}
cDataPembeli
package
pkgPenjualanATK;
public
class CDataPembeli {
private String nama;
private String alamat;
private String tgltrn;
private int nominal;
//constructor
public CDataPembeli(){
}
public CDataPembeli(String nm, String al,
String ttr){
nama = nm; alamat = al; tgltrn = ttr;
}
//member function
//method setter
public void setNama(String n){
nama = n;
}
public void setAlamat(String a){
alamat = a;
}
public void setTgltrn(String t){
tgltrn = t;
}
public void setNominal(int n){
nominal = n;
}
//method getter
public String getNama(){
return nama;
}
public String getAlamat(){
return alamat;
}
public String getTgltrn(){
return tgltrn;
}
public int getNominal(){
return nominal;
}
//method query
public String ToString(){
return "pembeli "+nama+"
dengan alamat "+alamat+" tanggal transaksi "
+tgltrn;
}
}
cPelanggan
package
pkgPenjualanATK;
public
class CPelangganATK {
private String nama;
private String alamat;
CPelangganATK(String n, String a){
nama=n; alamat=a;
}
public String getNama(){
return nama;
}
public String getAlamat(){
return alamat;
}
}
cPembelianATK
package
pkgPenjualanATK;
public
class CPembelianATK {
private CPelangganATK pelanggan;
private CBarang[] barang;
private int jbrg, maksbrg;
CPembelianATK(CPelangganATK p, int j){
pelanggan=p; maksbrg=j; jbrg=0;
barang=new CBarang[j];
}
CPembelianATK() {
}
public String ToString(){
String t="";
for (int i = 0; i < jbrg; i++){
t=t+barang[i].getKode()+"\t";
t=t+barang[i].getNama()+"\t";
t=t+barang[i].getHarga()+"\t";
}
return t;
}
public void tambahBarang(CBarang brg){
if(jbrg<maksbrg){
barang[jbrg]=brg;
jbrg++;
System.out.println("Penambahan
barang sukses...");
}
else System.out.println("Kapasitas
penuh!");
}
public void hapusBarang(String kd){
if (jbrg>0){
//cari kode KD barang di array
barang
boolean ada=false;
for (int i=0; i<jbrg; i++){
if(barang[i].getKode().equalsIgnoreCase(kd)){
ada=true;
barang[i]=null;
int t=0;
for(int j=i; j<jbrg-1;
j++){
barang[j]=barang[j+1];
t=j;
}
barang[t]=null;
jbrg--;
System.out.println("Penghapusan sukses...");
}
}
if(ada==false){
System.out.println("Barang
tidak ada!");
}
}
else System.out.println("Barang
masih kosong...");
}
}
cPendapatan
package
pkgPenjualanATK;
public
class CPendapatan {
private int totalpend;
private int mdl,modal, untung, rugi, harga;
CBarang bar = new CBarang();
CPendapatan(){
}
CPendapatan(int harga, int stck){
totalpend = harga*stck;
}
public void setModal(int m){
mdl = m;
}
public void setTotalPend(int tp){
totalpend=tp;
}
public void setUntung(int utg){
untung = utg;
}
public void setRugi(int rg){
rugi = rg;
}
public int getModal(){
return modal;
}
public int getTotalPend(){
return totalpend;
}
public int getUntung(){
return untung;
}
public int getRugi(){
return rugi;
}
public String ToString(){
return "Total pendapatan hari ini
sejumlah Rp"+getTotalPend()+" dengan keuntungan sebesar
Rp"+getUntung()+" dan kerugian sebesar Rp"+getRugi();
}
}
AppPenjualan
package
pkgPenjualanATK;
import
java.util.Scanner;
public
class appPenjualanATK {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
CBarang brg[]=new CBarang[5];
CDataPembeli dp[] = new
CDataPembeli[10];
int pilih, pilih2, pilihh, harga,
satuan, modal, g=0, h=0, i=0;
byte pil; boolean ketemu;
CPendapatan pend;
pend = new CPendapatan();
do{
System.out.println("");
System.out.println("MENU
PENJUALAN STATIONARY");
System.out.println("1.
Barang");
System.out.println("2. Data
Pembeli");
System.out.println("3.
Pendapatan");
System.out.println("4.
Selesai");
System.out.print("Pilihan =
");
pilih = sc.nextInt();
switch(pilih){
case 1:
do{
System.out.println("\nMENU Barang");
System.out.println("1. Tambah Barang");
System.out.println("2. Hapus Barang");
System.out.println("3. Update Barang");
System.out.println("4. Lihat Barang");
System.out.println("5.
Query");
System.out.println("6. Kembali");
System.out.print("Pilih = ");
pilih2=sc.nextInt();
switch(pilih2){
case 1:
System.out.println("\n-- Tambah Nama Barang --");
System.out.print("Masukkan Nama Barang = ");
sc=new Scanner(System.in);
String
nama=sc.nextLine();
System.out.print("Masukkan Kode Barang = ");
String
kode=sc.next();
System.out.print("Masukkan
Satuan Barang = ");
satuan=sc.nextInt();
System.out.print("Masukkan Harga Jual = Rp");
harga=sc.nextInt();
System.out.print("Masukkan Harga Beli = Rp");
int hargabeli
=sc.nextInt();
System.out.print("Masukkan Update Stock Barang = ");
int
update=sc.nextInt();
brg[i] = new
CBarang(nama,kode,satuan,harga,hargabeli,update);
i++;
break;
case 2:
ketemu =false;
System.out.println("\n-- Hapus Barang --");
System.out.print("Masukkan Kode Barang = ");
kode=sc.next();
for (byte j =
0; j < 5 && ketemu!=true; j++) {
if(brg[j]
!=null&&brg[j].getKode().equalsIgnoreCase(kode)) {
ketemu =true;
System.out.println("Data Barang Telah Ditemukan!");
System.out.println("Yakin Barang Dihapus? 1. Ya, 2. Tidak");
System.out.print("Pilih = ");
pilih2=sc.nextInt();
if(pilih2==1){
brg[j]=null;
for
(int k = j; k < 4; k++) {
brg[k]=brg[k+1];
}
System.out.println("Data Barang Telah Dihapus!");
}
else
System.out.println("Batalkan Hapus Data Barang");
}
}
if(ketemu==false) System.out.println("Data Barang Tidak
Ditemukan!");
break;
case 3:
ketemu = false;
System.out.println("\n-- Update Data Barang --");
System.out.print("Masukkan Kode Barang = ");
kode=sc.next();
for (int j = 0; j < 5
&& ketemu!=true; j++) {
if(brg[j].getKode().equalsIgnoreCase(kode)){
ketemu
=true;
System.out.println("Data Barang Telah Ditemukan");
System.out.print("Nama Barang Baru = ");
sc=new
Scanner(System.in);
String
nm=sc.nextLine();
System.out.print("Harga Barang Baru = ");
int
ha=sc.nextInt();
System.out.print("Masukkan Harga
Beli = Rp");
hargabeli =sc.nextInt();
System.out.print("Masukkan Update Stock Barang = ");
update=sc.nextInt();
System.out.println("Simpan Data?");
System.out.println("1. Ya
2. Tidak");
System.out.print("Pilih = ");
pilih2=sc.nextInt();
if(pilih2==1){
brg[j].setNama(nm);
brg[j].setHarga(ha);
brg[j].setHargaBeli(hargabeli);
brg[j].setStock(update);
System.out.println("Data Telah Diperbarui!");
}
else
System.out.println("Batal Update Data");
}
}
if(ketemu=false) System.out.println("Data Barang Tidak Ada!");
break;
case 4:
System.out.println("\n-- Lihat Data Barang --");
if(brg[0]==null)
System.out.println("Maaf Data Barang Kosong!");
else {
for (int j
= 0; j < 5; j++) {
if(brg[j]!=null){
System.out.println("Nama
:"+brg[j].getNama());
System.out.println("Kode
:"+brg[j].getKode());
System.out.println("Harga :"+brg[j].getHarga());
System.out.println("");
}
}
}
break;
case 5:
System.out.println("\n-- Query Data Barang --");
for (int j
= 0; j < 4; j++) {
if(brg[j]!=null){
System.out.println(brg[j].Tostring());
}
}
if(brg[0]==null) System.out.println("Maaf Data Barang
Kosong!");
break;
case 6 :
System.out.println("Thank u");
}
}while(pilih2!=6);
break;
case 2:
do{
System.out.println("\nMENU Data Pembeli");
System.out.println("1. Tambah data pembeli");
System.out.println("2. Hapus data pembeli");
System.out.println("3.
Update data pembeli");
System.out.println("4. Cetak data");
System.out.println("5. Query");
System.out.println("6. Kembali");
System.out.print("Pilihan = ");
pilihh = sc.nextInt();
switch(pilihh){
case 1 :
dp[g] = new
CDataPembeli();
System.out.println("\n-- TAMBAH DATA PEMBELI --");
System.out.print("Masukkan Nama Pembeli : ");
sc=new
Scanner(System.in);
String nama =
sc.nextLine();
dp[g].setNama(nama);
System.out.print("Masukkan Alamat Pembeli : ");
sc=new
Scanner(System.in);
String almt =
sc.nextLine();
dp[g].setAlamat(almt);
System.out.print("Masukkan Tanggal Transaksi : ");
sc=new
Scanner(System.in);
String ttrn =
sc.nextLine();
dp[g].setTgltrn(ttrn);
System.out.println("Penambahan data berhasil!");
g++;
break;
case 2 :
ketemu=false;
System.out.println("\n-- HAPUS DATA PEMBELI --");
System.out.print("Masukkan nama Pembeli : ");
nama = sc.next();
for (int j = 0;
j < 10; j++) {
if (dp[j]
!= null && dp[j].getNama().equalsIgnoreCase(nama)){
ketemu=true;
System.out.println(" Data
Ditemukan!");
System.out.println("Nama :
" + dp[j].getNama());
System.out.println("Alamat : " + dp[j].getAlamat());
System.out.println("Tanggal Transaksi : " +
dp[j].getTgltrn());
System.out.println("Hapus Data Pembeli ?");
System.out.println(" 1. Ya
2. Tidak");
System.out.print("Pilih = ");
pilih2
= sc.nextInt();
if
(pilih2 == 1){
dp[j] = null;
for
(int k = j; k < 9; k++) {
dp[j] = dp[j+1];
}
System.out.println("Hapus Data Berhasil!");
}
else
System.out.println("Hapus Data Dibatalkan!");
}
}
if(ketemu==false) System.out.println("Data tidak ditemukan!");
break;
case 3 :
ketemu=false;
System.out.println("\n-- UPDATE DATA PEMBELI --");
System.out.print("Masukkan nama Pembeli : ");
nama =
sc.next();
for (int j = 0;
j < 10; j++) {
if (dp[j]
!= null && dp[j].getNama().equalsIgnoreCase(nama)){
ketemu=true;
System.out.println("Data Ditemukan");
System.out.print("Masukkan
Nama Baru : ");
String
n = sc.next(); dp[j].setNama(n);
System.out.print("Masukkan Alamat Baru : ");
String
b = sc.next(); dp[j].setAlamat(b);
System.out.print("Masukkan Tanggal Transaksi : ");
String
t = sc.next(); dp[j].setAlamat(t);
System.out.println("Simpan perubahan ?");
System.out.println("1. Ya
2. Tidak");
System.out.print("Pilih
= ");
pilih2
= sc.nextInt();
if
(pilih2 == 1){
System.out.println("Perubahan Data Berhasil disimpan!");
}
else
System.out.println("Perubahan Data Dibatalkan!");
}
}
if(ketemu==false)
System.out.println("Data Tidak Ditemukan!");
break;
case 4 :
System.out.println("\n-- CETAK DATA --");
if(dp[0]==null)
System.out.println("Tidak Ada Data");
else{
for (int j
= 0; j < 10; j++) {
if
(dp[j]!=null){
System.out.println("Nama
Pembeli : " +dp[j].getNama());
System.out.println("Alamat : " +dp[j].getAlamat());
System.out.println("Tanggal Transaksi : " +dp[j].getTgltrn());
System.out.println(" ");
}
}
}
break;
case 5 :
System.out.println("\n-- QUERY DATA --");
for (int j = 0;
j < g; j++) {
if (dp[j]!=null)
System.out.println(dp[j].ToString());
}
if(dp[0]==null)
System.out.println("Tidak Ada Data!");
break;
case 6 :
System.out.println("Thank u");
}
}while(pilihh !=6);
break;
case 3:
do{
System.out.println("\nMENU
Pendapatan");
System.out.println("1. Total Pendapatan");
System.out.println("2. Keuntungan");
System.out.println("3. Kerugian");
System.out.println("4. Query");
System.out.println("5. Kembali");
System.out.print("Pilih : ");
pil = sc.nextByte();
System.out.println(" ");
switch(pil){
case 1 :
System.out.println("\nMENU Total Pendapatan");
System.out.println("1. Lihat Total Pendapatan");
System.out.println("2. Update Total Pendapatan");
System.out.println("3. Kembali");
System.out.print("Pilih : ");
byte pill = sc.nextByte();
switch(pill){
case 1 :
int
pendpt=0;
System.out.println("\n== Lihat Total Pendapatan ==");
for
(int j = 0; j < 4; j++) {
if(brg[j]!=null){
int har = (int) brg[j].getHarga();
int sat =
brg[j].getSatuan();
pendpt = pendpt + (har*sat);
}
}
pend.setTotalPend(pendpt);
System.out.print("Total Pendapatan : Rp"+pend.getTotalPend());
break;
case 2 :
ketemu=false;
System.out.println("\n== Update Total Pendapatan ==");
System.out.print("Masukkan Nama Pembeli : ");
String
nmp = sc.nextLine();
for
(int j = 0; j < 10; j++) {
if(nmp.equalsIgnoreCase(dp[j].getNama())){
ketemu=true;
System.out.print("Total Pendapatan yang seharusnya didapat: Rp");
int tp = sc.nextInt();
System.out.println("Anda yakin akan mengupdate total
pendapatan?");
System.out.println("1. Ya
2. Tidak");
System.out.print("Pilih : ");
byte pilih5 = sc.nextByte();
if(pilih5 == 1) {
pend.setTotalPend(tp);
System.out.println("Total Pendapatan Berhasil diupdate!");
}
else System.out.println("Total Pendapatan Gagal diupdate!");
}
}
if(ketemu=false) System.out.println("Nama Pembeli Tidak
Ditemukan!");
break;
case 3 :
System.out.println("Thank u");
}
break;
case 2 :
System.out.println("\nMENU Keuntungan");
System.out.println("1. Lihat Total Keuntungan");
System.out.println("2. Hapus Total Keuntungan");
System.out.println("3. Update
Total Keuntungan");
System.out.println("4. Kembali");
System.out.print("Pilih : ");
pill =
sc.nextByte();
switch(pill){
case 1 :
modal
=0;
System.out.println("\n== Lihat Total Keuntungan ==");
for
(int j = 0; j < i; j++) {
int
hb = brg[j].getHargaBeli();
int sat =
brg[j].getSatuan();
int
stc = brg[j].getStock();
modal = modal +(hb*(sat+stc));
}
int tp =
pend.getTotalPend();
if(modal<tp) {
pend.setUntung(tp-modal);
System.out.println("Total
Keuntungan : Rp"+pend.getUntung());
}
else
System.out.println("Total Keuntungan : Rp0");
break;
case 2 :
System.out.println("\n== Hapus Total Keuntungan ==");
System.out.print("Masukkan Nama Pembeli : ");
String
nmp = sc.nextLine();
ketemu
=false;
for
(int j = 0; j < 10; j++) {
if(nmp.equalsIgnoreCase(dp[j].getNama())){
ketemu =true;
System.out.println("Anda
yakin akan menghapus data total keuntungan?");
System.out.println("1. Ya
2. Tidak");
System.out.print("Pilih : ");
byte pilih5 = sc.nextByte();
if(pilih5 == 1) {
pend.setUntung(0);
System.out.println("Data Total Keuntungan Berhasil dihapus!");
}
else System.out.println("Data Total Keuntungan Gagal
dihapus!");
}
}
if(ketemu==false)
System.out.println("Nama Pembeli Tidak Ditemukan!");
break;
case 3 :
ketemu=false;
System.out.println("\n== Update Total Keuntungan ==");
System.out.print("Masukkan Nama Pembeli : ");
nmp =
sc.nextLine();
for
(int j = 0; j < 10; j++) {
if(nmp.equalsIgnoreCase(dp[j].getNama())){
ketemu =true;
System.out.print("Total Keuntungan yang seharusnya didapat :
Rp");
int utg = sc.nextInt();
System.out.println("Anda
yakin akan mengupdate total keuntungan?");
System.out.println("1. Ya
2. Tidak");
System.out.print("Pilih : ");
byte pilih5 = sc.nextByte();
if(pilih5 == 1) {
pend.setUntung(utg);
System.out.println("Data Total Keuntungan hari ini Berhasil
diupdate!");
}
else System.out.println("Data Total Keuntungan Gagal
diupdate!");
}
}
if(ketemu=false) System.out.println("Nama Pembeli Tidak
Ditemukan!");
break;
case 4 :
System.out.println("Thank u");
}
break;
case 3 :
System.out.println("\nMENU Kerugian");
System.out.println("1. Lihat Data Kerugian Hari ini");
System.out.println("2. Hapus Data Kerugian Hari ini");
System.out.println("3. Update Data Kerugian Hari ini");
System.out.println("4. Kembali");
System.out.print("Pilih : ");
pill = sc.nextByte();
switch(pill){
case 1 :
modal=0;
System.out.println("\n== Lihat Data Kerugian Hari ini ==");
for
(int j = 0; j < i; j++) {
int
hb = brg[j].getHargaBeli();
int
sat = brg[j].getSatuan();
int
stc = brg[j].getStock();
modal = modal +(hb*(sat+stc));
pend.setModal(modal);
}
int tp
= pend.getTotalPend();
if(modal>tp) {
pend.setRugi(modal-tp);
System.out.println("Total Kerugian : Rp"+pend.getRugi());
}
else
System.out.println("Total Kerugian : Rp0");
break;
case 2 :
ketemu=false;
System.out.println("\n== Hapus Data Kerugian Hari ini ==");
System.out.print("Masukkan Nama Pembeli : ");
String
nmp = sc.nextLine();
for
(int j = 0; j < 10; j++) {
if(nmp.equalsIgnoreCase(dp[j].getNama())){
ketemu=true;
System.out.println("Anda yakin akan menghapus data kerugian yang
didapat hari ini?");
System.out.println("1. Ya
2. Tidak");
System.out.print("Pilih : ");
byte pilih5 = sc.nextByte();
if(pilih5 == 1) {
pend.setRugi(0);
System.out.println("Data Kerugian Berhasil dihapus!");
}
else System.out.println("Data Kerugian Gagal dihapus!");
}
}
if(ketemu == false) System.out.println("Nama Pembeli Tidak
Ditemukan!");
break;
case 3 :
ketemu=false;
System.out.println("\n== Update Data Kerugian Hari ini ==");
System.out.print("Masukkan Nama Pembeli : ");
nmp = sc.nextLine();
for
(int j = 0; j < 10; j++) {
if(nmp.equalsIgnoreCase(dp[j].getNama())){
ketemu =true;
System.out.print("Data Kerugian yang seharusnya didapat :
Rp");
int rg = sc.nextInt();
System.out.println("Anda yakin akan mengupdate data kerugian yang
didapat hari ini?");
System.out.println("1. Ya
2. Tidak");
System.out.print("Pilih : ");
byte pilih5 =
sc.nextByte();
if(pilih5 == 1) {
pend.setRugi(rg);
System.out.println("Data
Kerugian hari ini Berhasil diupdate!");
}
else System.out.println("Data Kerugian Gagal diupdate!");
}
}
if(ketemu==false) System.out.println("Nama Pembeli Tidak
Ditemukan!");
break;
case 4 :
System.out.println("Thank u");
}
break;
case 4 :
System.out.println("\n== Query ==");
//total pendapatan
int tp=0;
for (int j = 0; j <
i; j++) {
int har =
brg[j].getHarga();
int sat =
brg[j].getSatuan();
tp = tp +(har*sat);
pend.setTotalPend(tp);
}
//untung rugi
modal=0; int hb, stc, sat;
for (int j = 0; j <
i; j++) {
hb =
brg[j].getHargaBeli();
stc =
brg[j].getStock();
sat =
brg[j].getSatuan();
modal = modal
+(hb*(stc + sat));
}
if(modal<tp) {
pend.setUntung(tp-modal);
pend.setRugi(0);
}
else if(modal>tp) {
pend.setRugi(tp-modal);
pend.setUntung(0);
}
System.out.println(pend.ToString());
break;
case 5 :
System.out.println("Thank u");
break;
}
}while(pil!=5);
}
System.out.println("TERIMA
KASIH");
}while (pilih!=4);
}
}
0 Comments