Question: Hello, I'm preparing for my final exam and this question was part of the book and I simply am a little confused as to how
Hello,
I'm preparing for my final exam and this question was part of the book and I simply am a little confused as to how I should approach it. It seems to me that there is missing info, but I believe it's designed that way. Is it possible to answer this question? I genuinely just dont understand, completing it and adding comments to the code would be greatly appreciated! I wouldn't usually ask to complete it but I am sincerely confused. I tried back tracking but my end result was not running as intended unfortunately. I wrote out the skeletons below.
public class PhoneBook {
//firstAvailableIndex keeps track of indexes used,
//as there might be less data than max array size.
int firstAvailableIndex;
String owner;
String[] contacts;
//Q.25 constructor no-arg
public static void main (String[] args) {
}
public PhoneBook(String owner, int size) {
//Q.24, complete
}
//Q.26, copy constructor
//Q.27, setter and getter
public boolean addContact(String name, long cell) {
//Q.28, complete
return false;
}
public String getPhoneBookDetails() {
return owner;
}
}
public class PhoneBookTest {
private static final int COUNT=2;
private static final String[] NAMES =
{"Jack", "Jill", "Joe", "Jacob", "Janet"};
private static final int [] NUMBERS =
{111, 222, 333, 444, 555};
public static void main (String[] args) {
PhoneBook book = new PhoneBook("John", COUNT);
//Q.30 complete body of loop
for ( int i=0; 1<=COUNT; i++) {
book.addContact(NAMES[i], NUMBERS[i]);
}
//Q.31 print book
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
