Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem of Logic in Addressbook, should have no blank entries or same entry... Please Help
    text
    copied!<p>hope you can help me coding.</p> <p>What i need to do: 1.) I should not allow user to have a blank entry.. I should prompt them like "No name inputted!" 2.) I should not allow user to input same entry..</p> <p>I have no Idea how to code i, please help.</p> <p>Here's my complete code:</p> <p>public class AddressBook {</p> <pre><code>private AddressBookEntry entry[]; private int counter; private String SName; private int notfound=0; public static void main(String[] args) { AddressBook a = new AddressBook(); a.entry = new AddressBookEntry[100]; int option = 0; while (option != 5) { String content = "Choose an Option\n\n" + "[1] Add an Entry\n" + "[2] Delete an Entry\n" + "[3] Update an Entry\n" + "[4] View all Entries\n" + "[5] View Specific Entry\n" + "[6] Exit"; option = Integer.parseInt(JOptionPane.showInputDialog(content)); switch (option) { case 1: a.addEntry(); break; case 2: a.deleteEntry(); break; case 3: a.editEntry(); break; case 4: a.viewAll(); break; case 5: a.searchEntry(); break; case 6: System.exit(1); break; default: JOptionPane.showMessageDialog(null, "Invalid Choice!"); } } } public void addEntry() { entry[counter] = new AddressBookEntry(); entry[counter].setName(JOptionPane.showInputDialog("Enter name: ")); entry[counter].setAdd(JOptionPane.showInputDialog("Enter add: ")); entry[counter].setPhoneNo(JOptionPane.showInputDialog("Enter Phone No.: ")); entry[counter].setEmail(JOptionPane.showInputDialog("Enter E-mail: ")); counter++; } public void viewAll() { String addText = " NAME\tADDRESS\tPHONE NO.\tE-MAIL ADD\n\n"; int nonNull = 0; for (int i = 0; i &lt; entry.length; i++) { if (entry[i] != null) { addText = addText + entry[i].getInfo() + "\n"; nonNull++; } if (nonNull == counter) { break; } } JOptionPane.showMessageDialog(null, new JTextArea(addText)); } public void searchEntry() { SName = JOptionPane.showInputDialog("Enter Name to find: "); searchMethod(); } public void searchMethod() { for (int i = 0; i &lt; counter; i++) { if (entry[i].getName().equals(SName)) { JOptionPane.showMessageDialog(null, entry[i].getInfo2()); notfound = 0; break; } else { notfound++; } } if (notfound != 0) { JOptionPane.showMessageDialog(null, "Name Not Found!"); } } public void editEntry() { int notfound = 0; SName = JOptionPane.showInputDialog("Enter Name to edit: "); for (int i = 0; i &lt; counter; i++) { if (entry[i].getName().equals(SName)) { entry[i] = new AddressBookEntry(); entry[i].setName(JOptionPane.showInputDialog("Enter new name: ")); entry[i].setAdd(JOptionPane.showInputDialog("Enter new add: ")); entry[i].setPhoneNo(JOptionPane.showInputDialog("Enter new Phone No.: ")); entry[i].setEmail(JOptionPane.showInputDialog("Enter new E-mail: ")); notfound = 0; break; } else { notfound++; } } if (notfound != 0) { JOptionPane.showMessageDialog(null, "Name Not Found!"); } } public void deleteEntry() { SName = JOptionPane.showInputDialog("Enter Name to delete: "); for (int i = 0; i &lt; counter; i++) { if (entry[i].getName().equals(SName)) { JOptionPane.showMessageDialog(null, "Found!"); entry[i] = null; break; } } } </code></pre> <p>}</p> <p>What happen to my code was it allows user to click "OK" even he doesn't enter any character yet.. and it also allows identical entry...</p> <p>Hope you can help me... i need it very soon and yet i still have no Idea what to add in my code... please help thanks a lot..</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload