PhoneBook

Posted on Updated on

1. Class Utama
import java.io.*;
public class Utama
{
public static void main (String[]args) throws Exception
{
Phonebook [] p=new Phonebook[10];
int Pilihan;
int counterm=0;
String nama,alamat,notelp;
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//Phonebook kontak = new Phonebook();
do
{
System.out.println(“==================”);
System.out.println(”    Phone Book      “);
System.out.println(“==================”);
System.out.println(“1. TAMBAH KONTAK”);
System.out.println(“2. CARI KONTAK”);
System.out.println(“3. HAPUS KONTAK”);
System.out.println(“4. LIHAT SEMUA KONTAK”);
System.out.println(“5. KELUAR”);
System.out.print(“Masukkan Pilihan Anda    :”);
Pilihan = Integer.parseInt(in.readLine());
switch (Pilihan)
{
          case 1:
{
System.out.print(“Nama :”);
nama=in.readLine();
//kontak.setNama(in.readLine());
System.out.print(“Alamat :”);
alamat=in.readLine();
//kontak.setAlamat(in.readLine());
System.out.print(“No Telp :”);
notelp=in.readLine();
//kontak.setTelp(in.readLine());
p[counterm] = new Phonebook (nama,alamat,notelp);

counterm+=1;
}
break;
case 2:
{

}
break;
case 3:
{

}
break;
case 4:
{
for (int i=0; i<=counterm-1;i++)
{
System.out.println(p[i].displayinfo());
System.out.println();
}
}
}

}
while (Pilihan != 5);
}

}

2. Class PhoneBook
//—————————
// Super Kelas Phonebook
//—————————
class Phonebook
{
//atribut
private String nama=””;
private String alamat=””;
private String notelp=””;

//metode-constructor
public Phonebook (String nm,String al,String tlp)
{
nama=nm;
alamat=al;
notelp=tlp;
}

//modifier
public void setNama(String nm)
{
this.nama=nm;
}

public void setAlamat(String al)
{
this.alamat=al;
}

public void setTelp(String tlp)
{
this.notelp=tlp;
}

//accessor
public String getNama()
{
return nama;
}

public String getAlamat()
{
return alamat;
}

public String getTelp()
{
return notelp;
}
public String displayinfo()
{
return(“Nama :”+nama+”\nAlamat :”+alamat+”\nNO Telp :”+notelp);
}
}

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s