Wednesday, October 31, 2012

Menebak Angka Khayalmu dengan JOPtionPane JAVA

import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;

/**
 *
 * @author ERFAN FEBRIANTORO, NIM. 1210652040,
 * @author TEKNIK INFORMATIKA - UNMUH JEMBER
 */
public class Tebak_Angka_Di_Pikiranmu {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // Latihan Pemrograman Terstruktur "Mendapatkan Inputan dari Keyboard"
        // Sekarang, giliran JAVA yang menebak ANGKA MISTERIMU . . .
        String welcome1 = null, welcome2 = null, bil1, bil2, bil3, bil4, bil5, bil6, bil7, bil8, warning, ulangi, ulangi2, jawaban, pilihan;
        welcome1 = "Selamat Datang di Permainan Tebak Angka."
                + "\nPresented by :"
                + "\nerfan2040.blogspot.com (c) 2012";
        welcome2 = "Pikirkan sebuah angka antara 0 - 100 !!";
        bil1 = "(a). Pertanyaan PERTAMA :\nApakah angka yang kamu pikirkan ada disini?"
                + "\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51"
                + "\n53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99"
                + "\nJika ADA, isikan '1'\nJika TIDAK ADA, isikan '0'";
        bil2 = "(b). Pertanyaan KEDUA :\nApakah angkamu ada disini?"
                + "\n2 3 6 7 10 11 14 15 18 19 22 23 26 27 30 31 34 35 38 39 42 43 46 47 50 51"
                + "\n54 55 58 59 62 63 66 67 70 71 74 75 78 79 82 83 86 87 90 91 94 95 98 99"
                + "\nJika ADA, isikan '1'\nJika TIDAK ADA, isikan '0'";
        bil3 = "(c). Pertanyaan KETIGA :\nApakah angkamu ada disini?"
                + "\n4 5 6 7 12 13 14 15 20 21 22 23 28 29 30 31 36 37 38 39 44 45 46 47 52 53"
                + "\n54 55 60 61 62 63 68 69 70 71 76 77 78 79 84 85 86 87 92 93 94 95 100"
                + "\nJika ADA, isikan '1'\nJika TIDAK ADA, isikan '0'";
        bil4 = "(d). Pertanyaan KEEMPAT :\nApakah angkamu ada disini?"
                + "\n8 9 10 11 12 13 14 15 24 25 26 27 28 29 30 31 40 41 42 43 44 45 46 47 56 57"
                + "\n58 59 60 61 62 63 72 73 74 75 76 77 78 79 88 89 90 91 92 93 94 95"
                + "\nJika ADA, isikan '1'\nJika TIDAK ADA, isikan '0'";
        bil5 = "(e). Pertanyaan KELIMA :\nApakah angkamu ada disini?"
                + "\n16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 48 49 50 51 52 53 54 55 56 57"
                + "\n58 59 60 61 62 63 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100"
                + "\nJika ADA, isikan '1'\nJika TIDAK ADA, isikan '0'";
        bil6 = "(f). Pertanyaan KEENAM :\nApakah angkamu ada disini?"
                + "\n32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49"
                + "\n 50 51 52 53 54 55 56 57 58 59 60 61 62 63 96 97 98 99 100"
                + "\nJika ADA, isikan '1'\nJika TIDAK ADA, isikan '0'";
        bil7 = "(g). Pertanyaan KETUJUH :\nApakah angkamu ada disini?"
                + "\n64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81"
                + "\n82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100"
                + "\nJika ADA, isikan '1'\nJika TIDAK ADA, isikan '0'";
        bil8 = "(h). Pertanyaan KEDELAPAN:\nApakah seluruh pertanyaan kamu jawab dengan Jujur?"
                + "\nJika JUJUR, isikan '1'\nJika TIDAK atau RAGU-RAGU, isikan '0'";
        warning = "Maaf, Anda hanya diperkenankan memasukkan karakter angka 0 atau 1 saja."
                + "\nSelain itu, WASSALAM & GOOD BYE . . .";
        ulangi = "Maaf, tentukan pilihanmu hanya dengan mengetikkan :"
                + "\n0 (nol), jika Angkamu TIDAK ADA;"
                + "\n1 (satu), jika Angkamu ADA;\nTRY AGAIN . . .";
        ulangi2 = "Maaf, tentukan KEJUJURANMU hanya dengan mengetikkan :"
                + "\n0 (nol), jika kamu RAGU-RAGU atau TIDAK JUJUR;"
                + "\n1 (satu), jika Angkamu JUJUR;\nTRY AGAIN . . .";
        jawaban = "Pilihan Anda telah disimpan. Lanjutkan . . .";
        pilihan = null;

        int opsi, ya, tdk, data;
        data = 0;
        opsi = 0;
        ya = 1;
        tdk = 0;

        boolean tes = true;

        int himbulat[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
            21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
            41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
            61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
            81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100};
        int himganjil[] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39,
            41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79,
            81, 83, 85, 87, 89, 91, 93, 95, 97, 99};
        int himgenap[] = {0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38,
            40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80,
            82, 84, 86, 88, 90, 92, 94, 96, 98, 100};
        int hima[] = {2, 3, 6, 7, 10, 11, 14, 15, 18, 19, 22, 23, 26, 27, 30, 31, 34, 35, 38, 39,
            42, 43, 46, 47, 50, 51, 54, 55, 58, 59, 62, 63, 66, 67, 70, 71, 74, 75, 78, 79, 82,
            83, 86, 87, 90, 91, 94, 95, 98, 99};
        int himan[] = {0, 1, 4, 5, 8, 9, 12, 13, 16, 17, 20, 21, 24, 25, 28, 29, 32, 33, 36, 37, 40,
            41, 44, 45, 48, 49, 52, 53, 56, 57, 60, 61, 64, 65, 68, 69, 72, 73, 76, 77, 80,
            81, 84, 85, 88, 89, 92, 93, 96, 97, 100};
        int himb[] = {4, 5, 6, 7, 12, 13, 14, 15, 20, 21, 22, 23, 28, 29, 30, 31, 36, 37, 38, 39,
            44, 45, 46, 47, 52, 53, 54, 55, 60, 61, 62, 63, 68, 69, 70, 71, 76, 77, 78, 79, 84,
            85, 86, 87, 92, 93, 94, 95, 100};
        int himbn[] = {0, 1, 2, 3, 8, 9, 10, 11, 16, 17, 18, 19, 24, 25, 26, 27, 32, 33, 34, 35,
            40, 41, 42, 43, 48, 49, 50, 51, 56, 57, 58, 59, 64, 65, 66, 67, 72, 73, 74, 75,
            80, 81, 82, 83, 88, 89, 90, 91, 96, 97, 98, 99};
        int himc[] = {8, 9, 10, 11, 12, 13, 14, 15, 24, 25, 26, 27, 28, 29, 30, 31,
            40, 41, 42, 43, 44, 45, 46, 47, 56, 57, 58, 59, 60, 61, 62, 63,
            72, 73, 74, 75, 76, 77, 78, 79, 88, 89, 90, 91, 92, 93, 94, 95};
        int himcn[] = {0, 1, 2, 3, 4, 5, 6, 7, 16, 17, 18, 19, 20, 21, 22, 23,
            32, 33, 34, 35, 36, 37, 38, 39, 48, 49, 50, 51, 52, 53, 54, 55,
            64, 65, 66, 67, 68, 69, 70, 71, 80, 81, 82, 83, 84, 85, 86, 87, 96, 97, 98, 99, 100};
        int himd[] = {16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
            48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
            80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100};
        int himdn[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
            32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
            64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79};
        int hime[] = {32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
            50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 96, 97, 98, 99, 100};
        int himen[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
            21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73,
            74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95};
        int himf[] = {64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
            81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100};
        int himfn[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
            21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
            41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63};

        List step1 = new ArrayList();
        List step2 = new ArrayList();
        List step3 = new ArrayList();
        List step4 = new ArrayList();
        List step5 = new ArrayList();
        List step6 = new ArrayList();
        List step7 = new ArrayList();

        // Menampilkan Input dan Message Dialog :

        JOptionPane.showMessageDialog(null, welcome1);
        JOptionPane.showMessageDialog(null, welcome2);

        try {
            // Pertanyaan PERTAMA :
            do {
                pilihan = JOptionPane.showInputDialog(null, bil1);
                opsi = Integer.parseInt(pilihan);
                data = opsi;
                if (tes = (opsi == ya) | (opsi == tdk)) {
                    JOptionPane.showMessageDialog(null, jawaban);
                    System.out.println(data);
                    if (data == 1) {
                        for (int k = 0; k < himbulat.length; k++) {
                            for (int j = 0; j < himganjil.length; j++) {
                                if (himbulat[k] == himganjil[j]) {
                                    step1.add(himbulat[k]);
                                }
                            }
                        }
                    } else if (data == 0) {
                        for (int k = 0; k < himbulat.length; k++) {
                            for (int j = 0; j < himgenap.length; j++) {
                                if (himbulat[k] == himgenap[j]) {
                                    step1.add(himbulat[k]);
                                }
                            }
                        }
                    }
                    System.out.println(step1);
                    tes = (opsi == ya) | (opsi == tdk);
                    break;
                } else {
                    JOptionPane.showMessageDialog(null, ulangi);
                    tes = (opsi != ya) | (opsi != tdk);
                }
            } while (tes);

            // Pertanyaan KEDUA :
            do {
                pilihan = JOptionPane.showInputDialog(null, bil2);
                opsi = Integer.parseInt(pilihan);
                data = opsi;
                if (tes = (opsi == ya) | (opsi == tdk)) {
                    JOptionPane.showMessageDialog(null, jawaban);
                    System.out.println(data);
                    if (data == 1) {
                        for (int k = 0; k < step1.size(); k++) {
                            for (int j = 0; j < hima.length; j++) {
                                if (step1.get(k) == hima[j]) {
                                    step2.add(step1.get(k));
                                }
                            }
                        }
                    } else if (data == 0) {
                        for (int k = 0; k < step1.size(); k++) {
                            for (int j = 0; j < himan.length; j++) {
                                if (step1.get(k) == himan[j]) {
                                    step2.add(step1.get(k));
                                }
                            }
                        }
                    }
                    System.out.println(step2);
                    tes = (opsi == ya) | (opsi == tdk);
                    break;
                } else {
                    JOptionPane.showMessageDialog(null, ulangi);
                    tes = (opsi != ya) | (opsi != tdk);
                }
            } while (tes);

            // Pertanyaan KETIGA :
            do {
                pilihan = JOptionPane.showInputDialog(null, bil3);
                opsi = Integer.parseInt(pilihan);
                data = opsi;
                if (tes = (opsi == ya) | (opsi == tdk)) {
                    JOptionPane.showMessageDialog(null, jawaban);
                    System.out.println(data);
                    if (data == 1) {
                        for (int k = 0; k < step2.size(); k++) {
                            for (int j = 0; j < himb.length; j++) {
                                if (step2.get(k) == himb[j]) {
                                    step3.add(step2.get(k));
                                }
                            }
                        }
                    } else if (data == 0) {
                        for (int k = 0; k < step2.size(); k++) {
                            for (int j = 0; j < himbn.length; j++) {
                                if (step2.get(k) == himbn[j]) {
                                    step3.add(step2.get(k));
                                }
                            }
                        }
                    }
                    System.out.println(step3);
                    tes = (opsi == ya) | (opsi == tdk);
                    break;
                } else {
                    JOptionPane.showMessageDialog(null, ulangi);
                    tes = (opsi != ya) | (opsi != tdk);
                }
            } while (tes);

            // Pertanyaan KEEMPAT :
            do {
                pilihan = JOptionPane.showInputDialog(null, bil4);
                opsi = Integer.parseInt(pilihan);
                data = opsi;
                if (tes = (opsi == ya) | (opsi == tdk)) {
                    JOptionPane.showMessageDialog(null, jawaban);
                    System.out.println(data);
                    if (data == 1) {
                        for (int k = 0; k < step3.size(); k++) {
                            for (int j = 0; j < himc.length; j++) {
                                if (step3.get(k) == himc[j]) {
                                    step4.add(step3.get(k));
                                }
                            }
                        }
                    } else if (data == 0) {
                        for (int k = 0; k < step3.size(); k++) {
                            for (int j = 0; j < himcn.length; j++) {
                                if (step3.get(k) == himcn[j]) {
                                    step4.add(step3.get(k));
                                }
                            }
                        }
                    }
                    System.out.println(step4);
                    tes = (opsi == ya) | (opsi == tdk);
                    break;
                } else {
                    JOptionPane.showMessageDialog(null, ulangi);
                    tes = (opsi != ya) | (opsi != tdk);
                }
            } while (tes);

            // Pertanyaan KELIMA :
            do {
                pilihan = JOptionPane.showInputDialog(null, bil5);
                opsi = Integer.parseInt(pilihan);
                data = opsi;
                if (tes = (opsi == ya) | (opsi == tdk)) {
                    JOptionPane.showMessageDialog(null, jawaban);
                    System.out.println(data);
                    if (data == 1) {
                        for (int k = 0; k < step4.size(); k++) {
                            for (int j = 0; j < himd.length; j++) {
                                if (step4.get(k) == himd[j]) {
                                    step5.add(step4.get(k));
                                }
                            }
                        }
                    } else if (data == 0) {
                        for (int k = 0; k < step4.size(); k++) {
                            for (int j = 0; j < himdn.length; j++) {
                                if (step4.get(k) == himdn[j]) {
                                    step5.add(step4.get(k));
                                }
                            }
                        }
                    }
                    System.out.println(step5);
                    tes = (opsi == ya) | (opsi == tdk);
                    break;
                } else {
                    JOptionPane.showMessageDialog(null, ulangi);
                    tes = (opsi != ya) | (opsi != tdk);
                }
            } while (tes);

            // Pertanyaan KEENAM :
            do {
                pilihan = JOptionPane.showInputDialog(null, bil6);
                opsi = Integer.parseInt(pilihan);
                data = opsi;
                if (tes = (opsi == ya) | (opsi == tdk)) {
                    JOptionPane.showMessageDialog(null, jawaban);
                    System.out.println(data);
                    if (data == 1) {
                        for (int k = 0; k < step5.size(); k++) {
                            for (int j = 0; j < hime.length; j++) {
                                if (step5.get(k) == hime[j]) {
                                    step6.add(step5.get(k));
                                }
                            }
                        }
                    } else if (data == 0) {
                        for (int k = 0; k < step5.size(); k++) {
                            for (int j = 0; j < himen.length; j++) {
                                if (step5.get(k) == himen[j]) {
                                    step6.add(step5.get(k));
                                }
                            }
                        }
                    }
                    System.out.println(step6);
                    tes = (opsi == ya) | (opsi == tdk);
                    break;
                } else {
                    JOptionPane.showMessageDialog(null, ulangi);
                    tes = (opsi != ya) | (opsi != tdk);
                }
            } while (tes);

            // Pertanyaan KETUJUH :
            do {
                pilihan = JOptionPane.showInputDialog(null, bil7);
                opsi = Integer.parseInt(pilihan);
                data = opsi;
                if (tes = (opsi == ya) | (opsi == tdk)) {
                    JOptionPane.showMessageDialog(null, jawaban);
                    System.out.println(data);
                    if (data == 1) {
                        for (int k = 0; k < step6.size(); k++) {
                            for (int j = 0; j < himf.length; j++) {
                                if (step6.get(k) == himf[j]) {
                                    step7.add(step6.get(k));
                                }
                            }
                        }
                    } else if (data == 0) {
                        for (int k = 0; k < step6.size(); k++) {
                            for (int j = 0; j < himfn.length; j++) {
                                if (step6.get(k) == himfn[j]) {
                                    step7.add(step6.get(k));
                                }
                            }
                        }
                    }
                    System.out.println(step7);
                    tes = (opsi == ya) | (opsi == tdk);
                    break;
                } else {
                    JOptionPane.showMessageDialog(null, ulangi);
                    tes = (opsi != ya) | (opsi != tdk);
                }
            } while (tes);

            // Pertanyaan KEDELAPAN :
            do {
                pilihan = JOptionPane.showInputDialog(null, bil8);
                opsi = Integer.parseInt(pilihan);
                data = opsi;
                if (tes = (opsi == ya) | (opsi == tdk)) {
                    JOptionPane.showMessageDialog(null, jawaban);
                    System.out.println(data);
                    if (data == 1) {
                        JOptionPane.showMessageDialog(null, "Terima Kasih Atas Kejujuran Anda."
                                + "\n"
                                + "\nAngka yang Anda pikirkan adalah "
                                + "\nAngka " + step7 + "."
                                + "\n"
                                + "\nJika Anda menyukai aplikasi ini,"
                                + "\nDon't forget to LIKE this post or SHARE it !!"
                                + "\nPresented by :"
                                + "\nerfan2040.blogspot.com (c) 2012");
                    } else if (data == 0) {
                        JOptionPane.showMessageDialog(null, "Belajarlah Jujur pada diri sendiri."
                                + "\n"
                                + "\nJika Anda Jujur,"
                                + "\nMaka Angka yang Anda pikirkan seharusnya adalah "
                                + "\nAngka " + step7 + "."
                                + "\n"
                                + "\nJika Anda menyukai aplikasi ini,"
                                + "\nDon't forget to LIKE this post or SHARE it !!"
                                + "\nPresented by :"
                                + "\nerfan2040.blogspot.com (c) 2012");
                    }
                    System.out.println(step7);
                    tes = (opsi == ya) | (opsi == tdk);
                    break;
                } else {
                    JOptionPane.showMessageDialog(null, ulangi2);
                    tes = (opsi != ya) | (opsi != tdk);
                }
            } while (tes);

        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, warning);
        }
    }
}

Semoga Bermanfaat.
Saran & kritik membangun ditunggu . . .

3 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Asalammualaikum Pak Erfan, saya Lia yang tadi pagi menghubungi bapak lewat Facebook, ini file screenshoot yang sudah saya upload, ada tanda seru merah di sebelah kiri kodingnya pak yang menandakan ada yang bermasalah.. ketika saya coba Run, sempat error juga pak. mohon bimbingannya... Terimakasih..

    Screenshoot 1:
    https://drive.google.com/open?id=1hrpWdMJK4X0-7Cob8baQO5tfNnrHd2Lk

    Screenshoot 2:
    https://drive.google.com/open?id=1gue6mvWt9lJvT9zmXKJ61iId5VCTT0s5

    ReplyDelete