Okay this should be simple. But I have been at this for a good hour and cannot figure out why its a nullpointerexception.
I need to create an array for "Sally" and then test its length, which should be 0. This is in the main method of the driver class.
LendingItem[] sallysItemList = sally.getSignedOutItems();
if (sallysItemList.length == 0)
and this is in the object class that created sally. that rotten B.
private LendingItem[] signedOutItems;
public LendingItem[] getSignedOutItems() {
return signedOutItems;
}
I feel like I need to maybe declare the Lending item as
private LendingItem[] signedOutItems = {};
but I still get errors with that also.
EDIT:
Im going to add more so that its more understandable what I need to make happen
Provided code below.
System.out.println("\n*** Test case #1: Create a CardHolder object & test accessors");
CardHolder sally = new CardHolder("Sally Smith",
152,
"454-1234");
System.out.println("Name: " + sally.getName()
+ "\nAppt #: " + sally.getAptNumber()
+ "\nPhone: " + sally.getPhoneNumber()
+ "\nMember #: " + sally.getMembershipNumber());
LendingItem[] sallysItemList = sally.getSignedOutItems();
if (sallysItemList.length == 0)
System.out.println("Correct result: Sally has zero lending items.");
else
System.out.println(">> ERROR: Sally has more than zero lending items.");
System.out.println("\n*** Test case #6: Sign out one LendingItem");
if(sally.signOut(testItemList[0]))
{ System.out.println("Correct result: Sally signed out an item successfully.");
sallysItemList = sally.getSignedOutItems();
if (sallysItemList.length == 1)
System.out.println("Correct result: Sally has one lending item.");
else
System.out.println(">> ERROR: Sally has other than one lending item.");
}
else
System.out.println(">> ERROR: Sally was unable to sign out an item.");
This is my code thus far. Just need to return the current signed out items.
public LendingItem[] getSignedOutItems() {
return signedOutItems;
}
This is how we are expected to add to our array, it needs to return a boolean
public boolean signOut(LendingItem lendingItem) {
if (signedOutItems.length < 7) {
signedOutItems[0] = lendingItem;
return true;
} else {
return false;
}
Dont need the outright code just an idea of how to actually accomplish this.