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: 665619 • Letter: Y

Question

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

·        

A. 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.

B. 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.

C. 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

Exit

Explanation / Answer

import java.util.Scanner;


public class contactList {
String name;
int[] phone;
static contactList[] c=new contactList[50];
   public contactList(String n,int[] p){
       phone=new int[p.length];
       System.arraycopy( p, 0, phone, 0, p.length );
       name=n.toLowerCase();
   }
   public static void main(String[] args) {
       int count=0;
       int opt=0;
       while(opt!=5){
       System.out.println("Enter the option you want perform:");
       System.out.println("1.Add a contact");
       System.out.println("2.Delete a contact");
       System.out.println("3.print all contacts");
       System.out.println("4.search a contact");
       System.out.println("5.exit");
       Scanner s=new Scanner(System.in);
       opt=s.nextInt();
       switch(opt){
       case 1:
          
           Acontact(count);
           count++;
           break;
       case 2:
           Dcontact(count);
           break;
       case 3:
           Pcontact(count);
           break;
       case 4:
           Scontact(count);
           break;
       default:
           System.out.println("Exiting byeeeee");
       }
       }
   }
   private static void Acontact(int n) {
       System.out.println("enter name:");
       Scanner s=new Scanner(System.in);
       String name=s.next();
       System.out.println("enter number of phone numbers:");
       int no=s.nextInt();
       int[] phn=new int[no];
       System.out.println("enter phone numbers:");
       for(int i=0;i<no;i++){
           phn[i]=s.nextInt();
       }
       c[n]=new contactList(name,phn);
      
   }
   private static void Dcontact(int n) {
       if(n==0){
           System.out.println("No contacts:");
       }
       else{
       System.out.println("enter name you want to delete:");
       Scanner s=new Scanner(System.in);
       String name=s.next();
       name=name.toLowerCase();
       for(int i=0;i<n;i++){
           if(c[i].name.equals(name)){
               c[i]=null;
           }
                  
       }
       }
   }
   private static void Pcontact(int n) {
       if(n==0){
           System.out.println("No contacts:");
       }
       else{
       System.out.println("enter name you want to delete:");
       Scanner s=new Scanner(System.in);
       String name=s.next();
       name=name.toLowerCase();
       for(int i=0;i<n;i++){
          
               System.out.println("Name:"+name);
               System.out.println("Phone numbers:");
               for(int j=0;j<c[i].phone.length;j++){
                   System.out.println(c[i].phone[j]);
               }
          
                  
       }
       }
      
   }
   private static void Scontact(int n) {
       if(n==0){
           System.out.println("No contacts:");
       }
       else{
       System.out.println("enter name you want to delete:");
       Scanner s=new Scanner(System.in);
       String name=s.next();
       name=name.toLowerCase();
       for(int i=0;i<n;i++){
           if(c[i].name.equals(name)){
               System.out.println("Name:"+name);
               System.out.println("Phone numbers:");
               for(int j=0;j<c[i].phone.length;j++){
                   System.out.println(c[i].phone[j]);
               }
           }
                  
       }
      
       }
   }

}

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