Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 12 of 12

Thread: Java phone book with array PLEASE HELP

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java phone book with array PLEASE HELP

    Here is my code. i have to creat a phone book in whcih you can add entries. find them. list all entries. and quit. the entries are to be put in an array as a class. Please tell me whats wrong with it and how i can search for a name and then pull the number and notes that go with that name and return it to the user. please and thank you! The code compiles fine but when i try to excecute the find option it errors. also i dont know how i would go about listing all the entries in the phone book. and im not even sure if they way i did the add an entry part works properly. it seems to when excecuting it in the program but i dont know if it actually stores it in the array or not.

    import java.io.IOException;
    import java.util.*;
    public class phonebook {
     
     
     
     
    	public static void main(String [] args) throws IOException{
     
     
    		int counter = 0;
    		String name, number, notes;
    		char firstcommand;
     
     
     
    		System.out.print("Codes or names are entered with 1 to 8 characters. Use e to make a new entry, f to find an entry, l to list all current entries, and q to quit.");
     
    		Scanner input = new Scanner(System.in);
     
    		System.out.print("Please chose an option:  ");
     
    			firstcommand = (char)System.in.read();
     
    			while (firstcommand != 'q'){
    				System.out.print("Please chose an option:  ");
    				firstcommand = (char)System.in.read();
    				if (firstcommand == 'e') {
    					 System.out.print("Enter the code or name: ");
    					 name = input.next();
    					 System.out.print("Enter number: ");
    					 number =input.next();
    					 System.out.print("Enter any notes or press space then enter to leave blank:  ");
    					 notes = input.next(); 
     
    					while (counter <100){ Entry entryList = new Entry();
    					 	if (counter >= 100) {
    					 		System.out.print("phonebook is full");
    					 		break;
    					 	}
    					entryList.name = name;
    					 	entryList.notes = notes;
    					 	entryList.number = number;
    					 		counter ++;
    					}
    				}
     
     
    					else if (firstcommand == 'f') {
    				String find;
    				int index;
     
     
    				System.out.print("Please enter the name or code you wish to find");
    				find = input.next();
    				index = Arrays.binarySearch( Entry.entryList, find);   
    			System.out.print(index);
    					}
     
    			}
    	}
    }
     
    //here is my sperate class called Entry
     
    public class Entry {
     
     
    	public static Entry[] entryList = new Entry[100]; 
    	 public String name;
    	public  String number;
    	public  String notes;
     
    }
    Last edited by cardschaos; April 15th, 2012 at 06:36 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java phone book with array PLEASE HELP

    Please tell me whats wrong with it
    Can you explain what the problem with the program is? Does it compile ok? What happens when you execute it?
    If it needs code for some feature, describe what the steps the program should take to get the feature to work.

    Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java phone book with array PLEASE HELP

    there it should be updated

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java phone book with array PLEASE HELP

    What about the questions I asked?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java phone book with array PLEASE HELP

    the main problem i have right now is that i need to user to be able to put in the name part of a name number and notes entry, and have it return the number and notes that go with it. basicly like a search. this is done when the user gives the f command when asked to select an option. which is the part with the while loop.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java phone book with array PLEASE HELP

    main problem i have right now is that i need to user to be able to put in the name part of a name number and notes entry, and have it return the number and notes that go with it
    Can you be more specific on the problem?
    Which part is the problem:
    Read the name
    find the name
    return some data


    One problem: I don't see where you put Entry objects into the array hold the Entry objects: entryList

    The entryList array should not be in the Entry class.
    Last edited by Norm; April 15th, 2012 at 06:57 PM.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Apr 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java phone book with array PLEASE HELP

    i can read the name the user inputs, its the taking the inputed name and finding it in the array and then the reaturning the data in a system.out.print form that i dont get how to do

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java phone book with array PLEASE HELP

    Where do you add the Entry objects you create to the array?
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Apr 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java phone book with array PLEASE HELP

    this should be the adding part. but idk if thats right either.

     if (firstcommand == 'e') {
    					 System.out.print("Enter the code or name: ");
    					 name = input.next();
    					 System.out.print("Enter number: ");
    					 number =input.next();
    					 System.out.print("Enter any notes or press space then enter to leave blank:  ");
    					 notes = input.next(); 
     
    					while (counter <100){ Entry entryList = new Entry();
    					 	if (counter >= 100) {
    					 		System.out.print("phonebook is full");
    					 		break;
    					 	}
    					entryList.name = name;
    					 	entryList.notes = notes;
    					 	entryList.number = number;
    					 		counter ++;
    					}
    				}

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java phone book with array PLEASE HELP

    You put values into an array by assigning the value to a slot in the array at an index's location:
    theArray[theIndex] = theValue;

    I don't see where you do that.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Apr 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java phone book with array PLEASE HELP

    well the array values are the three variables name number and notes that are supposed to be entered by the user. its supposed to be a phone book

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java phone book with array PLEASE HELP

    Those are the values put into the Entry object you create. Then what do you do with that Entry object?
    You need to assign it to a slot in the array.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Java Error cannot be applied to (java.lang.String), phone book entry program.
    By iceyferrara in forum What's Wrong With My Code?
    Replies: 5
    Last Post: September 23rd, 2011, 06:32 AM
  2. phone book with linked list?
    By osloboy28 in forum Collections and Generics
    Replies: 5
    Last Post: September 7th, 2011, 11:28 AM
  3. phone book code problems
    By mu'min in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 16th, 2010, 11:36 AM
  4. phone book code problems
    By mu'min in forum Member Introductions
    Replies: 1
    Last Post: December 16th, 2010, 09:07 AM
  5. phone book
    By Skat in forum What's Wrong With My Code?
    Replies: 14
    Last Post: December 3rd, 2010, 09:56 AM