INTERFACE ATAU PEWARISAN DALAM JAVA DENGAN NETBEANS

langkah 1

  1. buat projek Apotek 
  2. buat class dalam projek Apotek
  • Apotekdao
  • Apotekdaoimp(implement)
  • main (pemanggilan)

Projek Apotek 
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mainn;

/**
 *
 * @author icko
 */
public class Apotek {
    private String obat;
    private String harga;
    private String kasir;
    private String pengunjung;

    public String getObat() {
        return obat;
    }

    public void setObat(String obat) {
        this.obat = obat;
    }

    public String getHarga() {
        return harga;
    }

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

    public String getKasir() {
        return kasir;
    }

    public void setKasir(String kasir) {
        this.kasir = kasir;
    }

    public String getPengunjung() {
        return pengunjung;
    }

    public void setPengunjung(String pengunjung) {
        this.pengunjung = pengunjung;
    }

    void infoApotek(String obat, String kasir, String pengunjung, String harga) {
       // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
   
        this.obat=obat;
        this.kasir=kasir;
        this.pengunjung=pengunjung;
        this.harga=harga;
        
        System.out.println("Obat :"+obat);
        System.out.println("Kasir :"+kasir);
        System.out.println("Pengunjung"+pengunjung);
        System.out.println("Harga"+harga);
    
    }
    
    
    
    
}

Dalam Class Apotekdao
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mainn;

/**
 *
 * @author icko
 */
public interface Apotekdao {
    public void pesanobat();
    public void beliobat();
    public void infoobat();
    }

Dalam Class Apotekdaoimp
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mainn;

/**
 *
 * @author icko
 */
public class Apotekdaoimp implements Apotekdao{
 Apotek obat =new Apotek();
    @Override
    public void pesanobat() {
      obat.setObat("DAKTARIN CREAM 10GR");
      obat.setKasir("Onie");
      obat.setPengunjung("icko");
      obat.setHarga("Rp. 32.800");
      
    }

    @Override
    public void beliobat() {
      obat.setObat("DAKTARIN CREAM 10GR");
      obat.setKasir("Onie");
      obat.setPengunjung("icko");
      obat.setHarga("Rp. 32.800");  
    }

   
    public void infoobat() {
        obat.infoApotek(obat.getObat(),obat.getKasir(),obat.getPengunjung(),obat.getHarga());
        
    }
    
   
}

Dalam Class Main 
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mainn;

/**
 *
 * @author icko
 */
public class Mainn {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        
        Apotekdaoimp x =new Apotekdaoimp();
        x.beliobat();
        x.pesanobat();
        x.infoobat();
       
        
        System.out.println("");
    }
}

SELAMAT MENCOBA