static void addInfo(string filename) { HashTabFile hashtabfile = new HashTabFile(filename); Hashtable hashtable = hashtabfile.makeHashtable(); using (TextWriter w = File.AppendText(filename)) { Console.WriteLine("Enter the name of the new person: "); string personName = Console.ReadLine().Trim(); while (!IsAllLetters(personName) || String.IsNullOrEmpty(personName)) { Console.WriteLine("The Name should include at least one letter."); Console.WriteLine("The Name can include only letters and white spaces."); Console.WriteLine("Please enter the name again:"); personName = Console.ReadLine().Trim(); } if (hashtable.ContainsKey(personName)) { Console.WriteLine("Person already exists in the phonebook."); } else { Console.WriteLine("Enter the phone number of the person without white space:"); long personNumber = long.Parse(Console.ReadLine()); w.WriteLine(personName + ":" + personNumber); Console.WriteLine("\n" + personName + " was added to the phonebook."); } } }
static void addInfoRandom(string filename) { HashTabFile hashtabfile = new HashTabFile(filename); Hashtable hashtable = hashtabfile.makeHashtable(); Console.WriteLine("Enter the name of the new person: "); string person_name = Console.ReadLine().Trim(); while (!IsAllLetters(person_name) || String.IsNullOrEmpty(person_name)) { Console.WriteLine("The Name should include at least one letter."); Console.WriteLine("The Name can include only letters and white spaces."); Console.WriteLine("Please enter the name again:"); person_name = Console.ReadLine().Trim(); } if (hashtable.ContainsKey(person_name)) { Console.WriteLine("Person already exists in the phonebook."); } else { AddRandomPhone add_random = new AddRandomPhone(filename, person_name); add_random.addToFile(); } }
long findRandToHashtable() { long random = generateRandom(); HashTabFile hashtabfile = new HashTabFile(filename); Hashtable hashtable = hashtabfile.makeHashtable(); if (hashtable.ContainsValue(random)) { random = generateRandom(); } return(random); }
static void readInfo(string filename) { HashTabFile hashtabfile = new HashTabFile(filename); Hashtable hashtable = hashtabfile.makeHashtable(); Console.Write("Enter the name of the person: "); string newName = Console.ReadLine().Trim(); object newPhone = hashtable[newName]; if (newPhone == null) { Console.WriteLine("-- Not Found in Phone Book"); } else { Console.WriteLine(newName + " phone number is " + newPhone + "."); } }