Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.21 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class phonebook
  4. {
  5.  
  6.     static String [] notelf;
  7.     static String [] user;
  8.  
  9.     public static void main(String[]args)
  10.     {
  11.         Scanner scan = new Scanner(System.in);
  12.         int jmlhdata=0, choice = 0;
  13.  
  14.         do
  15.         {
  16.             System.out.println("e-Phonebook");
  17.             System.out.println("===========");
  18.             System.out.println("1. Input Phonebook Data");
  19.             System.out.println("2. Tampilkan Isi Phonebook");
  20.             System.out.println("3. Exit");
  21.             System.out.print("Input Menu : ");
  22.             do
  23.             {
  24.                 try
  25.                 {
  26.                     choice = scan.nextInt();
  27.                     scan.nextLine();
  28.                 }
  29.                 catch(Exception e)
  30.                 {
  31.                     scan.nextLine();
  32.                     System.out.println("Input Yang Kamu Masukan Salah");
  33.                 }
  34.             }
  35.             while(choice <1 || choice >3);
  36.             switch(choice)
  37.             {
  38.                 case 1:
  39.                 if(jmlhdata == 0)
  40.                 {
  41.                     System.out.println("");
  42.                     System.out.println("Tentukan Jumlah Data Yang Akan Di Input!");
  43.                     System.out.print("Jumlah Data : ");
  44.                     try
  45.                     {
  46.                         jmlhdata = scan.nextInt();
  47.                         scan.nextLine();
  48.                     }
  49.                     catch(Exception e)
  50.                     {
  51.                         scan.nextLine();
  52.                         System.out.println("Hanya Angka Yang Diperbolehkan!");
  53.                     }
  54.                 }
  55.  
  56.                 notelf = new String[jmlhdata];
  57.                 user = new String[jmlhdata];
  58.  
  59.                 String phonebook;
  60.                 for(int i = 0;i<notelf.length;i++)
  61.                 {
  62.                     System.out.println("");
  63.                     System.out.print("Input Data [Nama # Nomor Telfon] : ");
  64.                     phonebook = scan.nextLine();
  65.                     if(!phonebook.contains("#"))
  66.                     {
  67.                         System.out.println("Format Phonebook Salah!");
  68.                         i--;
  69.                     }
  70.                     else
  71.                     {
  72.                         String[] book = phonebook.split("#");
  73.                         user[i] = book[0];
  74.                         notelf[i] = book[1];
  75.                     }
  76.                     System.out.println("");
  77.                 }
  78.                 System.out.println("Data Phonebook Telah Di Input");
  79.                 System.out.println("");
  80.                     break;
  81.  
  82.                 case 2:
  83.  
  84.                 if(jmlhdata ==0)
  85.                 {
  86.                     System.out.println("Data Tidak Ada!");
  87.                 }
  88.                 else
  89.                 {
  90.                     for (int i = 0; i < jmlhdata;i ++)
  91.                     {
  92.                         System.out.println("");
  93.                         System.out.println("No : " +(i+1));
  94.                         System.out.println("Nama : " +user[i]);
  95.                         System.out.println("No Telfon : " +notelf[i]);
  96.                         System.out.println("");
  97.                     }
  98.                 }
  99.                 case 3:
  100.                 break;
  101.             }
  102.         }while(choice !=3);
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement