Here is my code at the moment:
import java.util.Scanner;
class menuOperations
{
String[] fNames = new String[50];
String[] lNames = new String[50];
String fName = " ";
String lName = " ";
String sFName = " ";
String sLName = " ";
int dAmount,dTimes,i;
Scanner in = new Scanner(System.in);
public void newEntry()
{
if (fName == " ")
{
int i = 0;
}
if (i == 50)
{
System.out.println("Sorry, your address book is full. You can only store 50 entires per book.");
}
else
{
System.out.println("Please enter the first name of the person:");
fName = in.nextLine();
fNames[i] = fName;
if (fNames[i] != fName)
{
System.out.println("There was a probelm entering the name.");
}
else
{
System.out.println("The name was entered successfully.");
i += 1;
}
}
} //End newEntry
public void search()
{
System.out.println("Please enter the name you wish to search for, first or last name ONLY");
sFName = in.nextLine();
System.out.println(sFName);
for (int j = 0; j < fNames.length; j++)
{
if (fNames[j] == sFName)
{
System.out.println(fNames[j]);
}
}
} //End search
}
public class it215_w2_addressbook
{
public static void main(String[] args)
{
//String fName,lName;
//int dAmount,dTimes;
int uChoice;
boolean quit = false;
Scanner in = new Scanner(System.in);
menuOperations mO = new menuOperations();
System.out.println("Welcome to your Electronic Address Book, or EAB.");
while (!quit)
{
System.out.println("Please choose an option from the following menu:");
System.out.println("1) New Entry");
System.out.println("2) Search");
System.out.println("3) Display All");
System.out.println("4) Load Address Book");
System.out.println("5) Quit Program and Save Address Book");
System.out.printf(">");
uChoice = in.nextInt();
switch (uChoice)
{
case 2:
{
mO.search();
break;
}
case 5:
{
quit = true;
break;
}
default:
{
mO.newEntry();
break;
}
}
}
}
}
So, now my main problem is in the search method. At the for loop at the end the code should take the entered name, which I have verified is saved correctly via the system.out line, and then search the array for matching names and print them.
When I run the program, however, it does now print out these array elements. So far, everything I have found on google states that the print command used should work.
working in:
java version "1.6.0_23"
Java(TM) SE Runtime Environment (build 1.6.0_23-b05)
Java HotSpot(TM) Client VM (build 19.0-b09, mixed mode, sharing)