Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Book
- {
- public string title { get; set; }
- public string Author { get; set; }
- public string publisher { get; set; }
- public int price { get; set; }
- public static string genre;
- public override string ToString()
- {
- string output = String.Format("Title :{0} n Author :{1} n Publisher :{2} n Price {3}", this.title, this.Author, this.publisher, this.price);
- return output;
- }
- public static List<Book> myList = new List<Book>();
- private static void changegenre()
- {
- string mygenre = "Fantasy";
- genre = mygenre;
- }
- static void Main(string[] args)
- {
- changegenre();
- myList.Add(new Book() { title = "Hobbit", Author = "J.R.R Tolkien", publisher = "U & G", price = 34, });
- myList.Add(new Book() { title = "Two Towers", Author = "J.R.R Tolkien", publisher = "U & G", price = 55 });
- myList.Add(new Book() { title = "Opowiesci z meekhanskiego pogranicza", Author = "Robert M. Wegner", publisher = "Powergraph", price = 10 });
- myList.Add(new Book() { title = "A Dance with Dragons", Author = "G.R.R Martin", publisher = "Voyager Books", price = 25 });
- Console.WindowWidth = 95;
- Console.BackgroundColor = ConsoleColor.DarkMagenta;
- Console.WriteLine(" --------Welcome to our bookstore!-------");
- do
- {
- Console.BackgroundColor = ConsoleColor.Black;
- 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");
- string input = Console.ReadLine();
- switch (input)
- {
- case "a":
- searchbyauthor();
- break;
- case "p":
- searchbyprice();
- break;
- case "pub":
- searchbypublisher();
- break;
- case "t":
- searchbytitle();
- break;
- }
- Console.WriteLine("Do you want to search again?");
- } while (Console.ReadLine().ToUpper() == "YES");
- }
- private static void searchbytitle()
- {
- Console.WriteLine("Please, write book's title!");
- string input = Console.ReadLine();
- foreach (Book result in myList.Where(x => x.title == input).ToList())
- {
- Console.WriteLine(result);
- }
- }
- private static void searchbypublisher()
- {
- Console.WriteLine("Please, write publisher's name!");
- string input = Console.ReadLine();
- foreach (Book result in myList.Where(x => x.publisher == input).ToList())
- {
- Console.WriteLine(result);
- }
- }
- private static void searchbyprice()
- {
- Console.WriteLine("Please, give me the maximum book price");
- string input = Console.ReadLine();
- int maxprice = Convert.ToInt32(input);
- foreach (Book result in myList.Where(x => x.price <= maxprice).ToList())
- {
- Console.WriteLine(result);
- }
- }
- private static void searchbyauthor()
- {
- Console.WriteLine("Please, write author's name!");
- string input = Console.ReadLine();
- foreach (Book result in myList.Where(x => x.Author== input).ToList())
- {
- Console.WriteLine(result);
- }
- }
- }
Add Comment
Please, Sign In to add comment