vquad
Banned
- Messages
- 2,644
- Joined
- Jan 25, 2010
- Messages
- 2,644
- Reaction score
- 39
- Points
- 30
Salam semua..saya nak mintak tolong otai2 sume bg tips psal java program yg saya buat nie.. pening dok pikir algorithm die..xkena jek
Write a Java application for a personal phone directory which contains first names and phone numbers for 30
people. Assign names and phone numbers for the first 3 people (use your own data). Prompt the user for a name,
and if the name is found in the list, display the corresponding phone number. If the name is not found in the list,
prompt the user for a phone number, and add the new name and phone number to the list. Continue to prompt the
user for names until the user enters “quit”. After the arrays are full (containing 30 names), do not allow the user to
add new entries.
Class phone
public class Phone{
private String name;
private int pNo;
public Phone(String name,int pNo){
this.name=name;
this.pNo=pNo;
**
public String getname(){
return name;
**
public int pNo(){
return pNo;
**
public void setName(){
this.name=name;
**
public void setPNo(){
this.pNo=pNo;
**
**
Class testPhone
import static javax.swing.JOptionPane.*;
public class TestPhoneBook{
public static void main(String []args){
String name;
int pNo;
int lastCount=3;
int count=0;
String ans;
Phone[] phone= new Phone[30];
phone[0]=new Phone("rashid",0324);
phone[1]=new Phone("azian",330);
phone[2]=new Phone("aziani",340);
do {
name=showInputDialog("Enter name : ");
//pNo=Integer.parseInt(showInputDialog("Enter Phone number :"));
if(name.equals(phone[count])){
showMessageDialog(null,"The name you entered is on the list.\nThe name and phone number is: "+phone[count]);
**
else{
showMessageDialog(null,"The name you entered is not in the system!!!\nPlease key in name and phone number");
name=showInputDialog("Enter name : ");
pNo=Integer.parseInt(showInputDialog("Enter Phone number :"));
phone[count]=new Phone(name,pNo);
**
ans = showInputDialog("Do you want continue? yes/no");
count++;
**while(count<30 || ans.equalsIgnoreCase("yes"));
System.out.println("Sorry you have entered the maximum amount of contact!!!\nThank you for using this PHONEBOOK!!! goodbye");
**
**
Write a Java application for a personal phone directory which contains first names and phone numbers for 30
people. Assign names and phone numbers for the first 3 people (use your own data). Prompt the user for a name,
and if the name is found in the list, display the corresponding phone number. If the name is not found in the list,
prompt the user for a phone number, and add the new name and phone number to the list. Continue to prompt the
user for names until the user enters “quit”. After the arrays are full (containing 30 names), do not allow the user to
add new entries.
Class phone
public class Phone{
private String name;
private int pNo;
public Phone(String name,int pNo){
this.name=name;
this.pNo=pNo;
**
public String getname(){
return name;
**
public int pNo(){
return pNo;
**
public void setName(){
this.name=name;
**
public void setPNo(){
this.pNo=pNo;
**
**
Class testPhone
import static javax.swing.JOptionPane.*;
public class TestPhoneBook{
public static void main(String []args){
String name;
int pNo;
int lastCount=3;
int count=0;
String ans;
Phone[] phone= new Phone[30];
phone[0]=new Phone("rashid",0324);
phone[1]=new Phone("azian",330);
phone[2]=new Phone("aziani",340);
do {
name=showInputDialog("Enter name : ");
//pNo=Integer.parseInt(showInputDialog("Enter Phone number :"));
if(name.equals(phone[count])){
showMessageDialog(null,"The name you entered is on the list.\nThe name and phone number is: "+phone[count]);
**
else{
showMessageDialog(null,"The name you entered is not in the system!!!\nPlease key in name and phone number");
name=showInputDialog("Enter name : ");
pNo=Integer.parseInt(showInputDialog("Enter Phone number :"));
phone[count]=new Phone(name,pNo);
**
ans = showInputDialog("Do you want continue? yes/no");
count++;
**while(count<30 || ans.equalsIgnoreCase("yes"));
System.out.println("Sorry you have entered the maximum amount of contact!!!\nThank you for using this PHONEBOOK!!! goodbye");
**
**
Last edited: