Question
Library needs to automate the manual process of issue and receipt of books.To begin with, the developer needs to develop a class Book and a
Library needs to automate the manual process of issue and receipt of books.To begin with, the developer needs to develop a class Book and a class Magazine.
Help the developer to develop this class.
NOTE: A partial code has been given. Do the additions wherever necessary to satisfy the above requirements.
Java Class : Book (Constructor)
protected ISBNNumber - int
protected bookName - String
protected price - double
constructor - Book(int,String,double)
constructor - Book
getISBNNumber() int
setISBNNumber() int void
getBookName() String
setBookName() String void
getPrice() double
setPrice() double void
calculateDiscount() double
Java Class : Magazine (constructor)
constructor Magazine(int,String,double,String)
constructor Magazine()
getMagazineType() String
setMagazineType() String void
calculateDiscount() double
develop a public class Book with protected attributes :
int ISBNNumber
String bookName
double price
Include appropriate public getters and setters method.
develop a public 3 argument constructor with arguments - ISBNNumber, bookName and price.
develop a method calculateDiscount() in Book class as,
public float calculateDiscount() - This method will not be implemented in Book class. Make this method as abstract. Also make the class Book as abstract class.
develop a public class Magazine with private attributes :
String magazineType
Include appropriate public getters and setters method.
This class Magazine should inherit the Book class.
Write a public 4 argument constructor with arguments - ISBNNumber, bookName, price and magazineType.
Override the calculateDiscount() method as mentioned below.
public float calculateDiscount() - This method should return 15% of the price.
Example if the book price is 1500, then this method should calculate the discount as 15% of 1500 = 225 should be returned.
Create a public class Main which has the main method. Create the object for Magazine and check for its correctness as shown in the sample input and output.
Note : All classes and methods needs to be declared as public
Sample Input :
Enter the ISBN Number
5128
Enter the Book Name
Thinking in Java
Enter the price
1500
Enter the magazine Type
Weekly
Sample Output :
ISBN Number 5128
Discount Amount 225
---------------------------------------------------------------------------------------------------------
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the ISBN Number");
int isbnnum= sc.nextInt();
sc.nextLine();
System.out.println("Enter the Book Name");
String name=sc.nextLine();
System.out.println("Enter the price");
double price=sc.nextDouble();
System.out.println("Enter the magazine Type");
String type = sc.next();
//Uncomment these lines after performing the necessary changes in Book and Magazine class
/*
Magazine magazine =new Magazine(isbnnum,name,price,type);
double discount = magazine.calculateDiscount();
System.out.println("ISBN Number "+isbnnum);
System.out.println("Discount Amount "+discount);
*/
}
}
-----------------------------------------------------------------------------------------------------------------------
//Make the necessary changes to make this class abstract
public class Book {
protected int ISBNNumber;
protected String bookName;
protected double price;
//Constructor
public Book(int ISBNNumber, String bookName, double price) {
this.ISBNNumber = ISBNNumber;
this.bookName = bookName;
this.price = price;
}
public Book()
{
}
//Getters and Setters
public int getISBNNumber() {
return ISBNNumber;
}
public void setISBNNumber(int iSBNNumber) {
ISBNNumber = iSBNNumber;
}
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
//Make this method calculateDiscount() as abstract
//public double calculateDiscount()
}
-------------------------------------------------------------------------------------------------------------------------------------------
//Make the necessary changes to make this class inherit the Book class
public class Magazine
{
private String magazineType;
//Constructor
public Magazine(int ISBNNumber, String bookName, double price,String magazineType) {
//Uncomment the below statement after you inherit the Book class
//super(ISBNNumber,bookName,price);
this.magazineType=magazineType;
}
public Magazine()
{
}
//Getters and Setters
public String getMagazineType() {
return magazineType;
}
public void setMagazineType(String magazineType) {
this.magazineType = magazineType;
}
//Override the calculateDiscount() method to return 15% of price
// public double calculateDiscount() {
// }
}
-------------------------------------------------------------------------------------------------------------------------------------------------
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started