Rabu, 17 Oktober 2012
Main
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package kalkulator;

/**
 *
 * @author Praktikum
 */
public class Main {
    private int a;
    private int b;
    private int hasil;

   
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
    }

    /**
     * @return the a
     */
    public int getA() {
        return a;
    }

    /**
     * @param a the a to set
     */
    public void setA(int a) {
        this.a = a;
    }

    /**
     * @return the b
     */
    public int getB() {
        return b;
    }

    /**
     * @param b the b to set
     */
    public void setB(int b) {
        this.b = b;
    }

    int tambah(){
       return a+b;
    }
    int kurang(){
        return a-b;
    }
    int kali(){
        return a*b;
    }
    int bagi(){
        return a/b;
    }

    void display(){


        }

    /**
     * @return the hasil
     */
    public int getHasil() {
        return hasil;
    }

    /**
     * @param hasil the hasil to set
     */
    public void setHasil(int hasil) {
        this.hasil = hasil;
    }

}
 
Driver

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package kalkulator;
import java.util.Scanner;
/**
 *
 * @author Praktikum
 */
public class driver {
    public static void main(String args[]){
        int pil;
        Scanner key = new Scanner(System.in);
        Main Kal= new Main();

        do{
        System.out.println("Kalkulator");
        System.out.println("1. Tambah");
        System.out.println("2. Kurang");
        System.out.println("3. Kali");
        System.out.println("4. Bagi");
        System.out.println("0. OUT");
        System.out.print("Pilihan : ");
        pil = key.nextInt();
            switch(pil){
                case 1:
                    System.out.print("Masukan Bilangan Ke-1 : ");
                    Kal.setA(key.nextInt());
                    System.out.print("Masukan Bilangan Ke-2 : ");
                    Kal.setB(key.nextInt());
                    System.out.println("Hasil = "+ Kal.tambah());
                    System.out.println();
                    break;
                case 2:
                    System.out.print("Masukan Bilangan Ke-1 : ");
                    Kal.setA(key.nextInt());
                    System.out.print("Masukan Bilangan Ke-2 : ");
                    Kal.setB(key.nextInt());
                    System.out.println("Hasil = "+ Kal.kurang());
                    System.out.println();
                    break;
                case 3:
                    System.out.print("Masukan Bilangan Ke-1 : ");
                    Kal.setA(key.nextInt());
                    System.out.print("Masukan Bilangan Ke-2 : ");
                    Kal.setB(key.nextInt());
                    System.out.println("Hasil = "+ Kal.kali());
                    System.out.println();
                    break;
                case 4:

                    System.out.print("Masukan Bilangan Ke-1 : ");
                    Kal.setA(key.nextInt());
                    System.out.print("Masukan Bilangan Ke-2 : ");
                    Kal.setB(key.nextInt());
                    System.out.println("Hasil = "+ Kal.bagi());
                    System.out.println();
                    break;

                case 0: System.out.print("Keluar");
                default: System.out.println("Perintah Tidak ada");



        //switch(int ){
    }}while(pil!=0);
}}
 

0 komentar: