// Arup Guha
// 2/19/2026
// Edited old Address Book to use Scanner and not crash if the book is full.

import java.util.*;

public class AddressBook {

    private Contact[] friends; // An array of Contacts - each stores info for one friend
    private int numfriends; // Number of friends currently in AddressBook

    // Create an empty AddressBook
    public AddressBook() {
		friends = new Contact[10];
		numfriends = 0;
    }
	
	// Returns true iff we can add a friend.
	public boolean canAdd() {
		return numfriends < 10;
	}

    // Add a contact that's passed in as a parameter.
    public boolean addContact(Contact c) {
		
		// Can't do it.
		if (!canAdd()) return false;
		
		// Add the friend.
		friends[numfriends] = c;
		numfriends++;
		return true;
    }

    // Returns a String represetation of this AddressBook.
    public String toString() {
		String res = "";
		for (int i=0;i<numfriends;i++)
	    	res = res + friends[i] + "\n";
		return res;
    }

    // Returns the number of friends currently in AddressBook
    public int numContacts() {
		return numfriends;
    }

    // Returns a non-neg integer if a Contact with name s exists corresponding
    // to which place in the array friends the Contact is stored. Returns -1
    // otherwise.
    private int haveContact(String s) {
		for (int i=0;i<numfriends;i++)
	    	if (friends[i].getName().equals(s))
				return i;
		return -1;
    }

    // Deletes a contact with name s, if one is in the AddressBook.
	// Returns true if delete successful, false if person wasn't in the book 
	// to begin with.
    public boolean deleteContact(String s) {
		
		// See where this person is.
		int place = haveContact(s);
		
		// Not found.
		if (place < 0) return false;
	    	
		// Remove them by copying the last friend to this slot.
		friends[place] = friends[numfriends-1];
	    numfriends--;
		
		// We did it.
		return true;
    }
}
