help with this java program?

Posted Thursday, February 18, 2010 by admin


we’ve been asked to do an address book program that could view all the inputted entries as well as add,update, and delete an entry….

i’m done with adding and updating entries…
but i’m having trouble with displaying all entries and deleting an entry

help please??
here’s what i’ve done so far:

import java.io.*;

public class AddressBook {
private int top = 0;
private static final int MAXENTRIES = 100;
private AddressBookEntry [] list;

public static void main(String[] args) {
BufferedReader keyIn = new BufferedReader (new InputStreamReader(System.in));
AddressBook addBook = new AddressBook();
String act = “”;
while (true){
System.out.println (“\n[A] Add entry”);
System.out.println (“[D] Delete entry”);
System.out.println (“[V] View all entries”);
System.out.println (“[U] Update entry”);
System.out.println (“[Q] Quit”);
System.out.println (“Enter desired action: “);

try{
act = keyIn.readLine();
} catch (Exception e){
System.out.println (“Error”);
}

if (act.equals(“A”)||act.equals (“a”))
addBook.addEntry();
else if (act.equals(“V”)||act.equals (“v”))
addBook.viewEntries();
else if (act.equals(“D”)||act.equals (“d”))
addBook.deleteEntry();
else if (act.equals(“U”)||act.equals (“u”))
addBook.updateEntry();
else if (act.equals(“Q”)||act.equals (“q”))
System.exit (0);
else
System.out.println (“Unknown command”);
}
}

public AddressBook() {
list = new AddressBookEntry [MAXENTRIES];
}

public void addEntry(){
BufferedReader keyIn = new BufferedReader (new InputStreamReader (System.in));
String name = “”;
String add = “”;
int tel = 0;
String email = “”;

if (top == MAXENTRIES){
System.out.println (“Address Book is full”);
return;

}

try{
System.out.print (“Name: “);
name = keyIn.readLine();
System.out.print (“Address: “);
add = keyIn.readLine ();
System.out.print (“Telephone number: “);
tel = Integer.parseInt (keyIn.readLine());
System.out.print (“Email Address: “);
email = keyIn.readLine ();
} catch (Exception e){
System.out.println (e);
System.exit (0);
}
AddressBookEntry entry = new AddressBookEntry (name, add, tel, email);
list [top] = entry;
top++;

}
public void updateEntry (){
BufferedReader keyIn = new BufferedReader (new InputStreamReader(System.in));
int index = 0;
String name = “”;
String add = “”;
int tel = 0;
String email = “”;

try {
System.out.print (“Entry number: “);
index = Integer.parseInt (keyIn.readLine ())-1;
System.out.print (“Name: “);
name = keyIn.readLine ();
System.out.print(“Address: “);
add = keyIn.readLine ();
System.out.print(“Telephone number: “);
tel = Integer.parseInt(keyIn.readLine());
System.out.print(“Email Address: “);
email = keyIn.readLine ();
} catch (Exception e){
System.out.println (e);
System.exit (0);

}
AddressBookEntry entry = new AddressBookEntry (name, add, tel, email);
list [index] = entry;

}

}

}

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • Ask

1 Comment on "help with this java program?"

  • Asker said on Feb 18th, 2010 at 4:41 AM:

    public void displayEntry (){
    for(int i=0;i

Leave a Comment

Copyright © 2012 Ebook program
Design by ID Themes