NEED HELP WITH THIS QUESTION PROGRAMMING LANGUAGE : JAVA An alphabetically order
ID: 3843943 • Letter: N
Question
NEED HELP WITH THIS QUESTION
PROGRAMMING LANGUAGE : JAVA
An alphabetically ordered phone book application based on the use of a doubly linked list data structure will be developed. The application will also have a visual interface. n this context, we write Java code that meets the requirements detailed below. The name and surname of the persons and phone numbers are included in the guide. You can use a String variable of the form "namesurname" o represent the names and surnames of people. The person may have more than one phone number, so their phone numbers can be stored in an "ArrayList Define this information about people in a class named nfo n this way, in addition to the necessary bindings for the doubl nked n the node class of the list, a ariable st of type "Info" class will also be defined In your double linked list class, define 2 variables representing the list's head and ta In practice, the user should be offered the following options: 1) Reading from the text file named as below and guide.txt should be done in double linked list memory. (The data is separated by a com ma NOTE-1: The guide will be created in alphabetical order by name. When someone else by the same name comes in, they will be added in alphabetical order by surname. uide txt Alex Garrison, 0 533 1111111, 0 232 1111 111 Harry Kane, o 554 2222222, o 543 3333333, o 312 1111111 Jane Kubrick, 0216 444444Explanation / Answer
import java.util.ArrayList;
public class Phonebook implements Directory
{
private ArrayList<Person> book;
public Phonebook ()
{
book = new ArrayList<Person>();
}
public int size()
{
return book.size();
}
/** * will display the entries currently entered in the <code>Directory</code>. **/
public void listAll()
{
for(int i = 0; i < book.size(); i++)
{
System.out.println(book.get(i));
}
}
/** * will add a new record to the <code>Directory</code> in alphabetical order **/
public boolean addPerson(String name, String number)
{
Person x = new Person (name, number);
if (checkPerson(name) == -1)
return false;
int index = 0;
while(index < book.size())
{
if((x.getName().compareTo((book.get(index)).getName())) < 0)
{
book.add(x);
return true;
}
index++;
}
return false;
}
public int checkPerson(String name)
{
int lo = 0;
int hi = book.size() - 1;
while(lo <= hi)
{
int half = (lo + hi) / 2;
if(name.equals(book.get(half).getName()))
return half;
if(name.compareTo(book.get(half).getName()) < 0){
hi = half - 1;}
else lo = half + 1;
}
return -1;
}
/**
* will remove an entry from the <code>Directory</code> if the name parameter **/
public boolean removePerson(String name)
{
if (checkPerson(name) == -1)
return false;
book.remove(checkPerson(name));
return true;
}
/** * will search the <code>Directory</code> to find out if the name passed in **/
public String lookUp(String name)
{
Person n = new Person (name, "999-9999");
int local = checkPerson(n.getName());
if(local == -1)
return null;
return book.get(local).getNumber();
}
public String lookUpNum(String number)
{
for(int i = 0; i <book.size(); i++)
{
if(number.equals(book.get(i).getNumber()))
return book.get(i).getName();
}
return null;
}
}
public class Person implements Comparable<Person>
{
private String first;
private String last;
private String name; // Last, First
private String number;
public Person(String na, String nu)
{
convert(na);
number = nu;
}
public Person(Person per)
{
first = per.first;
last = per.last;
name = per.name;
number = per.number;
}
public String getName()
{
return name;
}
public String getNumber()
{
return number;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.