still get these error messages: C:\Users\thorunn\Documents\NetBeansProjects\PhoneBook\src\TestPhoneBook.java:25: error: illegal start of expression public static void main(String[] args) { C:\Users\thorunn\Documents\NetBeansProjects\PhoneBook\src\TestPhoneBook.java:25: error: illegal start of expression public static void main(String[] args) { C:\Users\thorunn\Documents\NetBeansProjects
I still get these error messages:
C:\Users\thorunn\Documents\NetBeansProjects\PhoneBook\src\TestPhoneBook.java:25: error: illegal start of expression
public static void main(String[] args) {
C:\Users\thorunn\Documents\NetBeansProjects\PhoneBook\src\TestPhoneBook.java:25: error: illegal start of expression
public static void main(String[] args) {
C:\Users\thorunn\Documents\NetBeansProjects\PhoneBook\src\TestPhoneBook.java:25: error: ';' expected
public static void main(String[] args) {
C:\Users\thorunn\Documents\NetBeansProjects\PhoneBook\src\TestPhoneBook.java:25: error: '.class' expected
public static void main(String[] args) {
C:\Users\thorunn\Documents\NetBeansProjects\PhoneBook\src\TestPhoneBook.java:25: error: ';' expected
public static void main(String[] args) {
C:\Users\thorunn\Documents\NetBeansProjects\PhoneBook\src\TestPhoneBook.java:43: error: reached end of file while parsing
}
6 errors
After correction of TestPhoneBook
package PhoneBook;
import java.util.Scanner;
public class TestPhoneBook {
// lookupName method that return the target phone number
public static String lookupName(String targetName, PhoneBook anArray[])
{
String targetPhoneNumber="";
boolean result=false;
// checking the name with lookupName
for (int idx = 0; idx<anArray.length && !result; idx++)
{
if(anArray[idx].getName().equalsIgnoreCase(targetName))
{
targetPhoneNumber = anArray[idx].getPhoneNumber();
result=true;
}
}
// return targetPhoneNumber
return targetPhoneNumber;
}
public static void main(String[] args) {
Scanner kbd = new Scanner(System.in);
PhoneBook[]arrObj = new PhoneBook[3];
arrObj[0]= new PhoneBook("John Ficks", "657-9875");
arrObj[1]= new PhoneBook("Howard Williams", "908-1001");
arrObj[2]= new PhoneBook("George Clemens", "808-5001");
System.out.println("Enter name to look up");
String targetName = kbd.nextLine();
String targetPhone = lookupName(targetName, arrObj);
System.out.println("The phone number is "+targetPhone);
}
}

Step by step
Solved in 4 steps with 2 images









