Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- namespace ConsoleApplication2
- {
- class Program
- {
- static Hashtable BorrowedList = new Hashtable();
- static void Main(string[] args)
- {
- string[] Books = new string[] { "Hunger games", "The Vinci Code", "The Secret of the Nagas", "The Immortals of Meluha", "Angles And Demons", "Two States", "Half Life", "Harry Potter and the Philosopher's Stone" };
- for (int i = 0; i < Books.Length; i++)
- {
- Console.WriteLine((i + 1) + "." + Books[i]);
- }
- while (true)
- {
- Console.WriteLine("enter 1 if you want to Borrow a Book \nEnter 2 if you want to return a book \n Enter 3 if you want to check Borrwed List");
- int a = int.Parse(Console.ReadLine());
- if (a == 1)
- {
- Console.WriteLine("Write name of Book you want to borrow");
- string BorrowBook = Console.ReadLine();
- Console.WriteLine("enter Your Name");
- string Name = Console.ReadLine();
- if (BorrowedList.ContainsValue(Name))
- {
- if (BorrowedList.ContainsKey(BorrowBook))
- throw new ApplicationException("You already Have Borrowed this Book");
- }
- Borrow(BorrowBook, Name);
- }
- else if (a == 2)
- {
- Console.WriteLine("Write name of Book you want to return");
- string ReturnBook = Console.ReadLine();
- if (BorrowedList.ContainsKey(ReturnBook))
- {
- ReturnBook1(ReturnBook);
- }
- }
- else if (a == 3)
- {
- foreach (DictionaryEntry item in BorrowedList)
- {
- Console.WriteLine(item.Key + " " + item.Value);
- }
- }
- }
- }
- static void Borrow(string BookName, string name)
- {
- BorrowedList.Add(BookName, name);
- }
- static void ReturnBook1(string BookName)
- {
- BorrowedList.Remove(BookName);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement