Guest User

Untitled

a guest
Oct 18th, 2017
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. class Book
  2.  
  3. {
  4. public string title { get; set; }
  5. public string Author { get; set; }
  6. public string publisher { get; set; }
  7. public int price { get; set; }
  8. public static string genre;
  9.  
  10. public override string ToString()
  11. {
  12. string output = String.Format("Title :{0} n Author :{1} n Publisher :{2} n Price {3}", this.title, this.Author, this.publisher, this.price);
  13. return output;
  14. }
  15.  
  16.  
  17. public static List<Book> myList = new List<Book>();
  18. private static void changegenre()
  19. {
  20. string mygenre = "Fantasy";
  21. genre = mygenre;
  22. }
  23.  
  24. static void Main(string[] args)
  25. {
  26. changegenre();
  27. myList.Add(new Book() { title = "Hobbit", Author = "J.R.R Tolkien", publisher = "U & G", price = 34, });
  28. myList.Add(new Book() { title = "Two Towers", Author = "J.R.R Tolkien", publisher = "U & G", price = 55 });
  29. myList.Add(new Book() { title = "Opowiesci z meekhanskiego pogranicza", Author = "Robert M. Wegner", publisher = "Powergraph", price = 10 });
  30. myList.Add(new Book() { title = "A Dance with Dragons", Author = "G.R.R Martin", publisher = "Voyager Books", price = 25 });
  31. Console.WindowWidth = 95;
  32. Console.BackgroundColor = ConsoleColor.DarkMagenta;
  33. Console.WriteLine(" --------Welcome to our bookstore!-------");
  34.  
  35. do
  36. {
  37.  
  38. Console.BackgroundColor = ConsoleColor.Black;
  39. Console.WriteLine("Please write: rn a = if you want to search book by author, rn p = if you want to search book by price, rn pub - if you want to search by publisher or rn t- if you want to search by title");
  40. string input = Console.ReadLine();
  41. switch (input)
  42. {
  43. case "a":
  44. searchbyauthor();
  45. break;
  46.  
  47. case "p":
  48. searchbyprice();
  49. break;
  50. case "pub":
  51. searchbypublisher();
  52. break;
  53. case "t":
  54. searchbytitle();
  55. break;
  56.  
  57.  
  58.  
  59. }
  60.  
  61.  
  62.  
  63.  
  64.  
  65. Console.WriteLine("Do you want to search again?");
  66. } while (Console.ReadLine().ToUpper() == "YES");
  67. }
  68.  
  69. private static void searchbytitle()
  70. {
  71. Console.WriteLine("Please, write book's title!");
  72. string input = Console.ReadLine();
  73. foreach (Book result in myList.Where(x => x.title == input).ToList())
  74. {
  75. Console.WriteLine(result);
  76.  
  77. }
  78. }
  79.  
  80. private static void searchbypublisher()
  81. {
  82. Console.WriteLine("Please, write publisher's name!");
  83. string input = Console.ReadLine();
  84. foreach (Book result in myList.Where(x => x.publisher == input).ToList())
  85. {
  86. Console.WriteLine(result);
  87.  
  88. }
  89. }
  90.  
  91. private static void searchbyprice()
  92. {
  93. Console.WriteLine("Please, give me the maximum book price");
  94. string input = Console.ReadLine();
  95. int maxprice = Convert.ToInt32(input);
  96. foreach (Book result in myList.Where(x => x.price <= maxprice).ToList())
  97. {
  98. Console.WriteLine(result);
  99. }
  100. }
  101.  
  102. private static void searchbyauthor()
  103.  
  104. {
  105. Console.WriteLine("Please, write author's name!");
  106. string input = Console.ReadLine();
  107. foreach (Book result in myList.Where(x => x.Author== input).ToList())
  108. {
  109. Console.WriteLine(result);
  110.  
  111. }
  112. }
  113.  
  114. }
Add Comment
Please, Sign In to add comment