
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...
1- Create the base class Book that has the following instance variables, constructor, and methods title ( String) isbn ( String) authors (String) publisher (String) edition ( int) published_year (int) Constructor that takes all of the above variables as input parameters. set/get methods ToString method // that return sting representation of Book object. 2- Create the sub class New_Book that is derived from the base class Book and has the following instance variables, constructor, and methods: title ( String) isbn...
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...
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...
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....
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...
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.
Create an abstract class “Appointment” that represents an event on a calendar. The “Appointment” class will have four instance variables: • An instance variable called “year” which will be of type int • An instance variable called “month” which will be of type int • An instance variable called “day” which will be of type int • An instance variable called “description” which will be of type String The “Appointment” class must also implement the following methods: • A getter...
Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters long encryptedPassword : String key int Must be between 1 and 10(inclusive) accountId - A unique integer that identifies each account nextIDNum – a static int that starts at 1000 and is used to generate the accountID no other instance variables needed. Default constructor – set all instance variables to a default value. Parameterized constructor Takes in clearPassword, key. Calls encrypt method to create...