Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
5.3 kB
3
Indexable
Never
package com.Dian.PBO.pertemuan4;

public class Menu {
    private int nomor;
    private String namaMakanan;
    private int harga;
    private int stock;

    public void detailMakanan() {
        System.out.println("Nomor Makanan : " + nomor);
        System.out.println("Nama Makanan  : " + namaMakanan);
        System.out.println("Harga Makanan : " + harga);
        System.out.println("Stock Makanan : " + stock);
    }

    public int getNomor() {
        return nomor;
    }

    public void setNomor(int nomor) {
        this.nomor = nomor;
    }

    public String getNamaMakanan() {
        return namaMakanan;
    }

    public void setNamaMakanan(String namaMakanan) {
        this.namaMakanan = namaMakanan;
    }

    public int getHarga() {
        return harga;
    }

    public void setHarga(int harga) {
        this.harga = harga;
    }

    public int getStock() {
        return stock;
    }

    public void setStock(int stock) {
        this.stock = stock;
    }

    public int totalHarga(int jumlah) {
        return harga * jumlah;
    }
}



package com.Dian.PBO.pertemuan4;

public class WarungMakan extends Menu {
    private String namaWarung;
    private String alamatWarung;
    private String noTelp;

    public String getNamaWarung() {
        return namaWarung;
    }

    public void setNamaWarung(String namaWarung) {
        this.namaWarung = namaWarung;
    }

    public String getAlamatWarung() {
        return alamatWarung;
    }

    public void setAlamatWarung(String alamatWarung) {
        this.alamatWarung = alamatWarung;
    }

    public String getNoTelp() {
        return noTelp;
    }

    public void setNoTelp(String noTelp) {
        this.noTelp = noTelp;
    }

    public void detailWarung() {
        System.out.println("Warung  : " + namaWarung);
        System.out.println("Alamat  : " + alamatWarung);
        System.out.println("No Telp : " + noTelp);
    }


    public void beliMakanan(Menu menu, int jumlah) {
        if (menu.getStock() < jumlah ){
            System.out.println("Stok Tidak Cukup");
            return;
        }
        System.out.println("<<<< Detail Pembelian >>>>");
        System.out.println("Nama Makanan  : " + menu.getNamaMakanan());
        System.out.println("Harga Satuan  : " + menu.getHarga());
        System.out.println("Jumlah Beli   : " + jumlah);
        menu.totalHarga(jumlah);
        System.out.println("<<<< Detail Pembelian)");

        int stok = menu.getStock() - jumlah;
        menu.setStock(stok);

    }
    public void cekStock(Menu menu, int jumlah){
        System.out.println("Sisa Stok     : " + menu.getStock());
    }
}


package com.Dian.PBO.pertemuan4;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        WarungMakan warung = new WarungMakan();
        warung.setNamaWarung("Rumah Makan Nasi Goyeng");
        warung.setAlamatWarung("Jl. kemana aja 123");
        warung.setNoTelp("081312345432");

        Menu nasiGoreng = new Menu();
        nasiGoreng.setNomor(1);
        nasiGoreng.setNamaMakanan("Nasi Goreng");
        nasiGoreng.setHarga(10000);
        nasiGoreng.setStock(10);

        Menu nasiGorengS = new Menu();
        nasiGorengS.setNomor(2);
        nasiGorengS.setNamaMakanan("Nasi Goreng Spesial");
        nasiGorengS.setHarga(15000);
        nasiGorengS.setStock(4);

        Menu nasiGorengST = new Menu();
        nasiGorengST.setNomor(3);
        nasiGorengST.setNamaMakanan("Nasi Goreng Spesial + Telur");
        nasiGorengST.setHarga(20000);
        nasiGorengST.setStock(20);

        System.out.println("<<<< RUMAH MAKAN NASI GOYENG >>>>");
        warung.detailWarung();
        System.out.println("<<<< MENU MAKANAN >>>>");
        nasiGoreng.detailMakanan();
        nasiGorengS.detailMakanan();
        nasiGorengST.detailMakanan();

        Scanner input = new Scanner(System.in);

        System.out.print("Masukkan Nomor Makanan  : ");
        int nomormakanan = input.nextInt();
        System.out.print("Masukkan Jumlah Makanan : ");
        int jumlahmakanan = input.nextInt();

        if (nomormakanan == 1){
            warung.beliMakanan(nasiGoreng, jumlahmakanan);
            int totalharga = jumlahmakanan * nasiGoreng.getHarga();
            System.out.println("Total Harga   : " + totalharga);
            warung.cekStock(nasiGoreng, jumlahmakanan);
            System.out.println();

        } else if (nomormakanan == 2) {
            warung.beliMakanan(nasiGorengS, jumlahmakanan);
            int totalharga = jumlahmakanan * nasiGorengS.getHarga();
            System.out.println("Total Harga   : " + totalharga);
            warung.cekStock(nasiGorengS, jumlahmakanan);
            System.out.println();

        } else if (nomormakanan == 3) {
            warung.beliMakanan(nasiGorengST, jumlahmakanan);
            int totalharga = jumlahmakanan * nasiGorengST.getHarga();
            System.out.println("Total Harga   : " + totalharga);
            warung.cekStock(nasiGorengST, jumlahmakanan);
            System.out.println();

        } else {
            System.out.println("Menu Tidak Tersedia");
        }

    }
}