Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi , I need your help in C# please. I need to complete the code below for practice but I am not familiar with it

Hi, I need your help in C# please. I need to complete the code below for practice but I am not familiar with it yet.
Here is the code below.
using System;
using System.Collections.Generic;
namespace GLA_01
{
class Contact
{
public string Name { get; set; }
public long Phone { get; set; }
}
class Program
{
public static void DisplayListAll(List myList)
{
if (myList.Count ==0)
{
Console.WriteLine("List is empty!");
}
else
{
Console.WriteLine("
All Contacts from the phonebook:
");
foreach (var item in myList)
{
Console.WriteLine("Name: {0}, Phone: {1}", item.Name, item.Phone);
}
}
}
public static string ConvertToNameCase(string name)
{
return name[0].ToString().ToUpper()+ name.Substring(1);
}
//Complete the ToDo Methods, additionally, you may also add new methods, if you need.
public static void DisplayAllContactsOfAUserName(List myList)//you may change parameters if required
{
//ToDo
//All contacts of a single user name
//if an user have two contact number, print user name once followed by contact numbers
//please see provided input/output for the formatting
}
public static Contact FindContactGivenAPhone(List myList, long phone)
{
//ToDo: remove the return null statement and complete the method
//Note: this method should return a Contact object
return null;
}
public static List FindAllContactsOfAGivenName(List myList, string name)
{
//ToDo: remove the return null statement and complete the method
//Note: this method returns a List of Contacts; even if a single contact record exists for the given name
return null;
}
//ToDo Methods
static void Main(string[] args)
{
List contactList = new List();
string command;
do
{
Console.WriteLine("
Enter a command: ");
command = Console.ReadLine();
command = command.ToLower();
while (command.Contains("")) command = command.Replace("","");
command = command.Trim();
var split = command.Split(null);
if (split.Length ==1)
{
if (split[0]== "exit")
{
break;
}
else if (split[0]== "findall")
{
DisplayListAll(contactList);
}
}
else if (split.Length ==0) continue;
else if (split[0]== "add")
{
for (int i =1; i < split.Length -1; i++)
{
split[i]= ConvertToNameCase(split[i]);
}
contactList.Add(new Contact(){ Name = string.Join("", split, 1, split.Length -2), Phone = long.Parse(split[split.Length -1])});
}
else if (split[0]== "find")
{
//ToDo
//Complete this block
//separate the correctly formatted name from the 'split' array
//choose the method to find all contacts when given a user name
//choose method to display all contacts of that user name
//NB: A user name can have one or more contact numbers
}
else if (split[0]== "update")
{
//ToDo update
//ToDo
//Complete this block
//separate old number from the 'split' array
//choose the method to find a contact when given the old phone number
//remove the contact containing the old phone number from the contactList
//extract the correctly formatted new user name and the from the 'split' array
//Add a new contact object into the contactList with and
}
else
{
Console.WriteLine("Unknown command!
Please enter command in correct format...");
}
} while (true);
}
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

If f(t) = e at cos wtu (t 1), find F(s).

Answered: 1 week ago