import java.util.*;
class AddressBook {
private static final int DEFAULT_SIZE = 25;
private Person[] entry; //getting error - cannot be resolved to a type
public AddressBook() {
this( DEFAULT_SIZE);
}
public AddressBook(int size) {
if (size <= 0) {
throw new IllegalArgumentException("Size must be positive");
}
entry = new Person[size]; // cannot be resolved to a type
System.out.println("array of " + size + " is created");
}
}
import java.util.Scanner;
class TestAddressBook {
public static void main(String args[]) {
AddressBook myBook;
String inputStr;
int size;
Scanner scanner = new Scanner(System.in);
while(true) {
System.out.print("array size: " );
inputStr = scanner.next();
if (inputStr.equalsIgnoreCase("stop")) {
break;
}
size = Integer.parseInt(inputStr);
try {
myBook = new AddressBook(size);
}
catch (IllegalArgumentException e) {
}
System.out.println("Exception thrown: size = " + size);
}
}
}
I can’t figure out what type I am supposed to use with the array to get everything to work properly.
private Person[] entry; //getting error – cannot be resolved to a type
….
entry = new Person[size]; // cannot be resolved to a type
Where is Person defined? at the very least, adding the following:
will allow it to compile. Otherwise, it doesn’t know what you mean when you create Person arrays.