Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp9
- {
- class MobliePhone
- {
- List<Contact> ContactsList = new List<Contact> { };
- public void menu()
- {
- Console.WriteLine("Choose Option:");
- Console.WriteLine("0 - Quit");
- Console.WriteLine("1 - Print List Of Contatcs");
- Console.WriteLine("2 - Add new Contact");
- Console.WriteLine("3 - Update Existing Contact");
- Console.WriteLine("4 - Remove Exisitng Object");
- Console.WriteLine("5 - Find Contact");
- bool MenuOption = true;
- while (MenuOption)
- {
- int number = Convert.ToInt32(Console.ReadLine());
- switch (number)
- {
- case 0:
- MenuOption = false;
- break;
- case 1:
- PrintListOfContacts();
- break;
- case 2:
- addNewContact();
- break;
- case 3:
- UpdateExistingContact();
- break;
- case 4:
- RemoveExistingContact();
- break;
- case 5:
- FindContact();
- break;
- }
- }
- }
- bool FindContact()
- {
- Console.WriteLine("Enter Name:");
- string name = Console.ReadLine();
- Console.WriteLine(FindContact(name));
- return false;
- }
- bool FindContact(string name)
- {
- for (int i = 0; i < ContactsList.Count; i++)
- {
- if (ContactsList[i].name == name)
- {
- Console.WriteLine("Contact:" + name + "On position:" + i);
- return true;
- }
- }
- return false;
- }
- private void RemoveExistingContact()
- {
- string imie;
- string number;
- Console.WriteLine("Enter Name:");
- imie = Console.ReadLine();
- int ifDel = 0;
- foreach (var item in ContactsList)
- {
- if (item.name.Equals(imie))
- {
- ContactsList.Remove(item);
- ifDel++;
- break;
- }
- }
- if (ifDel == 0)
- {
- Console.WriteLine("Contact dosent exsist");
- }
- }
- private void UpdateExistingContact()
- {
- string imie;
- string number;
- Console.WriteLine("Enter Name:");
- imie = Console.ReadLine();
- int ifEdit = 0;
- foreach (var item in ContactsList)
- {
- if (item.name == imie)
- {
- Console.WriteLine("Enter new name");
- string newName = Console.ReadLine();
- item.name = newName;
- Console.WriteLine("Enter new phone number");
- string newPN = Console.ReadLine();
- item.tel = newPN;
- ifEdit++;
- }
- }
- if (ifEdit == 0)
- {
- Console.WriteLine("Contact dosent exist");
- }
- }
- private void addNewContact()
- {
- string imie;
- string number;
- Console.WriteLine("Enter Name:");
- imie = Console.ReadLine();
- Console.WriteLine("Enter phone number");
- number = Console.ReadLine();
- if (FindContact(imie) == true)
- {
- Console.WriteLine("Contact already exist");
- }
- else
- {
- ContactsList.Add(new Contact(imie, number));
- }
- }
- private void PrintListOfContacts()
- {
- foreach (var item in ContactsList)
- {
- Console.WriteLine("Tel and Name" + item.tel +" "+ item.name);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement