public static void Main() { PhoneBook phoneBook = new PhoneBook(); string filePath = "../../TextFiles/phones.txt"; using (StreamReader fileReader = new StreamReader(filePath)) { string line; while ((line = fileReader.ReadLine()) != null) { string[] personElements = line.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); string personName = personElements[0].Trim(); string personTown = personElements[1].Trim(); string personPhone = personElements[2].Trim(); Person currentPerson = new Person(personName, personTown, personPhone); phoneBook.Add(currentPerson); } } Console.WriteLine("---------- Test Find(string name) ----------"); phoneBook.Find("Mimi Shmatkata"); Console.WriteLine("\n---------- Test Find(string name, string town) ----------"); phoneBook.Find("Mimi Shmatkata", "Sofia"); }
private static void ReadPhoneEntries( string path, PhoneBook phoneBook) { string line; using (System.IO.StreamReader reader = new System.IO.StreamReader(path)) { while ((line = reader.ReadLine()) != null) { PhoneBookEntry newEntry; var phoneEntry = line.Split('|'); var name = phoneEntry[0].Trim().Split(' '); var town = phoneEntry[1].Trim(); var phone = phoneEntry[2].Trim(); if (name.Length < 3) { newEntry = new PhoneBookEntry(town, phone, phoneEntry[0].Trim()); } else { newEntry = new PhoneBookEntry(name[0], name[1], name[2], town, phone); } phoneBook.Add(newEntry); } } }
static void Main(string[] args) { PhoneBook phoneBook = new PhoneBook(); // for testing purposes only phoneBook.Add("John Doe", "114 Market St", "St Louis", "MO", "63403", "6366435698"); phoneBook.Add("John E Doe", "324 Main St", "St Charles", "MO", "63303", "8475390126"); phoneBook.Add("John Michael West Doe", "574 Pole ave", "St Peters", "MO", "63333", "5628592375"); new Player().Play(phoneBook); List <Person> people = new List <Person>(); Helper.Filter(people, (p) => p.name = "Bob"); foreach (Person p in people) { Console.WriteLine(p.name); } Console.ReadLine(); }
static void Main(string[] args) { PhoneBook phonebook = new PhoneBook(); Console.WriteLine("ADD CONTACT -------------- Press 1"); Console.WriteLine("REMOVE CONTACT ----------- Press 2"); Console.WriteLine("FIND CONTACT ------------- Press 3"); Console.WriteLine("PRINT ALL CONTACTS ------- Press 4"); Console.WriteLine("EXIT --------------------- Press 5"); do { string keyWord = Console.ReadLine(); switch (keyWord) { case "1": Console.Write("Name: "); string name = Console.ReadLine(); Console.Write("Phone Number: "); string phoneNumber = Console.ReadLine(); phonebook.Add(new Record(name, phoneNumber)); Console.Write($"Contact \"{name}\" is added"); break; case "2": Console.Write("NAME: "); name = Console.ReadLine(); phonebook.Remove(phonebook[name]); Console.Write($"Contact \"{name}\" removed"); break; case "3": Console.WriteLine("NAME: "); name = Console.ReadLine(); Console.Write(phonebook[name]); break; case "4": phonebook.Display(); break; case "5": Environment.Exit(0); break; default: Console.Write("Enter valid number "); break; } } while (true); }
private static void Test1() { var book = new PhoneBook(); book.Add("Ivan", "1", "2"); book.Add("Ivan Vankata", "3", "4"); Console.WriteLine(book.Find("Ivan")); Console.WriteLine(); Console.WriteLine(book.Find("Ivan", "3")); }
public void Play(PhoneBook phoneBook) { Console.WriteLine("Phone Book"); Boolean run = true; while (run) { Console.WriteLine("1. Add " + "\n2. Search " + "\n3. Update " + "\n4. Delete " + "\n5. Display all contacts" + "\n6. Exit\n"); switch (Console.ReadLine()) { case "1": //Add Console.WriteLine("Add..."); Console.WriteLine("Enter full name: "); String name = Console.ReadLine(); Console.WriteLine("Enter street address (ex. 123 Fake St.): "); String streetAddress = Console.ReadLine(); Console.WriteLine("Enter city: "); String city = Console.ReadLine(); Console.WriteLine("Enter state abbreviation (ex. IL): "); String state = Console.ReadLine(); Console.WriteLine("Enter zipcode: "); String zipcode = Console.ReadLine(); Console.WriteLine("Enter telephone (1234567890): "); String telephone = Console.ReadLine(); phoneBook.Add(name, streetAddress, city, state, zipcode, telephone); break; case "2": //Search Boolean stayHere = true; while (stayHere) { Console.WriteLine("Search..."); Console.WriteLine("1. Search by first name " + "\n2. Search by last name " + "\n3. Search by full name (first last)" + "\n4. Search by telephone number (xxx-xxx-xxxx)" + "\n5. Search by city" + "\n6. Search by state" + "\n7. go back"); switch (Console.ReadLine()) { case "1": phoneBook.Search(new SearchFirst(phoneBook, Helper.Prompt("first name"))); break; case "2": phoneBook.Search(new SearchLast(phoneBook, Helper.Prompt("last name"))); break; case "3": phoneBook.Search(new SearchFullName(phoneBook, Helper.Prompt("full name"))); break; case "4": phoneBook.Search(new SearchTelephone(phoneBook, Helper.Prompt("telephone number(xxx - xxx - xxxx"))); break; case "5": phoneBook.Search(new SearchCity(phoneBook, Helper.Prompt("city"))); break; case "6": phoneBook.Search(new SearchState(phoneBook, Helper.Prompt("state"))); break; case "7": stayHere = false; break; default: Console.WriteLine("Invalid selection..."); continue; } } break; case "3": //Update Console.WriteLine("Update..."); Console.WriteLine("Enter telephone of contact to update"); String number = Console.ReadLine(); Console.WriteLine("Enter new name for contact"); String newName = Console.ReadLine(); Person toUpdate = phoneBook.Update(number, newName); if (toUpdate != null) { Console.WriteLine("Changed contact with phone number {0}'s name to {1}...", number, toUpdate.name); } else { Console.WriteLine("number not found..."); } break; case "4": //Delete Console.WriteLine("Delete..."); Console.WriteLine("Enter telephone number of contact to delete"); number = Console.ReadLine(); Person toDelete = phoneBook.Delete(number); if (toDelete != null) { Console.WriteLine("Deleted contact {0} with phone number {1}...", toDelete.name, number); } else { Console.WriteLine("number not found..."); } break; case "5": //Display all Console.WriteLine(phoneBook.DisplayAll()); break; case "6": //Exit Console.WriteLine("Exiting..."); run = false; break; default: //Invalid entry Console.WriteLine("Invalid choice. Please make another selection..."); break; } } }