I have a class, PhoneBook ,that instantiates an array of PhoneEntry objects. In phonebook, my teacher wants me to alphabetize the names as they come in. For example, you enter Bobby, it goes into book[0], next you enter Annie, after you enter Annie, i need it check to see if it less than the last entered(Bobby), which it is, so then the elements in the array need to move down, and Annie is inserted at book[0], and Bobby is now at book[1], i have a lessThan method in PhoneEntry, that checks to see if it less. So in the insert method of class Phonebook, i'll say if(book[current].lessThan) then perform the operation to insert it alphabetically. Does that make sense... i can post the code i have if neccessary. Any help is greatly appreciated
2007-02-19
10:33:14
·
4 answers
·
asked by
Mike
1
in
Computers & Internet
➔ Programming & Design
public void insert(String name)//inserts a new entry into the phonebook, let's user know
//if phonebook is full, and also organizes data when entered
{
if(isFull())
System.out.println("The Phonebook is full!");
else if(!isFull())
{
book[count] = new PhoneEntry(name);
count++;
}
2007-02-19
10:34:25 ·
update #1
I haven't entered anything yet to utilize the lessThan method yet.
The above is in Phone Book....the following is in PhoneEntry...
public boolean lessThan(PhoneEntry other)//determines if name is less than another name
{
if((this.getName()).compareTo(other.getName()) < 0)
return true;
return false;
2007-02-19
10:36:32 ·
update #2