Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package swalayan;
- import java.util.Scanner;
- public class Swalayan{
- String namaBarang;
- int harga,total,id,jumlah;
- public Scanner str=new Scanner(System.in);
- public Scanner in=new Scanner(System.in);
- public void setData(){
- this.id=160500;
- }
- public void setData(int id){
- this.id=1+id;
- System.out.print("Masukkan nama barang : ");
- this.namaBarang=str.nextLine();
- System.out.print("Masukkan harga barang : ");
- this.harga=in.nextInt();
- this.jumlah=1;
- this.total=this.harga;
- }
- public void setData(int id,int jumlah){
- this.id=1+id;
- System.out.print("Masukkan nama barang : ");
- this.namaBarang=str.nextLine();
- System.out.print("Masukkan harga barang : ");
- this.harga=in.nextInt();
- this.jumlah=jumlah;
- this.total=this.harga*jumlah;
- }
- public int getId(){
- return this.id;
- }
- public void tampil(){
- System.out.println("Id penjualan : "+this.id);
- System.out.println("Nama Barang : "+this.namaBarang);
- System.out.println("Harga Barang : "+this.harga);
- System.out.println("Jumlah Barang: "+this.jumlah);
- System.out.println("Total Harga : "+this.total);
- }
- public static void main(String[] args){
- int z=0,menu=0,a,jumlah,id;
- Swalayan[] sw=new Swalayan[1024];
- sw[0]=new Swalayan();
- sw[0].setData();
- while(menu!=6){
- System.out.print("1.input\n2.view\n3.search\n4.update\n5.delete\n6.exit\n : ");
- menu=sw[0].in.nextInt();
- if(menu==1){
- jumlah=0;
- while(jumlah<1){
- System.out.print("masukkan jumlah barang : ");
- jumlah=sw[0].in.nextInt();
- }
- z++;
- sw[z]=new Swalayan();
- if(jumlah>1)
- sw[z].setData(sw[z-1].getId(),jumlah);
- else
- sw[z].setData(sw[z-1].getId());
- }else if(menu==2){
- if(z<1)
- System.out.println("data kosong");
- else{
- a=0;
- while(a<z){
- a++;
- System.out.println("---"+a+"---");
- sw[a].tampil();
- }
- }
- }else if(menu==3){
- if(z<1)
- System.out.println("data kosong");
- else{
- System.out.print("masukkan id pembeli yang dicari : ");
- id=sw[0].in.nextInt();
- a=1;
- while(a<=z){
- if(sw[a].getId()==id)
- break;
- a++;
- }
- if(a<=z)
- sw[a].tampil();
- else
- System.out.println("data tidak ditemukan");
- }
- }else if(menu==4){
- if(z<1)
- System.out.println("data kosong");
- else{
- System.out.print("masukkan id pembeli yang diupdate : ");
- id=sw[0].in.nextInt();
- a=1;
- while(a<=z){
- if(sw[a].getId()==id)
- break;
- a++;
- }
- if(a<=z){
- sw[a].tampil();
- jumlah=0;
- while(jumlah<1){
- System.out.print("masukkan jumlah barang : ");
- jumlah=sw[0].in.nextInt();
- }
- if(jumlah>1)
- sw[a].setData(sw[z-1].getId(),jumlah);
- else
- sw[a].setData(sw[z-1].getId());
- }
- else
- System.out.println("data tidak ditemukan");
- }
- }else if(menu==5){
- if(z<1)
- System.out.println("data kosong");
- else{
- System.out.print("masukkan id pembeli yang didelete : ");
- id=sw[0].in.nextInt();
- a=1;
- while(a<=z){
- if(sw[a].getId()==id)
- break;
- a++;
- }
- if(a<=z){
- while(a<z){
- sw[a]=sw[a+1];
- a++;
- }
- z--;
- System.out.println("data berhasil dihapus");
- }
- else
- System.out.println("data tidak ditemukan");
- }
- }else if(menu==6)
- System.out.println("keluar...");
- else
- System.out.println("menu ilegal");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement