Advertisement
Guest User

question 2

a guest
Feb 28th, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3.  
  4. namespace ConsoleApplication2
  5. {
  6. class Program
  7. {
  8. static Hashtable BorrowedList = new Hashtable();
  9. static void Main(string[] args)
  10. {
  11. 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" };
  12. for (int i = 0; i < Books.Length; i++)
  13. {
  14. Console.WriteLine((i + 1) + "." + Books[i]);
  15. }
  16. while (true)
  17. {
  18. 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");
  19. int a = int.Parse(Console.ReadLine());
  20. if (a == 1)
  21. {
  22. Console.WriteLine("Write name of Book you want to borrow");
  23. string BorrowBook = Console.ReadLine();
  24. Console.WriteLine("enter Your Name");
  25. string Name = Console.ReadLine();
  26. if (BorrowedList.ContainsValue(Name))
  27. {
  28. if (BorrowedList.ContainsKey(BorrowBook))
  29. throw new ApplicationException("You already Have Borrowed this Book");
  30. }
  31. Borrow(BorrowBook, Name);
  32. }
  33. else if (a == 2)
  34. {
  35. Console.WriteLine("Write name of Book you want to return");
  36. string ReturnBook = Console.ReadLine();
  37. if (BorrowedList.ContainsKey(ReturnBook))
  38. {
  39. ReturnBook1(ReturnBook);
  40. }
  41. }
  42. else if (a == 3)
  43. {
  44. foreach (DictionaryEntry item in BorrowedList)
  45. {
  46. Console.WriteLine(item.Key + " " + item.Value);
  47. }
  48. }
  49. }
  50.  
  51. }
  52. static void Borrow(string BookName, string name)
  53. {
  54. BorrowedList.Add(BookName, name);
  55. }
  56. static void ReturnBook1(string BookName)
  57. {
  58. BorrowedList.Remove(BookName);
  59. }
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement