You are on page 1of 12

import java.util.

Scanner;

import java.util.ArrayList;

import java.util.Collections;

import java.util.Arrays;

public class phonebook

public static void main (String[] Args)

// SCANNER AND VARIABLES

Scanner input = new Scanner(System.in);

int prompt;

int prompt2;

int prompt3;

String Number2;

contact c1 = new contact();

ArrayList<contact> contactList = new ArrayList<contact>();

do

{
displayMenu();

System.out.print("Enter choice: ");

prompt = input.nextInt();

if (prompt == 1)

do

System.out.println ("Enter Contact Number: ");

String phoneNumber = input.next();

c1.setNumber(phoneNumber);

System.out.println ("Enter First Name: ");

String firstName = input.next();

c1.setFirstName(firstName);

System.out.println ("Enter Last Name: ");

String lastName = input.next();

c1.setLastName(lastName);
System.out.println ("Enter country code: ");

String countryCode = input.next();

c1.setCountryCode(countryCode);

contactList.add(new contact(c1.getNumber() ,
c1.getFirstName() , c1.getLastName() , c1.getCountrycode()));

System.out.println ("Do you want to add more entries?


Press 1 for yes and 2 for no.");

prompt2 = input.nextInt();

}while(prompt2 != 2);

else if (prompt == 2)

System.out.println ("Enter Phone Number: ");

Number2 = input.next();

for (int x = 0; x < contactList.size(); x++)

for (int y = 0; y < contactList.size(); y++)


{

if (Number2.charAt(y) ==
contactList.get(x).getNumber().charAt(y))

System.out.println ("Here are some information


about: " + contactList.get(x).getCountrycode() + "-" +
contactList.get(x).getNumber());

System.out.println ("The user is: " +


contactList.get(x).getFirstName() + " , " + contactList.get(x).getLastName());

System.out.println ("What info do you want to


change?");

System.out.println ("[1] Phone Number , [2] First


Name , [3] Last Name , [4] Country Code [5] Back to Main Menu");

prompt3 = input.nextInt();

if (prompt3 == 1)

System.out.println ("Enter new Phone


number: ");

String phoneNumber = input.next();

String temp =
contactList.get(x).getNumber();
contactList.get(x).setNumber(phoneNumber);

System.out.println ("number successfuly


updated from: " + temp + " to: " + contactList.get(x).getNumber());

else if (prompt3 == 2)

System.out.println ("Enter new first name: ");

String firstName = input.next();

String temp =
contactList.get(x).getFirstName();

contactList.get(x).setFirstName(firstName);

System.out.println ("first name successfully


updated from: " + temp + " to: " + contactList.get(x).getFirstName());

else if (prompt3 == 3)

System.out.println ("Enter new last name: ");

String lastName = input.next();


String temp =
contactList.get(x).getLastName();

contactList.get(x).setLastName(lastName);

System.out.println ("Last name successfully


updated from: " + temp + " to: " + contactList.get(x).getLastName());

else if (prompt == 4)

System.out.println ("Enter new country code:


");

String areaCode = input.next();

String temp =
contactList.get(x).getCountrycode();

contactList.get(x).setCountryCode(areaCode);

System.out.println ("Last name successfully


updated from: " + temp + " to: " + contactList.get(x).getCountrycode());

else if (prompt == 5)
{

else if (prompt == 3)

System.out.println ("Enter phone number: ");

Number2 = input.next();

for (int x = 0; x < contactList.size() ; x++)

for (int y = 0; y < contactList.size(); y++)

if (Number2.charAt(y) ==
contactList.get(x).getNumber().charAt(y))

}
}

System.out.println ("Are you sure you want to


delete? Press 1 if yes and 2 if no.");

prompt3 = input.nextInt();

if (prompt3 == 1)

for (int j = 0 ; j < contactList.size(); j++)

if
(contactList.get(x).getNumber().equals(Number2))

contactList.remove(j);

break;

}
}

else if (prompt == 4)

System.out.println ("View contact by: [1] Phone Number ,


[2] First Name , [3] Last Name , [4] Country Code");

prompt3 = input.nextInt();

if ( prompt3 == 1)

for (int x = 0; x < contactList.size(); x++)

System.out.println (contactList.toString());

else if (prompt3 == 2)

String inputText;

System.out.println ("Enter Name: ");

inputText = input.next();

for (int x = 0; x < contactList.size(); x++)

{
/*ArrayList<contact> contactList2 = new
ArrayList<contact>(100);

for (int j = 0; j < contactList.size(); j++)

if (inputText.charAt(0) >
contactList.get(j).getFirstName().charAt(0))

contactList2.add(0, contactList.get(j));

contactList.remove(j);

contactList.add(j , contactList.get(j));

*/
Collections.sort(contactList);

System.out.println (contactList.toString());

}while(prompt != 5);

System.out.println (contactList.toString());

public static void displayMenu()

{
System.out.println ("[1] Add New Contact");

System.out.println ("[2] Edit Contact Info");

System.out.println ("[3] Delete Contact");

System.out.println ("[4] View/Search Contact");

System.out.println ("[5] Exit Program");

You might also like