Selasa, 30 April 2013

program manipulasi buku tamu (add, update, remove, show all)

import java.io.*;
// program dibuat oleh Aji Hadi Prasetyo, Eko Rudi Suteja dan Muhammad Zaid Taufiq

public class BookAdd
{
    public static void main(String[] args) throws Exception
    {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String choice=null, jumlah=null, back=null, add=null;
        String[] name = new String[100];
        String[] address = new String[100];
        String[] phone = new String[100];
        String[] email = new String[100];
        int choicex, total=0, menu=0;
        EntryAdd newEntry = new EntryAdd();

        while (menu==0)
        {
        System.out.println();
        System.out.println(" _______________________________ ");
        System.out.println("|___________MAIN_MENU___________|");
        System.out.println("|_1._Add_Entry__________________|");
        System.out.println("|_2._Remove_Entry_______________|");
        System.out.println("|_3._Show_All_Entries___________|");
        System.out.println("|_4._Update_Entry_______________|");
        System.out.println("|______________END______________|");
        System.out.println();
        System.out.print("From the menu above, pick one number: ");
        choice = in.readLine();
        choicex = Integer.parseInt(choice);

        int x=choicex;
        switch (x)
        {
        case 1:
            System.out.print("Input number of entry you want to add: ");
            add = in.readLine();
            total = Integer.parseInt(add);
            for (int i=0; i<total; i++)
            {
                if (total>1)
                {
                    System.out.println("Input entry NO"+(i+1));
                }
                System.out.print("Name: ");
                name[i] = in.readLine();
                System.out.print("Address: ");
                address[i] = in.readLine();
                System.out.print("Phone number: ");
                phone[i] = in.readLine();
                System.out.print("E-mail: ");
                email[i] = in.readLine();
                newEntry.setEntry(name[i], address[i], phone[i], email[i], i);
                System.out.println();
                System.out.println(" _________________________________ ");
                System.out.println(" ____________ENTRY_NO"+(i+1)+"____________");
                System.out.println("  Name        :  "+newEntry.getName(i));
                System.out.println("  Address    :  "+newEntry.getAddress(i));
                System.out.println("  Phone        :  "+newEntry.getPhone(i));
                System.out.println("  E-mail    :  "+newEntry.getEmail(i));
                System.out.println(" _______________END_______________");
                System.out.println();
            }
            break;
       
        case 2:
            String del=null;
            int delx;
            if (total>0)
            {
                System.out.print("Which entry number will you delete? = ");
                del = in.readLine();
                delx = Integer.parseInt(del);
                name[(delx-1)] = "";
                address[(delx-1)] = "";
                phone[(delx-1)] = "";
                email[(delx-1)] = "";
                newEntry.setEntry(name[(delx-1)], address[(delx-1)], phone[(delx-1)], email[(delx-1)], (delx-1));
                System.out.println("Entry NO"+delx+" has been deleted.");
            }
            else System.out.println("You don't have any entries yet.");
            break;
       
        case 3:
            if (total > 0)
            {
                System.out.println("Showing all entries:");
                for (int j=0; j<total; j++)
                {
                    System.out.println();
                    System.out.println(" _________________________________ ");
                    System.out.println(" ____________ENTRY_NO"+(j+1)+"____________");
                    System.out.println("  Name        :  "+newEntry.getName(j));
                    System.out.println("  Address    :  "+newEntry.getAddress(j));
                    System.out.println("  Phone        :  "+newEntry.getPhone(j));
                    System.out.println("  E-mail    :  "+newEntry.getEmail(j));
                    System.out.println(" _______________END_______________");
                    System.out.println();
                }
            }
            else System.out.println("You don't have any entries yet.");
            break;

        case 4:
            String mod=null;
            int modx;
            if (total>0)
            {
            System.out.print("Which entry number will you modified? = " );
            mod = in.readLine();
            modx = Integer.parseInt(mod);
            System.out.println();
            System.out.println(" _________________________________ ");
            System.out.println(" ____________ENTRY_NO"+(modx)+"____________");
            System.out.println("  Name        :  "+newEntry.getName(modx-1));
            System.out.println("  Address    :  "+newEntry.getAddress(modx-1));
            System.out.println("  Phone        :  "+newEntry.getPhone(modx-1));
            System.out.println("  E-mail    :  "+newEntry.getEmail(modx-1));
            System.out.println(" _______________END_______________");
            System.out.println();
           
            System.out.println("Modifying entry NO"+modx+" now.");
            System.out.print("Name: ");
            name[(modx-1)] = in.readLine();
            System.out.print("Address: ");
            address[(modx-1)] = in.readLine();
            System.out.print("Phone number: ");
            phone[(modx-1)] = in.readLine();
            System.out.print("E-mail: ");
            email[(modx-1)] = in.readLine();
            newEntry.setEntry(name[(modx-1)], address[(modx-1)], phone[(modx-1)], email[(modx-1)], (modx-1));
            System.out.println("Showing the updated entry:");
            System.out.println();
            System.out.println(" _________________________________ ");
            System.out.println(" ____________ENTRY_NO"+(modx)+"____________");
            System.out.println("  Name        :  "+newEntry.getName((modx-1)));
            System.out.println("  Address    :  "+newEntry.getAddress((modx-1)));
            System.out.println("  Phone        :  "+newEntry.getPhone((modx-1)));
            System.out.println("  E-mail    :  "+newEntry.getEmail((modx-1)));
            System.out.println(" _______________END_______________");
            System.out.println();
            }
        }
        System.out.print("Return to main menu? (Y/N) = ");
        back = in.readLine();
        if ((back.equals("N")) || (back.equals("n")))
        {
            menu++;
        }
        else if ((back.equals("Y")) || (back.equals("y")))
        {
            System.out.println("Returning to main menu...");
        }
        }
    }
}