Archive for Mei 2015

SIXTH MEETING : INTERFACE

Selasa, 12 Mei 2015
Posted by Octo The Azura


SIXTH MEETING : INTERFACE
NAME
RAHMATUL MAHDALINA
STUDENT NUMBER
L200134004
CLASS
X


A.    Objective
Students are understand about interface in java

B.     Basic Teory
       Interface is a mechanism available in java and enable for share constantan or determine a method that used some class. A glance interface is like with abstract class, so abstract class determined method for subclass too.

C.    Tools and Materials
·      Laptop
·      Practice Object Oriented Programming Modul
·      Software NetBeans IDE 8.0.2
·      Java Development Kit (JDK) 1.8.0_31

D.    Work Step
EXPERIMENT
Steps of experiment:
1.    Create new interface by name “IntLampu.java” like in the picture
            package Interface;

/**
 *
 * @author Octopus_girl
 */
public interface IntLampu {
    public static final int KEADAAN_HIDUP = 1;
    public static final int KEADAAN_MATI = 0;
   
    public abstract void hidupkan();
    public abstract void matikan();
}
           

2.    Compile the program

3.    Create new class by name “Lampu.java” that is implementation from interface “IntLampu.java”

4.    Write the program code like this :
            package Interface;

/**
 *
 * @author Octopus_girl
 */
public class Lampu implements IntLampu {
    private int statusLampu = 0;
   
    public void hidupkan(){
        if(this.statusLampu != KEADAAN_MATI){
            this.statusLampu = KEADAAN_HIDUP;
            System.out.println("Lampu Hidup");
        }
        else{
            System.out.println("Lampu Sudah Hidup");
        }
    }
        public void matikan(){
        if(this.statusLampu != KEADAAN_HIDUP){
            this.statusLampu = KEADAAN_MATI;
            System.out.println("Lampu mati");
        }
        else{
            System.out.println("Lampu Sudah mati");
        }
    }  
}
   
5.    Compile, analyst described the class
6.    Create new class with main method () that is implementation of “Lampu.java” class. Write the program code like this :
package Interface;

/**
 *
 * @author Octopus_girl
 */
public class TesInterface {
    public static void main (String []args){
        Lampu lampuKamar = new Lampu();
        lampuKamar.hidupkan();
        lampuKamar.hidupkan();
        lampuKamar.matikan();
        lampuKamar.matikan();
    }
}
7.    Compile and run the program

EXERCISE

1.    Modification interface “IntLampu.java” by changed the final variable became
    public static final int KEADAAN_HIDUP = 2;
    public static final int KEADAAN_REDUP = 1;
    public static final int KEADAAN_MATI = 0;

add method redupkan ( )
    public abstract void redupkan()

2.    Modification class “TestInterface.java” in order that run and the output like in picture
package Interface;

/**
 *
 * @author Octopus_girl
 */
public class TesInterface {
    public static void main (String []args){
        Lampu lampuKamar = new Lampu();
        lampuKamar.hidupkan();
        lampuKamar.hidupkan();
        lampuKamar.matikan();
        lampuKamar.matikan();
        lampuKamar.hidupkan();
        lampuKamar.redupkan();
        lampuKamar.redupkan();
    }
}


3.    Create the analysis of the result
E.   Analysis
      Interface is looks like abstract class and can access by other class and for calling method. In the experiment and exercise it's tell about the changed condition and we can make it by interface.
Welcome to My Blog

Popular Post

Blogger templates

Pengikut

Diberdayakan oleh Blogger.

Arsip Blog

- Copyright © Mahdalina -Robotic Notes- Powered by Blogger - Designed by Johanes Djogan -