You have to make a new menu which show first menu like that 1.Enter 1 for using Doubly linkedList 2.Enter 2 for using arrayList

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Course:Data Structure and Algorithms

I am providing the two menu base programs in java for address book by using doubly LinkedList and arrayList separate codes i am proving in question:

You have to make a new menu which show first menu like that

1.Enter 1 for using Doubly linkedList

2.Enter 2 for using arrayList

 

AddressBook by using doubly LinkedList Code Are:

//Person.java

public class Person

{
    private String name;         
    private String address;      
    private long phoneNumber;  
  public Person(String name, String address, long phoneNumber){
       
        this.name=name;
        this.address=address;
        this.phoneNumber=phoneNumber;
    }
public String getName(){
        return this.name;
    }
public String getAddress(){
        return this.address;
    }
  public long getPhoneNumber()

{
        return this.phoneNumber;
    }
public String toString(){
        return "Name: "+this.name+" Address: "+this.address+" Phone Number: "+this.phoneNumber;    
    }
}

//Main.java

import java.util.List;
import java.util.LinkedList;
import java.util.Scanner;

public class Main

{
 public static void main(String[] args)

{
List<Person> AddressBook=new LinkedList<Person>(); 
  
  Scanner sc=new Scanner(System.in);         

  System.out.println("1.Add");
  System.out.println("2.Delete");
  System.out.println("3.Search");
  System.out.println("4.Exit");
  
  while(true)

{  
      System.out.print("Enter the choice: ");     
      int choice=Integer.parseInt(sc.nextLine());     
      
      if(choice==1)

{      
          System.out.print("Enter Name: ");
          String name=sc.nextLine();              
          System.out.print("Enter Address: ");
          String address=sc.nextLine();          
          System.out.print("Enter Phone Number: ");
          long phoneNumber=Long.parseLong(sc.nextLine());    
          Person p=new Person(name,address,phoneNumber);     
          AddressBook.add(p);                                 
          System.out.println("Person added succesfully");     
      }
      
      else if(choice==2)

{    
          System.out.print("Enter Name: ");
          String inputName=sc.nextLine();     
          for(Person p:AddressBook)

{         

              if(p.getName().equals(inputName))

{   
                  AddressBook.remove(p);      
                  System.out.println("Person deleted succesfully");   
              }
          }
      }
      
      else if(choice==3)

{     
 System.out.print("Enter Name: ");   
 String inputName=sc.nextLine();     
  for(Person p:AddressBook)

{          
       if(p.getName().equals(inputName))

{  
      System.out.println(p);      
  }
    }
      }
  else if(choice==4)

{     
    System.exit(0);     
  }
else

{                  
      System.out.println("Invalid Choice!Try again");
      }
  }
 }
}

Address book by using arrayList Code Are:

//Person.java

public class Person

{
 public String name;         
    public String address;      
    public long phoneNumber;    
    
public Person(String name, String address, long phoneNumber)

{
    this.name=name;
        this.address=address;
        this.phoneNumber=phoneNumber;
    }
 public String toString()

{
        return "Name: "+this.name+" Address: "+this.address+" Phone Number: "+this.phoneNumber;    
    }
}

//Main.java

import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;

public class Main

{
 public static void main(String[] args)

{
 List<Person> AddressBook=new ArrayList<Person>();  
  
  Scanner sc=new Scanner(System.in);         
  
  System.out.println("1.Add");
  System.out.println("2.Delete");
  System.out.println("3.Search");
  System.out.println("4.Exit");
  
  while(true)

{    
      System.out.print("Enter the choice: ");         
      int choice=Integer.parseInt(sc.nextLine());     
      
      if(choice==1)

{      
          System.out.print("Enter Name: ");
          String name=sc.nextLine();             
          System.out.print("Enter Address: ");
          String address=sc.nextLine();          
          System.out.print("Enter Phone Number: ");
          long phoneNumber=Long.parseLong(sc.nextLine());    


          Person p=new Person(name,address,phoneNumber);     
          AddressBook.add(p);                                
          System.out.println("Person added succesfully");     
      }
   else if(choice==2)

{     
          System.out.print("Enter Name: ");
          String inputName=sc.nextLine();    
          for(Person p:AddressBook)

{          
              if(p.name.equals(inputName))

{  
  AddressBook.remove(p);    
   System.out.println("Person deleted succesfully");   
 }
 }
 }
 else if(choice==3)

{     
          System.out.print("Enter Name: ");   
          String inputName=sc.nextLine();     
          for(Person p:AddressBook)

{      
     if(p.name.equals(inputName))

{  
       System.out.println(p);      
   }
  }
 }
 else if(choice==4)

{    
      System.exit(0);     
      }
else

{                   
          System.out.println("Invalid Choice!Try again");
      }
  }
 }
}

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Adjacency Matrix
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education