Jumat, 20 April 2012

program elevator dengan java

membuat program elevator dengan menggunakan java

public class elevator {
        final int BOTTOM_FLOOR=1;
        final int CAPACITY=450;
        final int TOP_FLOOR=5;
        private int current_floor;
        private boolean doorOpened;
        private int weight;

        public elevator(int current_floor, int weight){
            this.current_floor=current_floor;
            this.doorOpened=false;
            this.weight=weight;
        }
        void bongkarMuat(int toWeight){
            this.weight=toWeight;
        }
        void goUp(int toFloor){
            if(doorOpened==false){
                if(current_floor!=TOP_FLOOR){
                    if(weight<=CAPACITY){
                        if(current_floor<toFloor && toFloor<TOP_FLOOR){
                            current_floor=toFloor;
                            System.out.println("Lift Naik Ke Lantai "+toFloor);
                        }
                        else{
                            System.out.println("Salah Inputan");
                        }
                    }
                    else{
                        System.out.println("Overload!!!");
                    }
                }
                else{
                    System.out.println("Sudah Di Lantai Paling Atas");
                }
            }
            else{
                System.out.println("Pintu Masih Terbuka, Tutup Dahulu");
            }
        }
        void goDown(int toFloor){
            if(doorOpened==false){
                if(current_floor!=BOTTOM_FLOOR){
                    if(weight<=CAPACITY){
                        if(current_floor>toFloor && toFloor>BOTTOM_FLOOR){
                            current_floor=toFloor;
                            System.out.println("Lift Turun Ke Lantai "+toFloor);
                        }
                        else{
                            System.out.println("Salah Inputan");
                        }
                    }
                    else{
                        System.out.println("Overload!!!");
                    }
                }
                else{
                    System.out.println("Sudah Di Lantai Paling Bawah");
                }
            }
            else{
                System.out.println("Pintu Masih Terbuka, Tutup Dahulu");
            }
        }
        void openDoor(){
            if(doorOpened==false){
                doorOpened=true;
                System.out.println("Pintu Terbuka");
            }
            else{
                System.out.println("Pintu Sudah Terbuka Um");
            }
        }
        void closeDoor(){
            if(doorOpened==true){
                doorOpened=false;
                System.out.println("Pintu Tertutup");
            }
            else{
                System.out.println("Pintu Sudah Tertutup Um");
            }
        }
}








* untuk selanjutnya buka kelas lagi dan buat program seperti ini.*
public class elevatorBeraksi {
    public static void main(String[] args) {
        elevator liftUdinus = new elevator(1, 345);


        liftUdinus.goUp(8);
        liftUdinus.goUp(4);
        liftUdinus.openDoor();
        liftUdinus.goUp(4);
        liftUdinus.bongkarMuat(467);
        liftUdinus.closeDoor();
        liftUdinus.goUp(5);
        liftUdinus.goDown(3);
        liftUdinus.goDown(3);
        liftUdinus.closeDoor();
        liftUdinus.goDown(1);
        liftUdinus.goDown(3);
    }
}

0 komentar:

Posting Komentar

newer post older post Home