astrojunk 0 Newbie Poster

Hi. I'm working on an address book (JDK) which prompts the user to enter 1 if he wants to add an entry, 2 if he wants to search for a name, or 3 if he wants to quit. I'm done with the 'add entry' and exit parts but I couldn't make the searching work. Pls help me.. Here's the code..

import java.util.Scanner;

public class AddressBook
{
	public static void main(String[] args)
	{
	
	Scanner in=new Scanner(System.in);
	char choice;
	String col1="NAME";
	String col2="ADDRESS";
	boolean exit=false;
	String names[]=new String[50];
	String addresses[]=new String[50];
	int ctr=0;
	
	
	while(exit==false)
	{
		System.out.println("[1]Add Entry");
                System.out.println("[2]Search");
		String s=in.nextLine();
		choice=s.charAt(0);
		
		switch(choice)
		{
		case 1:
		System.out.println("Enter Name: ");
		names[ctr] = in.nextLine();
		System.out.println("Enter Address: ");
		addresses[ctr] = in.nextLine();
  		ctr++;
		break;

		case 2:
		boolean found=false;
		System.out.print("\n\tEnter name to search: ");
		String namesearch=in.nextLine();
		int i=0;
		while(i<ctr && !found)
		{
		if(namearray[i]==namesearch)
		{
		found=true;
		}
		i++;
		}
		if(found)
		{
		System.out.print(namesearch+" is at index "+i);
		}
		else
		{
		System.out.print("Not found");
		}
		
		break;
                
                case 3:
              	exit=true;
                
		break; 

		default:
		System.out.println("Incorrect input!");
                
	}	
	}
}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.