C# Program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace New_Old_Books
{
//Base Class
public class Book
{
private string title;
public string Title
{
get { return title; }
set { title = value; }
}
private string isbn;
public string Isbn
{
get { return isbn; }
set { isbn = value; }
}
private string authors;
public string Authors
{
get { return authors; }
set { authors = value; }
}
private string publisher;
public string Publisher
{
get { return publisher; }
set { publisher = value; }
}
private int edition;
public int Edition
{
get { return edition; }
set { edition = value; }
}
private int published_year;
public int Published_year
{
get { return published_year; }
set { published_year = value; }
}
//Constructor
public Book(string t, string i, string a, int e, int p, string
pub)
{
this.title = t;
this.isbn = i;
this.authors = a;
this.edition = e;
this.published_year = p;
this.publisher = pub;
}
//Tostring method
public override string ToString()
{
return "\n\n\n Title: " + title + "\n ISBN: " + isbn + "\n Authors:
" + authors + "\n Publisher: " + publisher + "\n Edition: " +
edition + "\n Published Year: " + published_year;
}
}
//Child class
public class New_Book : Book
{
private double price;
public double Price
{
get { return price; }
set { price = value; }
}
//Constructor
public New_Book(string t, string i, string a, string pub, int e,
int p, double pr) : base(t, i, a, e, p, pub)
{
price = pr;
}
//Tostring method
public override string ToString()
{
return base.ToString() + "\n Price: " + calculate_price();
}
//Price calculation
public double calculate_price()
{
return this.price;
}
}
//Child class 2
public class Used_Book : Book
{
private double price_new;
public double Price_new
{
get { return price_new; }
set { price_new = value; }
}
private int age;
public int Age
{
get { return age; }
set { age = value; }
}
//Constructor
public Used_Book(string t, string i, string a, string pub, int e,
int p, double pr, int age) : base(t, i, a, e, p, pub)
{
this.price_new = pr;
this.age = age;
}
//Tostring method
public override string ToString()
{
return base.ToString() + "\n Price: " + calculate_price() + "\n
Age: " + age + " years. \n";
}
//Price calculation
public double calculate_price()
{
return (price_new*(1-(0.15*age)));
}
}
class Program
{
static void Main(string[] args)
{
//Creating objects
New_Book nb = new New_Book("C Sharp", "ISBN:5646", "Mary",
"Himalaya", 2, 2014, 65.25);
Console.WriteLine(nb);
Used_Book ub = new Used_Book("VB.Net", "ISBN:8949", "Kary",
"Maruthi", 5, 2001, 14.25, 5);
Console.WriteLine(ub);
Console.Read();
}
}
}
_______________________________________________________________________________________________________
Sample Run:
C# programming 50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (Strin...
A java class named Book contains: instance data for the title, author, publisher and copyright year a constructor to accept and initialize the instance data variables set and get methods a toString() method to return a formatted, multi-line description of the book Produce a child class that inherits from Book. The class is called Dictionary. Dictonary must include: instance data that describes the number of words in the dictionary a constructor that takes in all information needed to describe a...
Book: - title: String - price: double +Book() +Book(String, double) +getTitle(): String +setTitle(String): void +getPrice(): double +setPrice(double): void +toString(): String The class has two attributes, title and price, and get/set methods for the two attributes. The first constructor doesn’t have a parameter. It assigns “” to title and 0.0 to price; The second constructor uses passed-in parameters to initialize the two attributes. The toString() method returns values for the two attributes. Notation: - means private, and + means public. 1....
Write a class named Book containing: Two instance variables named title and author of type String. A constructor that accepts two String parameters. The value of the first is used to initialize the value of title and the value of the second is used to initialize author. A method named toString that accepts no parameters. toString returns a String consisting of the value of title, followed by a newline character, followed by the value of author.
In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in 'Dog' : name (String type) age (int type) 2. declare the constructor for the 'Dog' class that takes two input parameters and uses these input parameters to initialize the instance variables 3. create another class called 'Driver' and inside the main method, declare two variables of type 'Dog' and call them 'myDog' and 'yourDog', then assign two variables to two instance of 'Dog' with...
Start a new project in NetBeans that defines a class Person with the following: Instance variables firstName (type String), middleInitial (type char) and lastName (type String) (1) A no-parameter constructor with a call to the this constructor; and (2) a constructor with String, char, String parameters (assign the parameters directly to the instance variables in this constructor--see info regarding the elimination of set methods below) Accessor (get) methods for all three instance variables (no set methods are required which makes...
Answer the following: 1. Create a Class Car with the following instance variables: model (String), Brand (String), maxspeed (double) Note: use encapsulation (all variables are private). (3 Marks) 2. Create a non-default constructor for Class Car which takes 3 parameters. (2 Marks) 3. Create a get and set methods for instance variable model variable only. (2 Marks) 4. Create PrintInfo() method which prints all three instance variables. (2 Marks) 5. Create a subclass GasCar with instance variable TankSize (double).. (2...
Create a Python file (book.py) that has a class named Book. Book class has four attributes, title (string), author(string), isbn(string), and year(int). Title - the name of the book. Author - the name of the persons who wrote the book. ISBN - is a unique 13 digit commercial book identifier. Year - the year the title was printed. Your class should have the following methods: (1) __init__(self, title, author, isbn, year): This method called when an object (book) is created...
Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and name variables (do not include topTrick). Note: The type refers to what the breed typically does; for example, a corgi would be a “cattle herding dog.” A Shiba Inu would be a “hunting dog.” Create the setTopTrick() mutator method Dog is parent class Corgi and Driver are subclasses Complete the Corgi class: Using the UML Class diagram, declare the instance variables. Create the two...
Create the class Book which has the following members: 1. private members: 1. title as String 2. isbn as String 3. author as String 4. price as double 2. public members: 1. default constructor which initializes all data members to their default values. 2. non-default constructor which initializes all data members to parameters values. 3. toString which returns a representing String of the Book. 4. add all the setters and getters. Create the class EBook which is a subclass of...
cs55(java) please. Write a class called Book that contains instance data for the title, author, publisher, price, and copyright date. Define the Book constructor to accept and initialize this data. Include setter and getter methods for all instance data. Include a toString method that returns a nicely formatted, multi-line description of the book. Write another class called Bookshelf, which has name and array of Book objects. Bookself capacity is maximum of five books. Includes method for Bookself that adds, removes,...