Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
2.3 kB
3
Indexable
Never
import java.util.*;
class Operation
{
 ArrayList<String> name=new ArrayList<String>();
 ArrayList<String> number=new ArrayList<String>();
 
  void save(String k,String m)
       {
          name.add(k);
          number.add(m);
       }
  void search(String y)
  {
    if (name.indexOf(y) != -1)
      {
         int a=name.indexOf(y);
         System.out.println("Name:"+name.get(a));
         System.out.println("Phone Number:"+number.get(a)); 
      }
    else
    {
      System.out.println("Name not found :(");
    }
  
  }
  
  void delete(String e)
  {
    if (name.indexOf(e) != -1)
      {
         int j=name.indexOf(e);
         System.out.println("Name:"+name.get(j));
         System.out.println("Phone Number:"+number.get(j));
         System.out.println("CONTACT DELETED!!!"); 
         name.remove(j);
         number.remove(j);
        
      }
    else
    {
      System.out.println("NAME NOT FOUND ENTER A VALID NAME");
    }
  
  }
  

}

class Contact extends Operation
{
   Contact()
   {
    Scanner sc=new Scanner(System.in);
    int n;
    String h,f,g,q;
     do
     {
       System.out.println("***WELCOME***");
       System.out.println("1.SAVE A CONTACT");
       System.out.println("2.SEARCH A CONTACT");
       System.out.println("3.DELETE A CONTACT");
       System.out.println("4.EXIT");
       System.out.println("ENTER THE NUMBER OF THE OPERATION TO BE PERFORMED:");
       n=sc.nextInt();
       if (n==1)
       {
         System.out.println("ENTER NAME:");
         h=sc.next();
         System.out.println("ENTER NUMBER:");
         g=sc.next();
         save(h,g);
         System.out.println("CONTACT HAS BEEN SAVED!!!");
        }
       else if(n==2)
       {
          System.out.println("ENTER NAME OF THE CONTACT TO BE SEARCHED:");
          g=sc.next();
          search(g); 
 
        }
       else if (n==3)
        {
          System.out.println("ENTER NAME OF THE CONTACT TO BE DELETED:");
          f=sc.next();
          delete(f);
         }
        else if (n==4)
        {
          System.out.println("THANK YOU!!:)");
          
         }
       else
       {
            System.out.println("ENTER A VALID OPERATION NUMBER");

        }

     }while(n!=4);
     

   }
 



}

class Project
{
  public static void main(String args[])
   {
      Contact c=new Contact(); 

   }

}