Question

1- Create the base class Book that has the following instance variables, constructor, and methods title...

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 ( String)

authors (String)

publisher (String)

edition ( int)

published_year (int)

price (double)

Constructor that takes all of the above variables as input parameters.

set/get methods

calculate_price // returns the price of the book as listed in the price variable.

ToString method // that return sting representation of New_Book object.

3- Create the sub class Used_Book that is derived from the base class Book and has the following instance variables

title ( String)

isbn ( String)

authors (String)

publisher (String)

edition ( int)

published_year (int)

price_new (double) // the price of the book if it is new

age (int) // how old the book is in years

Constructor that takes all of the above variables as input parameters.

set/get methods

calculate_price method // the price is calculated as price_new * (1- 0.15*age)

ToString method

4- Create the Testing class that has the main method and does the following:

     a- Use the constructor to create object of New_Book class named newbook (you can choose the values of input parameters of the constructor). Call compute_price method.

     b- Use the constructor to create object of Used_Book class named usedbook (you can choose the values of input parameters of the constructor).. Call compute_price method.

     c- Print out the related information of newbook and usedbook objects.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You

_________________

// Book.java

public class Book {
   private String title;
   private String isbn;
   private String authors;
   private int edition;
   private int published_year;

   public Book(String title, String isbn, String authors, int edition,
           int published_year) {
       this.title = title;
       this.isbn = isbn;
       this.authors = authors;
       this.edition = edition;
       this.published_year = published_year;
   }

   public String getTitle() {
       return title;
   }

   public void setTitle(String title) {
       this.title = title;
   }

   public String getIsbn() {
       return isbn;
   }

   public void setIsbn(String isbn) {
       this.isbn = isbn;
   }

   public String getAuthors() {
       return authors;
   }

   public void setAuthors(String authors) {
       this.authors = authors;
   }

   public int getEdition() {
       return edition;
   }

   public void setEdition(int edition) {
       this.edition = edition;
   }

   public int getPublished_year() {
       return published_year;
   }

   public void setPublished_year(int published_year) {
       this.published_year = published_year;
   }

   @Override
   public String toString() {
       return " Title=" + title + ", ISBN=" + isbn + ", authors="
               + authors + ", Edition=" + edition + ", Published_year="
               + published_year;
   }

}
_________________________

// New_Book.java

public class New_Book extends Book {
   private double price;

   public New_Book(String title, String isbn, String authors, int edition,
           int published_year, double price) {
       super(title, isbn, authors, edition, published_year);
       this.price = price;
   }

   public double calculate_price() {
       return price;
   }

   public void setPrice(double price) {
       this.price = price;
   }

   @Override
   public String toString() {
       return "New_Book : Price=" + price +super.toString();
   }

}
_____________________________

// Used_Book.java

public class Used_Book extends Book {
private double price_new;
private int age;
public Used_Book(String title, String isbn, String authors, int edition,
       int published_year, double price_new, int age) {
   super(title, isbn, authors, edition, published_year);
   this.price_new = price_new;
   this.age = age;
}
public double getPrice_new() {
   return price_new;
}
public void setPrice_new(double price_new) {
   this.price_new = price_new;
}
public int getAge() {
   return age;
}
public void setAge(int age) {
   this.age = age;
}
private double calculate_price()
{
   return price_new * (1- 0.15*age);
}
@Override
public String toString() {
   return "Used_Book : Price_new=" + calculate_price() + ", Age=" + age +super.toString();
}

}
______________________________

// Test.java

public class Test {

   public static void main(String[] args) {
New_Book nb=new New_Book("Wings of Fire","978-3-16-148410-0","Abdul kalam",2,2000,150);
Used_Book ub=new Used_Book("Introduction to Java Programming","978-3-16-148410-0","Yeshwanth Kanitkar",3, 2002,120,5);
System.out.println(nb);
System.out.println(ub);

   }

}
_________________________________

Output:

New_Book : Price=150.0 Title=Wings of Fire, ISBN=978-3-16-148410-0, authors=Abdul kalam, Edition=2, Published_year=2000
Used_Book : Price_new=30.0, Age=5 Title=Introduction to Java Programming, ISBN=978-3-16-148410-0, authors=Yeshwanth Kanitkar, Edition=3, Published_year=2002


_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
1- Create the base class Book that has the following instance variables, constructor, and methods title...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 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...

    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 (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...

  • A java class named Book contains: instance data for the title, author, publisher and copyright year...

    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...

    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...

  • Write a class named Book containing: Two instance variables named title and author of type String....

    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.

  • Answer the following: 1.        Create a Class Car with the following instance variables: model (String), Brand...

    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...

  • Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and...

    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 called Book. Here are the relevant attributes: title author yearPublished            bookPriceInCAD Provide...

    Write a class called Book. Here are the relevant attributes: title author yearPublished            bookPriceInCAD Provide a constructor that takes parameters to initialize all the instance variables. The constructor calls the mutator (set) methods to initialize the instance variables. Provide an accessor (get) and mutator (set) for each instance variable. The mutators all validate their parameters appropriately and use them only if valid. If the passed parameter was invalid an IllegalArgumentException will be thrown with a proper error message A...

  • Create an abstract class “Appointment” that represents an event on a calendar. The “Appointment” class will...

    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...

  • Create a Python file (book.py) that has a class named Book. Book class has four attributes, title...

    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...

  • Book: - title: String - price: double +Book() +Book(String, double) +getTitle(): String +setTitle(String): void +getPrice(): double...

    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....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT