By GokiSoft.com|
09:41 01/11/2021|
C Sharp
[Assignment] Bài tập ôn luyên tổng quát C# - Lập Trình C# - Lập Trình C Sharp
Đề 1: Tạo ứng dụng calculator bằng giao diện (Winform Application) gồm các chức năng sau
- Tạo máy tính gồm các chức năng cơ bản
- Lưu lại toàn bộ lịch sử đã thực hiện các phép tính vào file hoặc CSDL
Đề 2 : Tạo ứng dụng quản lý khách sạn (Dùng console hoặc Winform -> tuỳ chọn)
Note : Form sẽ đc nhiều điểm hơn
Gồm các chức năng
- Thêm/Sửa/Xoá KS
- Thêm sửa xoá khách hàng
- Quản lý đặt phòng
- Tìm kiếm.
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)
Do Trung Duc
2021-06-01 10:29:02
using System;
using System.Collections.Generic;
using System.Text;
namespace Assigment
{
[Serializable]
class Hotel
{
public List<Room> RoomList { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public int ID { get; set; }
public Hotel() {
RoomList = new List<Room>();
}
public void CreateNewRoom()
{
Room room = new Room();
room.Input();
RoomList.Add(room);
Console.WriteLine("Da tao phong moi thanh cong");
}
public void DeleteRoom()
{
Console.WriteLine("Nhap ten phong can xoa");
string FindRoomName = Console.ReadLine();
foreach(Room item in RoomList)
{
if (item.Name == FindRoomName)
{
RoomList.Remove(item);
}
}
Room room = new Room();
room.Input();
RoomList.Add(room);
Console.WriteLine("Da tao phong moi thanh cong");
}
public void Input()
{
Console.WriteLine("Nhap ten khach san: ");
Name = Console.ReadLine();
Console.WriteLine("Nhap dia chi khach san: ");
Address = Console.ReadLine();
Console.WriteLine("Nhap ID khach san: ");
ID = Int32.Parse(Console.ReadLine());
}
public void Display()
{
Console.WriteLine("Ten khach san: {0} , Dia chi: :{1}, ID: {2} ", Name, Address, ID);
Console.WriteLine("Ban co muon xem danh sach phong khong? An phim 1 neu co, phim 0 neu khong");
int choose = Int32.Parse(Console.ReadLine());
if (choose == 1)
{
int count = 1;
foreach (Room item in RoomList)
{
Console.WriteLine("Thong tin phong thu " + count);
item.Dispay();
count++;
}
}
else
{
return;
}
}
}
}
Do Trung Duc
2021-06-01 10:28:47
using System;
using System.Collections.Generic;
using System.IO;
namespace Assigment
{
class Manager
{
static List<Hotel> HotelList = new List<Hotel>();
static void Main(string[] args)
{
int choose;
do
{
DisplayMenu();
Console.WriteLine("Nhap lua chon: ");
choose = Int32.Parse(Console.ReadLine());
switch (choose)
{
case 1:
AddNewHotel();
break;
case 2:
DeleteHotel();
break;
case 3:
CreateNewRoom();
break;
case 4:
DeleteRoom();
break;
case 5:
AddNewBookRoom();
break;
case 6:
DeleteBookRoom();
break;
case 7:
FindEmtyRoom();
break;
case 8:
FindHotelInforMation();
break;
case 9:
SaveAndExit();
break;
case 0:
LoadData();
break;
}
} while (choose != 9);
}
private static void DeleteRoom()
{
Console.WriteLine("Nhap ID khach san ban muon xoa phong");
int ID = Int32.Parse(Console.ReadLine());
foreach (Hotel hotel in HotelList)
{
if (ID == hotel.ID)
{
hotel.DeleteRoom();
}
}
}
private static void CreateNewRoom()
{
Console.WriteLine("Nhap ID khach san ban tao phong moi");
int ID = Int32.Parse(Console.ReadLine());
foreach(Hotel hotel in HotelList)
{
if(ID == hotel.ID)
{
hotel.CreateNewRoom();
}
}
}
private static void LoadData()
{
using (Stream stream = File.Open("hotels.dat", FileMode.Open))
{
var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
HotelList = (List<Hotel>)binaryFormatter.Deserialize(stream);
}
Console.WriteLine("Doc file thanh cong");
}
private static void SaveAndExit()
{
string filePath = "hotels.dat";
using (Stream stream = File.Open(filePath, FileMode.Create))
{
var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
binaryFormatter.Serialize(stream, HotelList);
}
Console.WriteLine("Luu file thanh cong");
}
private static void FindHotelInforMation()
{
foreach(Hotel hotel in HotelList)
{
Console.WriteLine("Ten Khach san: {0}, ID : {1}", hotel.Name, hotel.ID);
}
Console.WriteLine("Nhap ID khach san ban muon tim thong tin theo danh sach tren ");
int ID = Int32.Parse(Console.ReadLine());
int count = 0;
foreach (Hotel hotel in HotelList)
{
if(ID == hotel.ID)
{
hotel.Display();
count++;
}
}
if (count == 0)
{
Console.WriteLine("Khong tim thay khach san nao co ID da nhap: ");
}
}
private static void FindEmtyRoom()
{
int count = 0;
Console.WriteLine("Nhap loai phong phong can tim: An phim 1 neu la phong don, an phim 2 neu la phong doi: ");
int choose = Int32.Parse(Console.ReadLine());
string Type;
if (choose == 1)
{
Type = "Single";
}
else
{
Type = "Double";
}
Console.WriteLine("Nhap thoi gian checkin theo cu phap: Nam/thang/ngay Gio:Phut:Giay");
DateTime CheckInTime = DateTime.Parse(Console.ReadLine());
Console.WriteLine("Nhap thoi gian checkout theo cu phap: Nam/thang/ngay Gio:Phut:Giay");
DateTime CheckOutTime = DateTime.Parse(Console.ReadLine());
foreach(Hotel hotel in HotelList)
{
foreach (Room room in hotel.RoomList)
{
if(room.Type == Type)
{
bool Emty = false;
foreach(BookRoom bookroom in room.BookRoomList)
{
int CompareCheckIn1 = DateTime.Compare(CheckInTime, bookroom.CheckInTime);
int CompareCheckIn2 = DateTime.Compare(CheckInTime, bookroom.CheckOutTime);
int CompareCheckOut1 = DateTime.Compare(CheckOutTime, bookroom.CheckInTime);
int CompareCheckOut2 = DateTime.Compare(CheckOutTime, bookroom.CheckOutTime);
if ((CompareCheckIn1 > 0 && CompareCheckIn2 < 0) || (CompareCheckOut1 > 0 && CompareCheckOut2 < 0))
{
Emty = true;
break;
}
}
if (Emty == false)
{
Console.Write("Thong tin phong phu hop nhu sau:");
Console.WriteLine("Ten khach san {0}, Phong: {1}",hotel.Name, room.Name);
count++;
}
}
}
}
if(count == 0)
{
Console.WriteLine("Tat ca cac phong da duoc Book vao khoang thoi gian tren");
}
}
private static void DeleteBookRoom()
{
Console.WriteLine("Nhap ID khach san: ");
int ID = Int32.Parse(Console.ReadLine());
Console.WriteLine("Nhap chinh xac ten phong muon xoa lich Book: ");
string RoomName = Console.ReadLine();
foreach (Hotel hotel in HotelList)
{
if (hotel.ID == ID)
{
foreach (Room item in hotel.RoomList)
{
if (RoomName == item.Name)
{
item.DeleteBookRoom();
break;
}
}
}
}
}
private static void AddNewBookRoom()
{
Console.WriteLine("Nhap ID khach san: ");
int ID = Int32.Parse(Console.ReadLine());
Console.WriteLine("Nhap chinh xac ten phong duoc Book: ");
string RoomName = Console.ReadLine();
foreach(Hotel hotel in HotelList)
{
if(hotel.ID == ID)
{
foreach(Room item in hotel.RoomList)
{
if(RoomName == item.Name)
{
item.AddBookRoom();
}
}
}
}
}
private static void AddNewHotel()
{
Hotel hotel = new Hotel();
hotel.Input();
HotelList.Add(hotel);
Console.WriteLine("Them moi khach san thanh cong");
}
private static void DeleteHotel()
{
Console.WriteLine("Nhap ID khach san can xoa");
int FindHotelID = Int32.Parse(Console.ReadLine());
foreach (Hotel hotel in HotelList)
{
if (hotel.ID == FindHotelID)
{
HotelList.Remove(hotel);
break;
}
}
Console.WriteLine("Da xoa thanh cong");
}
private static void DisplayMenu()
{
Console.WriteLine("0. Update du lieu tu File");
Console.WriteLine("1. Tao khach san moi");
Console.WriteLine("2. Xoa khach san");
Console.WriteLine("3. Tao Phong moi");
Console.WriteLine("4. Xoa phong");
Console.WriteLine("5. Them lich Book phong");
Console.WriteLine("6. Xoa lich Book phong");
Console.WriteLine("7. Tim kiem phong con trong theo yeu cau");
Console.WriteLine("8. Tra cuu thong tin khach san");
Console.WriteLine("9. Thoat chuong trinh, du lieu se duoc luu tu dong...");
}
}
}
Trần Văn Lâm
2021-05-27 13:29:56
#Book.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Hotel
{
class Book
{
int CheckIn { get; set; }
int CheckOut { get; set; }
public string CMTND { get; set; }
public string HotelNo { get; set; }
public string RoomNo { get; set; }
public Book()
{
}
public Book(int CheckIn, int CheckOut, string CMTND, string HotelNo, string RoomNo)
{
this.CheckIn = CheckIn;
this.CheckOut = CheckOut;
this.CMTND = CMTND;
this.HotelNo = HotelNo;
this.RoomNo = RoomNo;
}
public void Input(List<Customer> customerList, List<Hotel> hotelList)
{
Console.WriteLine("Nhap CMTND Cua Khach Hang");
CMTND = Console.ReadLine();
bool isFind = false;
for (int i = 0; i < customerList.Count; i++)
{
if (customerList[i].CMTND.Equals(CMTND))
{
isFind = true;
break;
}
}
if (!isFind)
{
Console.WriteLine("Khach Hang Khong Ton Tai! Nhap Moi:");
Customer customer = new Customer();
customer.CMTND = CMTND;
customer.InputWithCMTND();
}
DisplayHotelMenu(hotelList);
Hotel hotel = null;
while (true)
{
HotelNo = Console.ReadLine();
isFind = false;
for (int i = 0; i < hotelList.Count; i++)
{
if (hotelList[i].No.Equals(HotelNo))
{
isFind = true;
hotel = hotelList[i];
break;
}
}
if (!isFind)
{
break;
}
else
{
Console.WriteLine("Nhap Lai Ma Khach San!");
}
}
DisplayRoomMenu(hotel);
while (true)
{
RoomNo = Console.ReadLine();
isFind = false;
for (int i = 0; i < hotel.roomList.Count; i++)
{
if (hotel.roomList[i].No.Equals(RoomNo))
{
isFind = true;
break;
}
}
if (!isFind)
{
break;
}
else
{
Console.WriteLine("Nhap Lai Ma Phong Khach San!");
}
}
Console.WriteLine("Nhap Ngay Dat Phong:");
CheckIn = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Nhap Ngay Tra Phong:");
CheckOut = Convert.ToInt32(Console.ReadLine());
}
public void DisplayHotelMenu(List<Hotel> hotelList)
{
for (int i = 0; i < hotelList.Count; i++)
{
Console.WriteLine("{0}. - {1} - {2}", i+1, hotelList[i].Name, hotelList[i].No);
}
Console.WriteLine("Nhap Ma Khach San Can Chon:");
}
public void DisplayRoomMenu(Hotel hotel)
{
for (int i = 0; i < hotel.roomList.Count; i++)
{
Console.WriteLine("{0}. - {1} - {2}", i + 1, hotel.roomList[i].Name, hotel.roomList[i].No) ;
}
Console.WriteLine("Nhap Ma Phong Can Chon:");
}
}
}
#Customer.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Hotel
{
class Customer
{
public string CMTND { get; set; }
public string Fullname { get; set; }
public int Age { get; set; }
public string Gender { get; set; }
public string Address { get; set; }
public Customer()
{
}
public Customer(string CMTND, string Fullname, int Age, string Gender, string Address)
{
this.CMTND = CMTND;
this.Fullname = Fullname;
this.Age = Age;
this.Gender = Gender;
this.Address = Address;
}
public void Input()
{
Console.WriteLine("Nhap CMTND:");
CMTND = Console.ReadLine();
InputWithCMTND();
}
public void InputWithCMTND()
{
Console.WriteLine("Nhap Ho Ten:");
Fullname = Console.ReadLine();
Console.WriteLine("Nhap Tuoi:");
Age = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Nhap Gioi Tinh:");
Gender = Console.ReadLine();
Console.WriteLine("Nhap Dia Chi:");
Address = Console.ReadLine();
}
public void Display()
{
Console.WriteLine("Thon tin Khach Hang: (Ho Ten : {0}, Tuoi : {1}, CMTND : {2}, Gioi Tinh : {3}, Dia Chi : {4})", Fullname, Age, CMTND, Gender, Address);
}
}
}
#Hotel.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Hotel
{
class Hotel
{
public string No { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string Type { get; set; }
public List<Room> roomList = new List<Room>();
public Hotel()
{
}
public Hotel(string No, string Name, string Address, string Type)
{
this.No = No;
this.Name = Name;
this.Address = Address;
this.Type = Type;
}
public void Input()
{
Console.WriteLine("Nhap Ma Khach San:");
No = Console.ReadLine();
Console.WriteLine("Nhap Ten Khach San:");
Name = Console.ReadLine();
Console.WriteLine("Nhap Dia Chi:");
Address = Console.ReadLine();
Console.WriteLine("Nhap Loai Khach San:");
Type = Console.ReadLine();
Console.WriteLine("Nhap So Phong Can Them:");
int N = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < N; i++)
{
Room room = new Room();
room.Input();
roomList.Add(room);
}
}
public void Display()
{
Console.WriteLine("Hotel(Ten Khach San : {0}, Dia Chi : {1}, Loai Khach San : {2})", Name, Address, Type);
for (int i = 0;i < roomList.Count; i++)
{
roomList[i].Display();
}
}
public void DisplayBase()
{
Console.WriteLine("Hotel(Ten Khach San : {0}, Dia Chi : {1}, Loai Khach San : {2})", Name, Address, Type);
}
}
}
#Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Hotel
{
class Program
{
static void Main(string[] args)
{
List<Customer> customerList = new List<Customer>();
List<Hotel> hotelList = new List<Hotel>();
List<Book> bookList = new List<Book>();
int choose;
do
{
showMenu();
choose = Convert.ToInt32(Console.ReadLine());
switch (choose)
{
case 1:
Input(hotelList);
break;
case 2:
Display(hotelList);
break;
case 3:
InputBook(hotelList,customerList,bookList);
break;
case 4:
SearchAvailableBook(hotelList, bookList);
break;
case 5:
Statistic(bookList, hotelList);
break;
case 6:
Search(bookList, hotelList);
break;
case 7:
Console.WriteLine("Thoat!!!");
break;
default :
Console.WriteLine("Nhap Lai!!");
break;
}
} while (choose!=7);
}
static void Input(List<Hotel> hotelList)
{
Console.WriteLine("Nhap So Khach San Can Them:");
int N = Convert.ToInt32(Console.ReadLine());
for(int i = 0; i < N; i++)
{
Hotel hotel = new Hotel();
hotel.Input();
hotelList.Add(hotel);
}
}
static void Display(List<Hotel> hotelList)
{
for (int i = 0; i < hotelList.Count; i++)
{
hotelList[i].Display();
}
}
static void InputBook(List<Hotel> hotelList, List<Customer> customerList, List<Book> bookList)
{
Book book = new Book();
book.Input(customerList, hotelList);
bookList.Add(book);
}
static void SearchAvailableBook(List<Hotel> hotelList, List<Book> bookList)
{
int checkIn;
int checkOut;
Console.WriteLine("Nhap Ngay Dat Phong:");
checkIn = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Nhap Ngay Tra Phong:");
checkOut = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < hotelList.Count; i++)
{
hotelList[i].DisplayBase();
Console.WriteLine("Danh Sach Phong Trong:");
List<Room> rooms = new List<Room>();
for (int j = 0; j < rooms.Count; j++)
{
if (checkA(bookList, hotelList[i].No, rooms[j], checkIn, checkOut))
{
rooms[j].Display();
}
}
}
}
static bool checkA(List<Book> bookList, Room room, int checkIn, int checkOut, string roomNo, string hotelNo)
{
for (int i = 0; i < bookList.Count; i++)
{
Book book = bookList[i];
if (book.HotelNo.Equals(hotelNo) && book.RoomNo.Equals(roomNo) && (book.CheckIn >= checkIn && book.CheckIn <= checkOut) || (book.CheckIn >= checkIn && book.CheckOut <= checkOut))
{
return false;
}
}
return true;
}
static int Calculate(List<Book> bookList, Hotel hotel )
{
int total = 0;
for (int i = 0; i < bookList.Count; i++)
{
if (bookList[i].HotelNo.Equals(hotel.No))
{
int price = GetMoney(hotel.roomList, bookList[i].RoomNo);
total += price * (bookList[i].CheckOut) - bookList[i].CheckIn;
}
}
return total;
}
static int GetMoney(List<Room> roomList, string roomNo)
{
for (int i = 0; i < roomList.Count; i++)
{
if (roomList[i].No.Equals(roomNo))
{
return roomList[i].Price;
}
}
return 0;
}
static void Statistic(List<Book> bookList, List<Hotel> hotelList)
{
for (int i = 0; i < hotelList.Count; i++)
{
int total = Calculate(bookList, hotelList[i]);
Console.WriteLine("{0}. {1} - Doanh Thu : {2}", i + 1, hotelList[i].Name, total);
}
}
static void Search(List<Book> bookList, List<Hotel> hotelList)
{
Console.WriteLine("Nhap CMTND Can Tim Kiem:");
string cmtnd = Console.ReadLine();
for (int i = 0; i < bookList.Count; i++)
{
if (bookList[i].Equals(cmtnd))
{
Hotel hotel = GetHotelByNo(hotelList, bookList[i].HotelNo);
if (hotel!=null)
{
hotel.DisplayBase();
}
}
}
}
static Hotel GetHotelByNo(List<Hotel> hotelList, string hotelNo)
{
for (int i = 0; i < hotelList.Count; i++)
{
if (hotelList[i].No.Equals(hotelNo))
{
return hotelList[i];
}
}
return null;
}
static void showMenu()
{
Console.WriteLine("1.Nhap Thong Tin Khach San");
Console.WriteLine("2.Hien Thi Thong Tin Khach San");
Console.WriteLine("3.Dat Phong");
Console.WriteLine("4.Tim Phong Con Trong");
Console.WriteLine("5.Thong Ke Doanh Thu");
Console.WriteLine("6.Tim Kiem Thong Tin Khach Hang");
Console.WriteLine("7.Thoat!!!");
Console.WriteLine("Lua Chon:");
}
}
}
#Room.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Hotel
{
class Room
{
public string Name { get; set; }
public int Price { get; set; }
public int Floor { get; set; }
public int PersonalMax { get; set; }
public string No { get; set; }
public Room()
{
}
public Room(string Name, int Price, int Floor, int PersonalMax, string No)
{
this.Name = Name;
this.Price = Price;
this.Floor = Floor;
this.PersonalMax = PersonalMax;
this.No = No;
}
public void Input()
{
Console.WriteLine("Nhap Ten Phong:");
Name = Console.ReadLine();
Console.WriteLine("Nhap Gia:");
Price = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Nhap So Tang:");
Floor = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Nhap So Nguoi Toi Da:");
PersonalMax = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Nhap Ma Phong:");
No = Console.ReadLine();
}
public void Display()
{
Console.WriteLine("Room (Ten Phong : {0}, Gia Phong : {1}, So Tang : {2}, So Nguoi Toi Da : {3}, Ma Phong : {4} )", Name, Price, Floor, PersonalMax, No);
}
}
}
Nguyễn đình quân
2021-05-24 09:37:18
private void button8_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 2;
}
private void button9_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 1;
}
private void button13_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 3;
}
private void button3_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 6;
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 5;
}
private void button10_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 4;
}
private void button6_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 9;
}
private void button7_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 8;
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 7;
}
private void button5_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 0;
}
private void button16_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 0 + 0;
}
private void btnPlus_Click(object sender, EventArgs e)
{
num1 = float.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 2;
}
private void btnminus_Click(object sender, EventArgs e)
{
if (textBox1.Text != "")
{
num1 = float.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 1;
}
}
private void btnmultiply_Click(object sender, EventArgs e)
{
num1 = float.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 3;
}
private void btndivide_Click(object sender, EventArgs e)
{
num1 = float.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 4;
}
private void btnequal_Click(object sender, EventArgs e)
{
compute(count);
}
public void compute(int count)
{
switch (count)
{
case 1:
ans = num1 - float.Parse(textBox1.Text);
textBox1.Text = ans.ToString();
break;
case 2:
ans = num1 + float.Parse(textBox1.Text);
textBox1.Text = ans.ToString();
break;
case 3:
ans = num1 * float.Parse(textBox1.Text);
textBox1.Text = ans.ToString();
break;
case 4:
ans = num1 / float.Parse(textBox1.Text);
textBox1.Text = ans.ToString();
break;
default:
break;
}
}
private void btnC_Click(object sender, EventArgs e)
{
textBox1.Clear();
count = 0;
}
private void button15_Click(object sender, EventArgs e)
{
int c = textBox1.TextLength;
int flag = 0;
string text = textBox1.Text;
for (int i = 0; i < c; i++)
{
if (text[i].ToString() == ".")
{
flag = 1; break;
}
else
{
flag = 0;
}
}
if (flag == 0)
{
textBox1.Text = textBox1.Text + ".";
}
}
public Form1()
{
InitializeComponent();
}
float num1, ans;
int count;
Trần Ngọc Hải
2020-06-05 06:15:02
using HCNinterface;
using System;
using System.Collections.Generic;
using System.Text;
namespace RectangleInterface
{
class Program : Rectangle
{
static public void Main(String[] args)
{
int N;
Console.WriteLine("Moi nhap vao so hinh chu nhat :");
N = int.Parse(Console.ReadLine());
Rectangle[] reclist = new Rectangle[N];
foreach (Rectangle Rectangle in reclist)
{
float cd, cr;
Console.WriteLine("Chieudai la :");
cd = float.Parse(Console.ReadLine());
Console.WriteLine("Chieurong la :");
cr = float.Parse(Console.ReadLine());
Rectangle.setDaiRong(cd,
cr);
}
foreach (Rectangle rectangle in reclist)
{
Console.WriteLine("Chieu dai :{0}", rectangle.getChieuDai());
Console.WriteLine("Chieu rong :{0}", rectangle.getChieuRong());
Console.WriteLine("Dien tich :{0}", rectangle.dientichHCN());
}
float max = 0;
int a = 0;
for (int i = 0; i < N; i++)
{
float dientich = reclist[i].dientichHCN();
if (dientich > max)
{
max = dientich;
a++;
}
}
Console.WriteLine("Dien tich max : {0} , có chiều dài : {1} , chiều rộng {2} ", max, reclist[a].getChieuDai(), reclist[a].getChieuRong());
}
}
}
HCNinterface.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace HCNinterface
{
interface HCNInterface
{
float dientichHCN();
float getChieuDai();
float getChieuRong();
void setDaiRong(float cd, float cr);
}
}
Rectangle.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace HCNinterface
{
class Rectangle : HCNInterface
{
float chieudai { get; set; }
float chieurong { get; set; }
public Rectangle()
{
}
public float dientichHCN()
{
return chieudai * chieurong;
}
public float getChieuDai()
{
return chieudai;
}
public float getChieuRong()
{
return chieurong;
}
public void setDaiRong(float cd, float cr)
{
chieudai = cd;
chieurong = cr;
}
}
}
Đề bài : https://gokisoft.com/java-basic-oop-interface-hinh-chu-nhat-trong-java.html
NguyenHuuThanh
2020-06-05 05:49:20
private void button8_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 2;
}
private void button9_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 1;
}
private void button13_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 3;
}
private void button3_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 6;
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 5;
}
private void button10_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 4;
}
private void button6_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 9;
}
private void button7_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 8;
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 7;
}
private void button5_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 0;
}
private void button16_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 0 + 0;
}
private void btnPlus_Click(object sender, EventArgs e)
{
num1 = float.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 2;
}
private void btnminus_Click(object sender, EventArgs e)
{
if (textBox1.Text != "")
{
num1 = float.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 1;
}
}
private void btnmultiply_Click(object sender, EventArgs e)
{
num1 = float.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 3;
}
private void btndivide_Click(object sender, EventArgs e)
{
num1 = float.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 4;
}
private void btnequal_Click(object sender, EventArgs e)
{
compute(count);
}
public void compute(int count)
{
switch (count)
{
case 1:
ans = num1 - float.Parse(textBox1.Text);
textBox1.Text = ans.ToString();
break;
case 2:
ans = num1 + float.Parse(textBox1.Text);
textBox1.Text = ans.ToString();
break;
case 3:
ans = num1 * float.Parse(textBox1.Text);
textBox1.Text = ans.ToString();
break;
case 4:
ans = num1 / float.Parse(textBox1.Text);
textBox1.Text = ans.ToString();
break;
default:
break;
}
}
private void btnC_Click(object sender, EventArgs e)
{
textBox1.Clear();
count = 0;
}
private void button15_Click(object sender, EventArgs e)
{
int c = textBox1.TextLength;
int flag = 0;
string text = textBox1.Text;
for (int i = 0; i < c; i++)
{
if (text[i].ToString() == ".")
{
flag = 1; break;
}
else
{
flag = 0;
}
}
if (flag == 0)
{
textBox1.Text = textBox1.Text + ".";
}
}
public Form1()
{
InitializeComponent();
}
float num1, ans;
int count;
Lê Minh Bắc
2020-06-04 18:08:09
using System;
using System.Collections.Generic;
using System.Text;
namespace AssignmentConsole
{
class Hotel
{
public static int chosse;
public string name { get; set; }
public string address { get; set; }
public string Rank { get; set; }
public List<Room> rooms { get; set; }
public string hotelID { get; set; }
public Hotel()
{
rooms = new List<Room>();
}
public void input(List<string> ids)
{
inputHotelID(ids);
input(hotelID, ids);
}
public void input(string hotelID, List<string> ids)
{
inputHotelName();
inputHotelAddress();
rankHotel();
inputRoom(rooms, ids);
this.hotelID = hotelID;
}
private void inputHotelID(List<string> vs)
{
bool ischeck = false;
for (; ischeck == false;)
{
Console.Write("Nhập Mã Khách Sạn: ");
hotelID = Console.ReadLine();
foreach (string str in vs)
{
if (hotelID.Equals(str))
{
Console.WriteLine("Mã khách sạn đã tồn tại!!");
ischeck = true;
break;
}
}
if (!ischeck && string.IsNullOrEmpty(hotelID) == false)
{
vs.Add(hotelID);
ischeck = true;
break;
}
else
{
Console.WriteLine("Lỗi, mời nhập lại!!");
ischeck = false;
}
}
}
private void inputHotelName()
{
bool ischeck = true;
while (ischeck)
{
Console.Write("Nhập tên khách sạn: ");
name = Console.ReadLine();
if (string.IsNullOrEmpty(name) == false)
{
ischeck = false;
}
else
{
Console.WriteLine("Tên Khách Sạn không được để trống!!");
}
}
}
private void inputHotelAddress()
{
bool ischeck = true;
while (ischeck)
{
Console.Write("Nhập địa chỉ: ");
address = Console.ReadLine();
if (string.IsNullOrEmpty(address) == false)
{
ischeck = false;
}
else
{
Console.WriteLine("Địa Chỉ không được để trống!!");
}
}
}
public void display()
{
Console.WriteLine("Tên Khách Sạn: {0}\nĐịa chỉ: {1}\nLoại KS: {2}\nMã Khách Sạn: {3} ", name, address, Rank, hotelID);
Console.WriteLine("Danh sách phòng: ");
foreach (var item in rooms)
{
item.display();
}
Console.WriteLine("------------------------------------------------------------");
}
private void inputRoom(List<Room> rooms, List<string> ids)
{
Console.WriteLine("Thiết lập danh sách phòng: ");
for (; ; )
{
Room room = new Room();
room.input(ids);
rooms.Add(room);
Console.WriteLine("Tiếp tục thêm phòng: (y/n)");
string option = Console.ReadLine();
if (option.ToLower().Equals("n"))
{
break;
}
}
}
private void rankHotel()
{
bool checkDK = true;
while (checkDK)
{
Console.WriteLine("1.VIP");
Console.WriteLine("2.Bình Dân");
checkChosse();
switch (chosse)
{
case 1:
Rank = "VIP";
checkDK = false;
break;
case 2:
Rank = "Bình Dân";
checkDK = false;
break;
default:
Console.WriteLine("Lỗi, mời chọn lại !! ");
break;
}
}
}
private static void checkChosse()
{
bool isName = true;
while (isName)
{
string str;
Console.Write("Chọn: ");
str = Console.ReadLine();
if (String.IsNullOrEmpty(str))
{
Console.WriteLine("Lựa chọn không được để trống!!!");
}
else
{
if (check(str))
{
chosse = int.Parse(str);
if (chosse > 0)
{
isName = false;
}
else
{
Console.WriteLine("Lựa chọn phải lớn hơn 0");
}
}
else
{
Console.WriteLine("Lựa chọn không được nhập chữ!! ");
}
}
}
}
static bool check(string s)
{
bool checkk = false;
foreach (char item in s)
{
if (item >= 48 && item <= 57)
{
checkk = true;
}
}
return checkk;
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace AssignmentConsole
{
class Customer
{
public static int chosse;
public string Cmnd { get; set; }
public string Name { get; set; }
public string Gender { get; set; }
public string Address { get; set; }
public int Age { get; set; }
public Customer()
{
}
public Customer(string Cmnd, string Name, int Age, string Gender, string Address)
{
this.Address = Address;
this.Age = Age;
this.Cmnd = Cmnd;
this.Gender = Gender;
this.Name = Name;
}
public void input(List<string> vs)
{
inputCmnd(vs);
input(Cmnd);
}
public void input(string Cmnd)
{
this.Cmnd = Cmnd;
inputName();
inputAge();
inputGender();
inputaddress();
}
private void inputAge()
{
bool ischeck = true;
while (ischeck)
{
Console.Write("Nhập Tuổi:");
string c2 = Console.ReadLine();
if (checkInt(c2) && string.IsNullOrEmpty(c2) == false)
{
Age = int.Parse(c2);
ischeck = false;
break;
}
else
{
Console.WriteLine("Lỗi, mời nhập lại !!");
}
}
}
bool checkInt(string s)
{
bool check = true;
foreach (char item in s)
{
if (item < 48 || item > 57)
{
check = false;
break;
}
}
return check;
}
private void inputCmnd(List<string> vs)
{
bool ischeck = false;
for (; ischeck == false;)
{
Console.Write("Nhập CMND: ");
Cmnd = Console.ReadLine();
foreach (string str in vs)
{
if (Cmnd.Equals(str))
{
Console.WriteLine("CMND đã tồn tại!!");
ischeck = true;
break;
}
}
if (!ischeck && string.IsNullOrEmpty(Cmnd) == false)
{
vs.Add(Cmnd);
ischeck = true;
break;
}
else
{
Console.WriteLine("Lỗi, mời nhập lại !!");
ischeck = false;
}
}
}
private void inputGender()
{
bool ischeck = true;
while (ischeck)
{
Console.Write("Nhập giới tính: ");
Gender = Console.ReadLine();
if (string.IsNullOrEmpty(Gender) == false)
{
ischeck = false;
}
}
}
private void inputaddress()
{
bool ischeck = true;
while (ischeck)
{
Console.Write("Nhập địa chỉ: ");
Address = Console.ReadLine();
if (string.IsNullOrEmpty(Address) == false)
{
ischeck = false;
}
}
}
private void inputName()
{
bool ischeck = true;
while (ischeck)
{
Console.Write("Nhập tên: ");
Name = Console.ReadLine();
if (string.IsNullOrEmpty(Name) == false)
{
ischeck = false;
}
}
}
public void display()
{
Console.WriteLine("CMND: {0}\nFullname: {1}\nAge: {2}\nGender: {3}\nAddress: {4}", Cmnd, Name, Age, Gender, Address);
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace AssignmentConsole
{
class Booking
{
public DateTime Checkin { get; set; }
public DateTime Checkout { get; set; }
public string Cmnd { get; set; }
public string HotelID { get; set; }
public string RoomCode { get; set; }
public Booking()
{
}
public void display()
{
Console.WriteLine("Ngày Đặt Phòng: {0}\nNgày Trả Phòng: {1}\nCMND: {2}\nMã Khách Sạn: {3}\nMã Phòng: {4}", Checkin, Checkout, Cmnd, HotelID, RoomCode);
}
public void input(List<Hotel> hotels, List<Customer> customers, List<string> ids)
{
string strDatetime = null;
while (string.IsNullOrEmpty(strDatetime))
{
Console.WriteLine("Ngày Đặt Phòng (dd/mm/YYYY): ");
strDatetime = Console.ReadLine();
Checkin = DateTime.ParseExact(strDatetime, "dd/MM/yyyy", null);
}
strDatetime = null;
while (string.IsNullOrEmpty(strDatetime))
{
Console.WriteLine("Ngày Trả Phòng (dd/mm/YYYY): ");
strDatetime = Console.ReadLine();
Checkout = DateTime.ParseExact(strDatetime, "dd/MM/yyyy", null);
}
inputCMND(customers);
inputHotelID(hotels, ids);
}
private void inputCMND(List<Customer> customers)
{
bool dk = false;
Console.WriteLine("Nhập CMND: ");
string find = Console.ReadLine();
foreach (var item in customers)
{
if (find.Equals(item.Cmnd))
{
Cmnd = find;
dk = true;
break;
}
}
if (!dk)
{
Console.WriteLine("Nhập thông tin Khách Hàng");
Customer customer = new Customer();
customer.input(find);
customers.Add(customer);
Cmnd = customer.Cmnd;
}
}
private void inputHotelID(List<Hotel> hotels, List<string> ids)
{
bool dk = false;
Console.WriteLine("Nhập Mã Khách Sạn: ");
string find = Console.ReadLine();
foreach (var item in hotels)
{
if (find.Equals(item.hotelID))
{
HotelID = find;
dk = true;
break;
}
}
if (!dk)
{
Console.WriteLine("Nhập thông tin Khách Sạn : ");
Hotel hotel = new Hotel();
hotel.input(ids);
HotelID = hotel.hotelID;
hotels.Add(hotel);
}
foreach (var item in hotels)
{
if (HotelID.Equals(item.hotelID))
{
findRoom(item);
}
}
}
private void findRoom(Hotel hotel)
{
bool checkDK = true;
while (checkDK)
{
foreach (Room item in hotel.rooms)
{
item.display();
}
Console.WriteLine("Nhập Mã Phòng muốn đặt: ");
string check;
check = Console.ReadLine();
foreach (Room item in hotel.rooms)
{
if (check.Equals(item.roomCode))
{
RoomCode = check;
checkDK = false;
break;
}
}
if (checkDK)
{
Console.WriteLine("Mã Phòng Sai !!");
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace AssignmentConsole
{
class hotelModify
{
public hotelModify()
{
}
public void addHotel(List<Hotel> hotels, List<string> ids)
{
Hotel hotel = new Hotel();
hotel.input(ids);
hotels.Add(hotel);
}
public void editHotel(List<Hotel> hotels, List<string> ids)
{
bool ischeck = true;
while (ischeck)
{
Console.Write("Nhập mã khách sạn cần sủa thông tin: ");
string str = Console.ReadLine();
bool isCheck = false;
foreach (Hotel hotel in hotels)
{
if (str.Equals(hotel.hotelID))
{
hotel.input(str, ids);
ischeck = false;
isCheck = true;
break;
}
}
if (!isCheck)
{
Console.WriteLine("Mã khách sạn không tồn tại !!");
}
}
}
public void deleteCustomer(List<Hotel> hotels, List<string> ids)
{
bool ischeck = true;
while (ischeck)
{
Console.Write("Nhập Mã Khách Sạn muốn xóa: ");
string str = Console.ReadLine();
bool isCheck = false;
foreach (Hotel hotel in hotels)
{
if (str.Equals(hotel.hotelID))
{
hotels.Remove(hotel);
ischeck = false;
isCheck = true;
break;
}
}
if (!isCheck)
{
Console.WriteLine("Mã Khách Sạn không tồn tại !!");
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace AssignmentConsole
{
class CustomerModify
{
public CustomerModify()
{
}
public void addCustomer(List<Customer> customers, List<string> ids)
{
Customer customer = new Customer();
customer.input(ids);
customers.Add(customer);
}
public void editCustomer(List<Customer> customers)
{
bool ischeck = true;
while (ischeck)
{
Console.Write("Nhập mã khách hàng cần sửa: ");
string str = Console.ReadLine();
bool isCheck = false;
foreach (Customer cus in customers)
{
if (str.Equals(cus.Cmnd))
{
cus.input(str);
ischeck = false;
isCheck = true;
break;
}
}
if (!isCheck)
{
Console.WriteLine("Mã khách hàng không tồn tại !!");
}
}
}
public void deleteCustomer(List<Customer> customers)
{
bool ischeck = true;
while (ischeck)
{
Console.WriteLine("Nhập mã khách hàng muốn xóa: ");
string str = Console.ReadLine();
bool isCheck = false;
foreach (Customer cus in customers)
{
if (str.Equals(cus.Cmnd))
{
customers.Remove(cus);
ischeck = false;
isCheck = true;
break;
}
}
if (!isCheck)
{
Console.WriteLine("Mã khách hàng không tồn tại !!");
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace AssignmentConsole
{
class Room
{
public string roomName { get; set; }
public int floorNumber { get; set; }
public int maxPerson { get; set; }
public int price { get; set; }
public string roomCode { get; set; }
public Room()
{
}
public Room(string roomName, int floorNumber, int maxPerson, int price, string roomCode)
{
this.floorNumber = floorNumber;
this.maxPerson = maxPerson;
this.price = price;
this.roomCode = roomCode;
this.roomName = roomName;
}
public void input(List<string> vs)
{
inputRoomName();
inputfloorNumber();
inputmaxPerson();
inputprice();
inputRoomCode(vs);
}
private void inputfloorNumber()
{
bool ischeck = true;
while (ischeck)
{
Console.Write("Tầng: ");
string c2 = Console.ReadLine();
if (checkInt(c2) && string.IsNullOrEmpty(c2) == false)
{
floorNumber = int.Parse(c2);
ischeck = false;
break;
}
else
{
Console.WriteLine("Lỗi, mời nhập lại !!");
}
}
}
private void inputmaxPerson()
{
bool ischeck = true;
while (ischeck)
{
Console.Write("Số người tối đa: ");
string c2 = Console.ReadLine();
if (checkInt(c2) && string.IsNullOrEmpty(c2) == false)
{
maxPerson = int.Parse(c2);
ischeck = false;
break;
}
else
{
Console.WriteLine("Lỗi, mời nhập lại !!");
}
}
}
private void inputprice()
{
bool ischeck = true;
while (ischeck)
{
Console.WriteLine("Giá phòng (1 ngày): ");
string c2 = Console.ReadLine();
if (checkInt(c2) && string.IsNullOrEmpty(c2) == false)
{
price = int.Parse(c2);
ischeck = false;
break;
}
else
{
Console.WriteLine("Lỗi, mời nhập lại !!");
}
}
}
bool checkInt(string s)
{
bool check = true;
foreach (char item in s)
{
if (item < 48 || item > 57)
{
check = false;
break;
}
}
return check;
}
private void inputRoomCode(List<string> vs)
{
bool ischeck = false;
for (; ischeck == false;)
{
Console.Write("Nhập mã phòng: ");
roomCode = Console.ReadLine();
foreach (string str in vs)
{
if (roomCode.Equals(str))
{
Console.WriteLine("Mã phòng đã tồn tại !!");
ischeck = true;
break;
}
}
if (!ischeck && string.IsNullOrEmpty(roomCode) == false)
{
vs.Add(roomCode);
ischeck = true;
break;
}
else
{
Console.WriteLine("Lỗi, mời nhập lại !!");
ischeck = false;
}
}
}
private void inputRoomName()
{
bool ischeck = true;
while (ischeck)
{
Console.Write("Nhập tên phòng: ");
roomName = Console.ReadLine();
if (string.IsNullOrEmpty(roomName) == false)
{
ischeck = false;
}
else
{
Console.WriteLine("Tên phòng không được để trống !!");
ischeck = false;
}
}
}
public void display()
{
Console.WriteLine("roomName : {0} , numberFloor : {1} , maxPerson : {2} , Price : {3} , roomCode : {4}", roomName, floorNumber, maxPerson, price, roomCode);
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace AssignmentConsole
{
class Management
{
List<Booking> bookings = new List<Booking>();
List<Hotel> hotels = new List<Hotel>();
List<Customer> customers = new List<Customer>();
List<string> ids = new List<string>();
public static int chosse;
public Management()
{
}
public void Searching()
{
do
{
menuSearch();
checkChosse();
switch (chosse)
{
case 1:
Console.Write("Nhập Mã Khách Sạn cần tìm: ");
string str = Console.ReadLine();
bool isCheck = false;
foreach (var item in hotels)
{
if (item.hotelID.Equals(str))
{
item.display();
isCheck = true;
break;
}
}
if (!isCheck)
{
Console.WriteLine("Khách Sạn Không Tồn Tại !!");
}
break;
case 2:
Console.WriteLine("Mã Khách Hàng cần tìm: ");
str = Console.ReadLine();
isCheck = false;
foreach (var item in customers)
{
if (item.Cmnd.Equals(str))
{
item.display();
isCheck = true;
break;
}
}
if (!isCheck)
{
Console.WriteLine("Khách Hàng Không Tồn Tại !!");
}
break;
case 3:
Console.Write("Nhập Mã Phòng cần tìm: ");
str = Console.ReadLine();
isCheck = false;
foreach (var item in hotels)
{
if (item.hotelID.Equals(str))
{
foreach (Room room in item.rooms)
{
room.display();
}
isCheck = true;
break;
}
}
if (!isCheck)
{
Console.WriteLine("Khách Sạn không tồn tại !!");
}
break;
case 4:
Console.WriteLine("Thoát !!");
break;
default:
Console.WriteLine("Lỗi, mời nhập lại !!");
break;
}
} while (chosse != 4);
}
public void book()
{
do
{
menuBooking();
checkChosse();
switch (chosse)
{
case 1:
Booking booking = new Booking();
booking.input(hotels, customers, ids);
bookings.Add(booking);
break;
case 2:
foreach (var item in bookings)
{
item.display();
}
break;
case 3:
showRoomByDate(bookings, hotels);
break;
case 4:
Console.WriteLine("Thoát !!");
break;
default:
Console.WriteLine("Lỗi, mời nhập lại !!");
break;
}
} while (chosse != 4);
}
public void showRoomByDate(List<Booking> books, List<Hotel> hotels)
{
if (hotels.Count == 0)
{
Console.WriteLine("Không có dữ liệu!!!");
return;
}
Hotel currentHotel = null;
for (; ; )
{
foreach (Hotel hotel in hotels)
{
Console.WriteLine("Mã Khách Sạn: {0}\nTên Khách Sạn: {1}", hotel.hotelID, hotel.name);
}
Console.Write("Nhập Mã Khách Sạn: ");
string hotelID = Console.ReadLine();
foreach (Hotel hotel in hotels)
{
if (hotel.hotelID.Equals(hotelID))
{
currentHotel = hotel;
break;
}
}
if (currentHotel != null)
{
break;
}
Console.WriteLine("(Không tìm thấy) Mời nhập lại: ");
}
if (currentHotel.rooms.Count == 0)
{
Console.WriteLine("Không có dữ liệu!!!");
return;
}
Console.WriteLine("Ngày CheckIn (dd/mm/YYYY): ");
string dateTime = Console.ReadLine();
DateTime CheckIn = DateTime.ParseExact(dateTime, "dd/MM/yyyy", null);
Console.WriteLine("Ngày CheckOut (dd/mm/YYYY): ");
dateTime = Console.ReadLine();
DateTime CheckOut = DateTime.ParseExact(dateTime, "dd/MM/yyyy", null);
foreach (var room in currentHotel.rooms)
{
List<Booking> currentBooking = new List<Booking>();
foreach (var book in books)
{
if (book.HotelID.Equals(currentHotel.hotelID) && book.RoomCode.Equals(room.roomCode))
{
currentBooking.Add(book);
}
}
bool isFind = false;
foreach (var book in currentBooking)
{
if (DateTime.Compare(book.Checkin, CheckOut) > 0 || DateTime.Compare(book.Checkout, CheckIn) < 0)
{
//room dat yeu cau
}
else
{
isFind = true;
break;
}
}
if (!isFind)
{
Console.WriteLine("Mã Phòng: {0}\nTên Phòng: {1}", room.roomCode, room.roomName);
}
}
}
public void Customer()
{
CustomerModify customerModify = new CustomerModify();
do
{
menuCustomer();
checkChosse();
switch (chosse)
{
case 1:
customerModify.addCustomer(customers, ids);
break;
case 2:
customerModify.editCustomer(customers);
break;
case 3:
customerModify.deleteCustomer(customers);
break;
case 4:
Console.WriteLine("Thoát !!");
break;
default:
Console.WriteLine("Lỗi, mời nhập lại !!");
break;
}
} while (chosse != 4);
}
public void Hotel()
{
hotelModify hotelModify = new hotelModify();
do
{
menuHotel();
checkChosse();
switch (chosse)
{
case 1:
hotelModify.addHotel(hotels, ids);
break;
case 2:
hotelModify.editHotel(hotels, ids);
break;
case 3:
hotelModify.deleteCustomer(hotels, ids);
break;
case 4:
Console.WriteLine("Thoát !!");
break;
default:
Console.WriteLine("Lỗi, mời nhập lại !!");
break;
}
} while (chosse != 4);
}
private void menuHotel()
{
Console.WriteLine("1.Thêm Khách Sạn");
Console.WriteLine("2.Sửa Khách Sạn");
Console.WriteLine("3.Xóa Khách Sạn");
Console.WriteLine("4.Thoát!!");
}
private void menuCustomer()
{
Console.WriteLine("1.Thêm Khách Hàng");
Console.WriteLine("2.Sửa Thông Tin Khách Hàng");
Console.WriteLine("3.Xóa Khách Hàng");
Console.WriteLine("4.Thoát !");
}
private void menuBooking()
{
Console.WriteLine("1.Đặt Phòng");
Console.WriteLine("2.Xem Danh Sách Đặt Phòng");
Console.WriteLine("3.Xem Danh Sách Phòng Có Sẵn");
Console.WriteLine("4.Thoát !");
}
private void menuSearch()
{
Console.WriteLine("1.Tìm Khách Sạn");
Console.WriteLine("2.Tìm Khách Hàng");
Console.WriteLine("3.Tìm Phòng");
Console.WriteLine("4.Thoát !");
}
private static void checkChosse()
{
bool isName = true;
while (isName)
{
string str;
Console.Write("Chọn: ");
str = Console.ReadLine();
if (String.IsNullOrEmpty(str))
{
Console.WriteLine("Lựa chọn không được để trống!!!");
}
else
{
if (check(str))
{
chosse = int.Parse(str);
if (chosse > 0)
{
isName = false;
}
else
{
Console.WriteLine("Lựa chọn phải lớn hơn 0");
}
}
else
{
Console.WriteLine("Lựa chọn không được nhập chữ!! ");
}
}
}
}
static bool check(string s)
{
bool checkk = false;
foreach (char item in s)
{
if (item >= 48 && item <= 57)
{
checkk = true;
}
}
return checkk;
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace AssignmentConsole
{
class Program
{
public static int chosse;
static void Main(string[] args)
{
Console.InputEncoding = Encoding.UTF8;
Console.OutputEncoding = Encoding.UTF8;
Management management = new Management();
int c;
do
{
menu();
checkChosse();
switch (chosse)
{
case 1:
management.Hotel();
break;
case 2:
management.Customer();
break;
case 3:
management.book();
break;
case 4:
management.Searching();
break;
case 5:
Console.WriteLine("Thoát !!");
break;
default:
Console.WriteLine("Lỗi, mời nhập lại !!");
break;
}
} while (chosse != 5);
}
static void menu()
{
Console.WriteLine("1.Quản Lý Khách Sạn");
Console.WriteLine("2.Quản Lý Khách Hàng");
Console.WriteLine("3.Quản Lý Đặt Phòng");
Console.WriteLine("4.Tìm Kiếm");
Console.WriteLine("5.Thoát !");
}
private static void checkChosse()
{
bool isName = true;
while (isName)
{
string str;
Console.Write("Chọn: ");
str = Console.ReadLine();
if (String.IsNullOrEmpty(str))
{
Console.WriteLine("Lựa chọn không được để trống!!!");
}
else
{
if (check(str))
{
chosse = int.Parse(str);
if (chosse > 0)
{
isName = false;
}
else
{
Console.WriteLine("Lựa chọn phải lớn hơn 0");
}
}
else
{
Console.WriteLine("Lựa chọn không được nhập chữ!! ");
}
}
}
}
static bool check(string s)
{
bool checkk = false;
foreach (char item in s)
{
if (item >= 48 && item <= 57)
{
checkk = true;
}
}
return checkk;
}
}
}
Phạm Ngọc Minh
2020-06-04 13:34:55
https://github.com/dragonballsa/ASS/tree/master
Phạm Ngọc Minh
Trần Anh Quân
Đỗ tuấn anh
2020-06-04 12:43:21
em làm về sách viết bằng C# ạ
Đỗ tuấn anh
2020-06-04 12:40:04
em làm về sách ạ
program.cs
using System;
using System.Collections.Generic;
using library.Books;
namespace library
{
class Program
{
static void Main(string[] args)
{
List<author> authors = new List<author>();
List<producer> producers = new List<producer>();
List<book> books = new List<book>();
int choose;
do
{
ShowMenu();
choose = int.Parse(Console.ReadLine());
switch (choose) {
case 1:
Inputproducer(producers);
break;
case 2:
Inputauthor(authors);
break;
case 3:
Inputbook(books);
break;
case 4:
Displayproducer(producers);
break;
case 5:
Displayauthor(authors);
break;
case 6:
Displaybook(books);
break;
case 7:
Console.WriteLine("thoat!");
break ;
default:
Console.WriteLine("khong co du lieu!");
break;
}
} while (choose != 7);
}
static void Displayproducer(List<producer> producers)
{
foreach (producer producer in producers)
{
producer.Display();
}
}
static void Inputproducer(List<producer> producers)
{
producer producer = new producer();
producer.Input();
producers.Add(producer);
}
static void Inputauthor(List<author> authors)
{
author author = new author();
author.Input();
authors.Add(author);
}
static void Displayauthor(List<author> authors)
{
foreach (author author in authors)
{
author.Display();
}
}
static void Inputbook(List<book> books)
{
book book = new book();
book.Input();
books.Add(book);
}
static void Displaybook(List<book> books)
{
foreach (book book in books)
{
book.Display();
}
}
static void ShowMenu()
{
Console.WriteLine("1. Nhap thong tin nha san xuat!");
Console.WriteLine("2. Nhap thong tin tac gia!");
Console.WriteLine("3. Nhap thong tin sach can tim !");
Console.WriteLine("4. Hien thi thong tin nha san xuat!");
Console.WriteLine("5. Nhap thong hien thi thong tin tac gia !");
Console.WriteLine("6. Hien thi thong tin sach can tim !");
Console.WriteLine("7. Thoat");
Console.WriteLine("Choose : ");
}
}
}
author.cs
using System;
namespace library.Books
{
public class author
{
public string authorName { get; set; }
public string pseudonym { get; set; }
public string BirthDay { get; set; }
public author()
{
}
public void Input()
{
Console.WriteLine("Nhap ten tac gia :");
authorName = Console.ReadLine();
Console.WriteLine("nhap but danh:");
pseudonym = Console.ReadLine();
Console.WriteLine("Nhap ngay thang nam thanh lap (dd/mm/YYYY):");
BirthDay = Console.ReadLine();
}
public void Display()
{
Console.WriteLine("ten tac gia : {0},But danh {1} ngay sinh {2}", authorName, pseudonym,BirthDay);
}
}
}
producer.cs
using System;
using System.Collections.Generic;
namespace library.Books
{
public class producer
{
public string Manufacturers { get; set; }
public int Foundingday { get; set; }
public string Representative { get; set; }
public int Foundingyear { get; set; }
public List<producer> TitleList { get; set; }
public producer()
{
TitleList = new List<producer>();
}
public void Input()
{
Console.WriteLine("Nhap ten nha san xuat :");
Manufacturers = Console.ReadLine();
Console.WriteLine("Ngay thanh lap (DD): ");
Foundingday = int.Parse(Console.ReadLine());
Console.WriteLine("Nhap ten nguoi dai dien:");
Representative = Console.ReadLine();
Console.WriteLine("Nhap nam thanh lap (YYYY):");
Foundingyear = int.Parse(Console.ReadLine());
}
public void Display()
{
Console.WriteLine("ten nha san xuat : {0} ,Ngay thanh lap:{1},ten nguoi dai dien:{2},Nam thanh lap:{3}", Manufacturers, Foundingday , Representative,Foundingyear);
}
}
}
book.cs
using System;
namespace library.Books
{
public class book
{
public string pseudonymauthor { get; set; }
public string publishingcompany { get; set; }
public string booktitle { get; set; }
public book()
{
}
public void Input()
{
Console.WriteLine("Nhap but danh tac gia :");
pseudonymauthor = Console.ReadLine();
Console.WriteLine("Nhap Nha san xuat :");
publishingcompany = Console.ReadLine();
Console.WriteLine("Nhap ten sach :");
booktitle = Console.ReadLine();
}
public void Display()
{
Console.WriteLine("But danh tac gia : {0}, Nha san xuat :{1},Ten sach : {2}",
pseudonymauthor, publishingcompany, booktitle);
}
}
}