Create the Class Book with the following attributes: Book ID, Title, Authors, Unit Price. Print the current details of the book. Add a behavior to modify the price and display the updated book details. Display the total Amount to be paid for each Book, using unit price & 12% tax. Implement using OO concepts.
1
Expert's answer
2014-08-08T04:49:10-0400
using System; using System.Collections.Generic; namespace Q44780 { class Program { static void Main(string[] args) { Book bk = new Book(25333, "By word and deal", 14.16, "Valentin Pikhul"); Console.WriteLine(bk); bk.Price = 15.00; Console.WriteLine("\n\n"+bk); bk.Price = -15.00; Console.WriteLine("\n\n" + bk); Console.ReadKey(); } } } class Book { uint book_id; public uint BookID { get { return book_id; } } string title; public string Title { get { return title; } } double price; public double Price { get { return price; } set { price = value >= 0 ? value : 0; } } List<string> authors; public Book(uint book_id, string title, double price, params string[] authors) { this.book_id = book_id; this.title = title; this.Price = price; this.authors = new List<string>(); foreach (var m in authors) this.authors.Add(m); } public override string ToString() { string athr = ""; foreach (var m in authors) athr +="\n "+ m; return String.Format(" Book ID: {0}\n Title: {1}\n Price: {2,7:c}\n Authors: ", book_id, title, price) + athr + String.Format("\n 12% tax: {0,7:c}\nTotal price: {1,7:c}", price * 0.12, price * 1.12); } } /* * Create the Class Book with the following attributes: * Book ID, Title, Authors, Unit Price. * Print the current details of the book. * Add a behavior to modify the price and display the updated book details. * Display the total Amount to be paid for each Book, using unit price & 12% tax. * Implement using OO concepts. */
Comments