using System;
using System.Collections;
using System.Text ;
public class telephonebox
{
private ArrayList telebook;
public telephonebox()
{
telebook = new ArrayList();
}
public void storeScords(String item)
{
telebook.Add(item);
Console.WriteLine("插入成功!");
}
public void deleteItem(int index)
{
if(index <= 0 || index > telebook.Count )
{
Console.WriteLine("无此记录");
}
else
telebook.RemoveAt(index-1);
}
public void listRecords()
{
int n=0;
Console.WriteLine("********************************************************************");
while(n<telebook.Count)
{
Console.WriteLine("{0}.{1}",n+1,telebook[n]);
n++;
}
Console.WriteLine("********************************************************************");
}
public void displayItem(int index)
{
if(index <= 0 || index > telebook.Count )
{
Console.WriteLine("Sorry,no find such Record!");
}
else
{
Console.WriteLine("*******************************************************************************");
Console.WriteLine ("您要查看的记录如下:");
Console.WriteLine(telebook[index-1]);
Console.WriteLine("*******************************************************************************");
}
}
public void getactulAmount()
{
Console.WriteLine("Now the telebook have {0} records",telebook.Count);
}
public static void
{
telephonebox telebook = new telephonebox();
telebook.storeScords("VX,3333333");
telebook.storeScords("FI ,565645645");
Console.WriteLine("********************************************************************");
Console.WriteLine("Welcome to my TELEPHONE BOOK.\n");
telebook.getactulAmount();
telebook.listRecords();
Console.WriteLine("Please acording to bleows and CHOOSE an
Console.WriteLine("1.LIST all records.");
Console.WriteLine("2.DISPLAY a specific record.");
Console.WriteLine("3.APPEND a new record.");
Console.WriteLine("4.DELETE a specific record.");
Console.WriteLine("5.Show the total AMOUNT of records.");
Console.WriteLine("0.Exit.");
Console.WriteLine("*******************************************************************************");
String choice,new_record;
int num;
do
{
Console.WriteLine("");
Console.Write("please input an
choice = Console.ReadLine();
switch (choice)
{
case "1":
telebook.listRecords();
break;
case "2":
Console.Write("Which record do you want to Find:");
num = int.Parse(Console.ReadLine());
telebook.displayItem(num);
break;
case"3":
Console.Write("Please input a record, using 逗号 to separate name and phone code :");
new_record= Console.ReadLine();
telebook.storeScords(new_record);
break;
case"4":
Console.Write("Which record do you want to DELETE ,please input a number:");
num = int.Parse(Console.ReadLine());
telebook.deleteItem(num);
Console.WriteLine ("Deleted successful!");
break;
case"5":
telebook.getactulAmount();
break;
case"0":
Console.WriteLine("telebook has exited");
break;
default:
Console.WriteLine("\nDo you want to find telephone number?\n");
break;
}
}while(choice!="0");
}
}