PDA

View Full Version : Xem bài quản lý danh sách xe hơi giúp mình



ruacon2008
08-03-2009, 21:33
làm xong bài này rùi mà sao gọi lệnh sỏt vẫn ko dc ae ai bik sai chỗ nào ko



using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace baitap
{

/// <summary>
/// Mô tả giao diện chung
/// cho các loại xe
/// </summary>
interface ICar
{



string Make
{
get;
set;
}

string Model
{
get;
set;
}

string Color
{
get;
set;
}

int Year
{
get;
set;
}

string Price
{
get;
set;
}
/// <summary>
/// Mô tả phương thức hiển thị
/// thông tin xe
/// </summary>
void Show();
} // end of Car
class Car : ICar
{
// du lieu thanh vien
// dinh nghia du lieu
private string make;
private string model;
private string color;
private string price;
private int year;

public string Make
{
get { return make; }
set { make = value; }
}
public string Model
{
get { return model; }
set { model = value; }
}
public string Color
{
get { return color; }
set { color = value; }
}
public string Price
{
get { return price; }
set { price = value; }
}
public int Year
{
get { return year; }
set { year = value; }
}
public void Input()
{

Console.Write("Make:");
make = Console.ReadLine();
Console.Write("Model:");
model = Console.ReadLine();
Console.Write("Color:");
color = Console.ReadLine();
Console.Write("Year:");
year = int.Parse(Console.ReadLine());
Console.Write("Price:");
price = Console.ReadLine();
}


public void Show()
{
Console.WriteLine(" ");
Console.Write("" + make);
Console.Write("-" + model);
Console.Write("-" + color);
Console.Write("- " + year);
Console.Write("-" + price);
}
public int CompareTo(object obj)
{
Car c2 = (Car)obj;

// so sanh thu tu theo ten sach
return this.Make.CompareTo(c2.make);
}
}
class CarList
{
private ArrayList list = new ArrayList();
public void AddCar()
{
Car c = new Car();
c.Input();//nhap vao danh sach
list.Add(c);//them vao danh sach

}

public void ShowList()
{

foreach (Car c in list)
{

c.Show();
}
}

public void InputList()
{
int n;
Console.Write("Amount of car :");
n = int.Parse(Console.ReadLine());
while (n > 0)
{
AddCar();
n--;
}
}
public void SortByMake()
{
// thuc thi sort

list.Sort();
}



}//end CarList
class Program
{
static void Main(string[] args)
{
string luachon;
CarList c1 = new CarList();
CarList list = new CarList();
do
{

Console.WriteLine("");
Console.WriteLine("New Command:");
luachon = Console.ReadLine();

if (luachon == "add" || luachon == "Add")
{
c1.InputList();
}
else if (luachon == "list" || luachon == "List")
{
c1.ShowList();
}
else if(luachon == "sort" || luachon == "Sort")
{
list.SortByMake();
list.ShowList();

}
else if (luachon == "help" || luachon == "Help")

{
Console.WriteLine("------HELP-----");
Console.WriteLine("Help - Show Help List");
Console.WriteLine("Add - Add to List Car");
Console.WriteLine("Show - Show List Car");
Console.WriteLine("Quit - Quit the application");
Console.WriteLine("Sort - Sort By Make");
}
else Console.WriteLine("Command invalid...");
}
while (luachon != "Quit" && luachon != "quit");





}


}

}

[=========> Bổ sung bài viết <=========]

Can u help me ?????please tell me why