public override void DeletePhone(string personName) { // p = new PhoneBook(personName, phoneNumber, phoneList); for (int i = 0; i < phoneList.Count; i++) { PhoneBook pb = (PhoneBook)phoneList[i]; if (pb.getName() == personName) { phoneList.Remove(pb); Console.WriteLine("The information has been deleted!"); } else if (pb.getName() != personName && i == phoneList.Count - 1) { Console.WriteLine("This person does not exist!"); } } }
static void Main(string[] args) { ArrayList phone = new ArrayList(); ArrayList phoneNumber = new ArrayList(); PhoneBook test = new PhoneBook(); PhoneBook p = new PhoneBook("", phoneNumber, phone); bool func = true; while (func) { Console.WriteLine("Press # from 1-6: "); int ch = Convert.ToInt32(Console.ReadLine()); switch (ch) { case 1: p.InsertPhone("Phillip", "0123"); break; case 2: p.UpdatePhone("Phillip", "343"); break; case 3: p.SearchPhone("Phillip"); break; case 4: p.DeletePhone("Phillip"); break; case 5: Console.WriteLine("Are you sure?(y/n)"); char yN = Convert.ToChar(Console.ReadLine()); if (yN == 'y') { func = false; } break; default: Console.WriteLine("Invalid Input!"); break; } } }
public override void UpdatePhone(string personName, string newPhone) { //PhoneBook p = new PhoneBook(personName, phoneNumber, phoneList); for (int i = 0; i < phoneList.Count; i++) { PhoneBook pb = (PhoneBook)phoneList[i]; if (pb.getName() == personName) { pb.getPhone().Clear(); pb.getPhone().Add(newPhone); Console.WriteLine("The information has been updated!"); } else if (pb.getName() != personName && i == phoneList.Count - 1) { Console.WriteLine("This person does not exist!"); } } }
public override void SearchPhone(string personName) { //PhoneBook p = new PhoneBook(personName, phoneNumber, phoneList); for (int i = 0; i < phoneList.Count; i++) { PhoneBook pb = (PhoneBook)phoneList[i]; if (pb.getName() == personName) { Console.Write("Name: " + pb.getName() + " " + "Phone Number: "); for (int j = 0; j < phoneNumber.Count; j++) { Console.Write(pb.getPhone()[j] + " "); } } else if (pb.getName() != personName && i == phoneList.Count - 1) { Console.WriteLine("This person does not exist!"); } } }
//use override method the same as method in abstract class public override void InsertPhone(string personName, string personPhone) { //int length = Int32.MaxValue; phoneList = new ArrayList(); //int i = 0; //bool isTru = true; //while (isTru) //{ //PhoneBook p = new PhoneBook(null,null,phoneList); phoneNumber = new ArrayList(); p = new PhoneBook(); //if (p != null) { //PhoneBook p = null; //for (int i = 0; i < phoneList.Count; i++) //{ // p = new PhoneBook(personName, phoneNumber, phoneList); // phoneList.Add(p); // p.getPhone().Add(personPhone); // Console.WriteLine("The information has been inserted into the database"); //} //for (int i = 0; i <= phoneList.Count; i++) //{ phoneList.Add(p); int count = 1; //Console.WriteLine(p.getName()); for (int i = 0; i < phoneList.Count; i++) { PhoneBook pb = (PhoneBook)phoneList[i]; if (pb.getName() == personName) { //phoneNumber.Add(personPhone); //phoneList[i] = new PhoneBook(personName, , phoneList) //Phone number : name, list of phone number. pb.getPhone().Add(personPhone); //p = new PhoneBook(personName, phoneNumber, phoneList); Console.WriteLine("The information has been inserted into the database"); break; } else if (pb.getName() != personName && phoneList.Count == 1) { p = new PhoneBook(personName, phoneNumber, phoneList); phoneList.Add(p); p.getPhone().Add(personPhone); Console.WriteLine("The information has been inserted into the database"); break; } } //foreach (PhoneBook pb in phoneList) //{ // Console.WriteLine(pb.getName() + " "); //} //Console.WriteLine(count); for (int i = 0; i < phoneList.Count; i++) { PhoneBook pb = (PhoneBook)phoneList[i]; if (phoneList.Contains(pb) && count == 2) { phoneList.Remove(pb); break; } else if (phoneList.Contains(pb) && count == 1) { count++; break; } } phoneList.RemoveAt(0); foreach (PhoneBook pb in phoneList) { Console.Write("Name: " + pb.getName() + " Phone Number: "); foreach (string ph in phoneNumber) { Console.Write(ph + " "); } Console.WriteLine(); } //} //isTru = false; // } }