Minggu, 22 April 2012

Program atm dengan java

0 komentar
*untuk pertama membuat class atm yang berisi tentang menu atm&menjelaskan isi dalam daftar menu atm*


public class ATM {
    String nasabah; double saldo; int nTransaksi=0;
    Histori[] histori = new Histori[10];
    public ATM(){}
    public ATM(String nasabah, double saldo){
        this.nasabah=nasabah;
        this.saldo=saldo }
    void menuUtama(){
        System.out.println("ATM\n\n");
        System.out.println("1. Tarik tunai");
        System.out.println("2. Setor tunai");
        System.out.println("3. Info Saldo");
        System.out.println("4. Histori transaksi");
        System.out.println("0. Keluar\n");
        System.out.print("Masukkan pilihan :"); }
    void menuTarik(){
        System.out.println("ATM\n\n");
        System.out.println("1. Tarik tunai\n");
        System.out.println("saldo anda :"+this.saldo+"\n");
        System.out.print("Masukkan nominal :");}
    void tarikTunai(double nominal){
        if (this.saldo>=nominal){           
            histori[nTransaksi] = new Histori();
            histori[nTransaksi].jnsTransaksi = "tarikTunai";
            histori[nTransaksi].saldoAwal = this.saldo;
            histori[nTransaksi].saldoAhir = this.saldo-=nominal;
            nTransaksi++;
        } else {
      System.out.println("Saldo anda tidak mencukupi");}
    }
 void menuSetor(){
        System.out.println("ATM\n\n");
        System.out.println("2. Setor tunai\n");
        System.out.println("saldo anda :"+this.saldo+"\n");
        System.out.print("Masukkan nominal :");}
   void setorTunai(double nominal){
            histori[nTransaksi] = new Histori();
            histori[nTransaksi].jnsTransaksi = "setorTunai";
            histori[nTransaksi].saldoAwal = this.saldo;
            histori[nTransaksi].saldoAhir = this.saldo+=nominal;
            nTransaksi++; }
   void ceksaldo(){
        System.out.println("Saldo Anda : "+this.saldo); }
      void menuHistori(){
        System.out.println("ATM\n\n");
        System.out.println("4. Histori Transaksi\n");
        System.out.println("No.\tJenis Transaksi\t\t nominal \t\tSaldo Awal\t\tSaldo Ahir");
        for(int n=0;n<this.nTransaksi;n++) {
      System.out.println(n+".\t"+histori[n].jnsTransaksi+"\t\t"+histori[n].saldoAwal+"\t\t"+histori[n].saldoAhir);
        }
    }
}


*untuk class yang kedua menjalankan program atm*

public class ATMberaksi {
    public static void main(String[] args) {
        Scanner inputan = new Scanner(System.in);
        ATM atm = new ATM("Fajar",9000);
        int pil=0; double nominal;
        do {
            atm.menuUtama();
            pil=inputan.nextInt();
            switch (pil) {
                case 1:
                    atm.menuTarik();
                    nominal=inputan.nextDouble();
                    atm.tarikTunai(nominal);
                    break;
                case 2:
                    atm.menuSetor();
                    nominal=inputan.nextDouble();
                    atm.setorTunai(nominal);
                    break;
                case 3:
                    atm.ceksaldo();
                    break;
                case 4:
                    atm.menuHistori();
                    break;
            }
        } while(pil!=0);
    }
}


*untuk class yang terakhr tentang histori / transaksi atm *

public class Histori {
    String jnsTransaksi;
    double saldoAwal, saldoAhir;
    public Histori(){
    }
}

* semoga bermanfaat bagi kalian*
newer post

Jumat, 20 April 2012

program elevator dengan java

0 komentar
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);
    }
}
newer post
newer post older post Home