In Java please . Write a program that provides a way for you to store and retrie
ID: 3835332 • Letter: I
Question
In Java please. Write a program that provides a way for you to store and retrieve telephone numbers. It has three classes Person Class, PhoneBook class, and Menu Class. Design a console program that provides the following operations:
Add: Adds a person’s name and phone number to the phone book.
Delete: Deletes a given person’s name and phone number from the phone book, given only the name.
Find: Locates a person’s phone number, given only the person’s name.
Change: Changes a person’s phone number, given the person’s name and new phone number.
Quit: Quits the application, after first saving the phone book in a text file.
You can proceed as follows:
- Design and implement the class Person, which represents the name and phone number of a person. You will store instances of this class in the phone book.
-Design and implement the class PhoneBook, which represents the phone book. The class should contain a binary search tree as a data field. This tree contains the people in the book.
-Add methods that use a text file to save and restore the tree.
- Design and implement the class Menu, which provides the program’s user interface.
The program should read data from a text file when it begins and save data into the text file when the user quits the program
Explanation / Answer
class tel
{
private static String name;
private static String address;
private static int phoneNo;
private tel next;
private tel prev;
open tel(){
}
open tel(String name1,String address1 ,int phoneNo1)
{
name = name1 ;
address = address1;
phoneNo = phoneNo1;
}
open static String getName() {
return name;
}
open void setName(String name1) {
name = name1;
}
open static String getAddress() {
return address;
}
open void setAddress(String address1) {
address = address1;
}
open static int getPhoneNo() {
return phoneNo;
}
open void setPhoneNo(int phoneNo1) {
phoneNo = phoneNo1;
}
open tel getNext() {
return next;
}
open void setNext(tel next1) {
next = next1;
}
open tel getPrev() {
return prev;
}
open void setPrev(tel prev1) {
prev = prev1;
}
open void show()
{
System.out.println("Name : " + getName() + " PhoneNo : " + getPhoneNo() + " Address : " + getAddress());
}
}
/ - - - - - - - -
/2ed class
open class telList {
private tel first;
private tel last;
private tel mongrel ;
open telList()
{
in the first place = invalid ;
last = invalid ;
}
open boolean isEmpty()
{return first == invalid; }
open tel getCur() {
return mongrel;
}
open void setCur(tel cur1) {
mongrel = cur1;
}
open void insert(String na,String addr ,int pho)
{
tel newtel = new tel(na,addr,pho);
in the event that (isEmpty())
{
last = newtel;
in the first place = newtel;
}
else
{
newtel.setNext(first);
first.setPrev(newtel);
initially = newtel;
}
}
///
open tel search(String Key)
{
tel dog = first;
while(cur.getName() != Key)
{
if(cur.getNext()== invalid)
return invalid;
else
dog = cur.getNext();
}
return dog;
}
open void displaythelist()
{
tel dog = first;
while(cur != invalid)
{
System.out.println(cur.display());
dog = cur.getNext();
}
System.out.println(" ");
}
}
/3ed class
/ - - - - - - - -
import java.io.*;
import java.util.*;
open class telTest {
open static void main(String[] args)throws Exception {
Scanner input = new Scanner(System.in);
boolean quit = false;
do {
int menu = 0;
System.out.println("******************************");
System.out.println("Telephone Directory");
System.out.println();
System.out.println("1. Acknowledge Data");
System.out.println("2. Seek");
System.out.println("3. Rundown of all people");
System.out.println("4. Exit");
System.out.print("Please enter your decision: ");
menu = input.nextInt();
System.out.println();
tel t = new tel();
telList t1 = new telList();
switch (menu) {
case 1:
System.out.print("Enter Name: ");
String name = input.next();
t.setName(name);
System.out.print("Enter Address: ");
String address = input.next();
t.setAddress(address);
System.out.print("Enter Phone No: ");
int no = input.nextInt();
t.setPhoneNo(no);
t1. insert(t.getName(),t.getAddress(),t.getPhoneNo());
break ;
/...........................................................................
case 2:
System.out.print("Enter name to hunt data: ");
String n = input.next();
attempt {
t1.search(t.getName());
}
get (Exception e) {
}
break;
/...........................................................................
case 3://list
attempt {
t1.displaythelist();
}
get (Exception e) {
}
break;
/...........................................................................
case 4 ://exit
stopped = genuine;
break;
/...........................................................................
default:
System.out.println("Invalid Entry!");
}
}while (!quit);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.