Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You will design an online contact list to keep track of names and phone numbers.

ID: 666879 • Letter: Y

Question

You will design an online contact list to keep track of names and phone numbers.

Define a class contactList that can store a name and up to 3 phone numbers (use an array for the phone numbers).Use constructors to automatically initialize the member variables.

Add the following operations to your program:

Add a new contact.Ask the user to enter the name and up to 3 phone numbers.

Delete a contact by having the user enter the name.

Search the list by name and print the name and phone numbers for that one person.

Print all contacts and phone numbers for each contact.

Create a program to test your class.The program should have a menu like this one.

Add a contact

Delete a contact

Print all contacts

Search for a contact

< >

Explanation / Answer

import java.util.Scanner;

public class contactList {
private static String name;
private static String[] numbers;
public contactList(String k,String[] f){
   name=k;
   numbers=new String[f.length];
   for(int i=0;i<f.length;i++){
       numbers[i]=f[i];
   }
}

public static void main(String[] args){
   int opt=0;
   contactList[] l=new contactList[100];
   int count=0;
   String nam;
   int num=3;
   String[] phn;
   System.out.println("Enter the option u want to enter:");
   while(opt<5){
   System.out.println("1.Add a COntact 2.Delete a Contact 3.Search for a Contact 4.Print all Contacts 5exit");
   Scanner s=new Scanner(System.in);
   opt=s.nextInt();
   switch(opt){
   case 1:
       System.out.println(" Enter the name:");
       nam=s.next();
       System.out.println("How many phn numbers:");
       num=s.nextInt();
       phn=new String[num];
       for(int i=0;i<num;i++){
           System.out.println("Enter the "+(i+1)+"phone numbers");
           phn[i]=s.next();
       }
       l[count]=new contactList(nam,phn);
       count++;
       break;
   case 2:
       System.out.println("Enter the name of the contact you want to delete:");
       nam=s.next();
       for(int i=0;i<count;i++){
           if(l[i].name.equals(nam)){
               l[i]=null;
               System.out.println("Contact deleted");
               break;
           }
       }
       break;
   case 3:
       System.out.println("Enter the name of the contact you want :");
       nam=s.next();
       for(int i=0;i<count;i++){
           if(l[i].name.equals(nam)){
              
               System.out.println("Contact name"+l[i].name);
               for(int j=0;j<l[i].numbers.length;j++){
                   System.out.println((j+1)+"phone number:"+l[i].numbers[j]);
               }
               break;
           }
       }
       break;
   case 4:
       for(int i=0;i<count;i++){
          
              
               System.out.println("Contact name"+l[i].name);
               for(int j=0;j<l[i].numbers.length;j++){
                   System.out.println((j+1)+"phone number:"+l[i].numbers[j]);
           }
       }
       break;
   default :
       opt=5;
       break;
   }
   }
   }

  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote