Question: Using C#: Create a console Application named BookDemo that declares and demonstrates objects of the Book class and its descendents. The Book class includes auto-implemented

Using C#: Create a console Application named BookDemo that declares and demonstrates objects of the Book class and its descendents. The Book class includes auto-implemented properties for the International Standard Book Number (ISBN), title, author, and price. Create a child class named TextBook that includes a grade level and a CoffeeTableBook child class that contains no additional fields or properties. In the child classes, override the accessor that sets a Book's price so that TextBooks must be priced between $20.00 and $80.00, inclusive, and CoffeeTableBooks must be priced between $35.00 and $100.00, inclusive. Be sure to use valid and invalid values when testing the child class properties."

HINT***

This programing exercise you will be creating a Console Application. You will create one base class called Book. Follow the instructions on what the Book class should contain.

You will create two other child classes called TextBook and CoffeeTableBook. Both of these child classes will inherit form the Book class. Make sure you read the instructions carefully on what these child classes should contain. Please use constants in your child classes for the Low and High prices as defined in the instructions. If the price is lower than the Low Price constant, then set the price to the Low Price constant. If the price is higher than the High Price constant, then set the price to the High Price constant. Otherwise the price is valid.

Each child class will override the price accessor of the Book class to set the price.

You will create one Book object from the Book class with a price.

You will create two objects for each of the child classes. One object will have a valid price and the other object will have a invalid price.

So you will have five objects in total

For each of the objects you will create your own data. For example, for valid TextBook data (one with a good price), you might set the data as:

aGoodText.ISBN = "1234567894";

aGoodText.title = "Understanding the Constitution";

aGoodText.auther = "Williams";

aGoodText.gradeLevel = 8;

aGoodText.price = 40.00;

You also need to write out the information for each object. Here is an example of how that might look:

Console.WriteLine(" ISBN: {0}", aGoodText.ISBN);

Console.WriteLine(" {0} by {1} for grade {2} sells for {3}", aGoodText.title, aGoodText.auther, aGoodText.gradeLevel, aGoodText.price.ToString("C"));

Here is what I have so far and its not working out for me***************

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace Book { class Book

{ //Book class starts here //all data members of class Book private int isbn; private string title; private string author; protected double price; //auto implemented properties //of every data member public int Isbn { get { return isbn; } set { isbn = value; } } public string Title { get { return title; } set {

title = value; } }

public string Author { get { return author; } set { author = value; } } public virtual double Price { get { return price; } set { price = value; } } //a function to display all the data members public virtual void show() { Console.WriteLine("Properties of Photo:" + Isbn + "" + Title + "" + Author + "" + Price); } //Definition of class Book ends here } class TextBook : Book { //TextBook class starts here //only one new data member private char level { get { return level; } set { level = value; } } //different definition of Price public override double Price { get { return price; } set { if (value >= 20 && value <= 80) price = value; else Console.WriteLine("Textbook must be " + "priced between 20-80"); } } //override function show public override void show() { Console.WriteLine("Properties of TextBook:" + Isbn + "" + Title + "" + Author + "" + Price); //Definition of class TextBook ends here } class CoffeTableBook : Book { //Definition of class CoffeTableBook starts here //override Price function of base class Book public override double Price { get { return price; } set { if (value >= 35 && value <= 100) price = value; else Console.WriteLine("CoffeTableBook must " + "be priced between 35-100"); } } //override function show public override void show() { Console.WriteLine("Properties of CoffeTableBook:" + +Isbn + "" + Title + "" + Author + "" + Price); } //Definition of class CoffeTableBook ends here } class Program { static void Main(string[] args) { //Main method starts here //object of class TextBook is initialized TextBook b = new TextBook(); Random r = new Random(); int v = r.Next(1, 20); b.Isbn = v; b.Title = "death note"; b.Author = "Richard"; b.Price = 15; //object of class CoffeTableBook is initialized CoffeTableBook b1 = new CoffeTableBook(); Random r1 = new Random(); int v1 = r1.Next(1, 20); b1.Isbn = v1; b1.Title = "footprints"; b1.Author = "Tom"; b1.Price = 120; Console.ReadKey(); //Main method ends here } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!