Design a console program that will print details of prescribed textbooks of students. Make use of an abstract class Book with variables that will store the author, title, category and price of a book. Create a constructor that accepts the author, title and category through parameters and assign these to the class variables. Create an abstract set method for the price of a book; also create get methods for the variables. Create a subclass TextBook that extends the Book class and implements an iPrintable interface. The interface that must be added is shown below: public interface iPrintable { String DisplayDetails(); The TextBook subclass has a private variable named yearPrescribed for which a get method must be written. The constructor of the TextBook class must accept the author, title, category and yearPrescribed through parameters. Write the code for the setPrice() and DisplayDetails() methods.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Please help with the question on the picture 

Design a console program that will print details of prescribed textbooks of students. Make use of an abstract
class Book with variables that will store the author, title, category and price of a book. Create a constructor that
accepts the author, title and category through parameters and assign these to the class variables. Create an
abstract set method for the price of a book; also create get methods for the variables.
Create a subclass TextBook that extends the Book class and implements an iPrintable interface. The interface
that must be added is shown below:
public interface iPrintable {
String DisplayDetails();
The TextBook subclass has a private variable named yearPrescribed for which a get method must be written.
The constructor of the TextBook class must accept the author, title, category and yearPrescribed through
parameters. Write the code for the setPrice() and DisplayDetails() methods.
Write a useBook class and instantiate 2 objects of the TextBook class. Sample output is show 2/4
Du
may use the same values to test your application.
24||
| Output - UseBook (run)
IDD zun:
Book Details
DD
Author: N.O. Body
Title: Intro to Programming
Category: Non-fiction
Year Prescribed: DISD1
Price: R350
Author: S.0. Mebody
Title: Web Development Intermediate
Category: Non-fiction
Year Prescribed: DISD2
Price: R425
BUILD SUCCESSFUL (total time: 0 seconds)
Transcribed Image Text:Design a console program that will print details of prescribed textbooks of students. Make use of an abstract class Book with variables that will store the author, title, category and price of a book. Create a constructor that accepts the author, title and category through parameters and assign these to the class variables. Create an abstract set method for the price of a book; also create get methods for the variables. Create a subclass TextBook that extends the Book class and implements an iPrintable interface. The interface that must be added is shown below: public interface iPrintable { String DisplayDetails(); The TextBook subclass has a private variable named yearPrescribed for which a get method must be written. The constructor of the TextBook class must accept the author, title, category and yearPrescribed through parameters. Write the code for the setPrice() and DisplayDetails() methods. Write a useBook class and instantiate 2 objects of the TextBook class. Sample output is show 2/4 Du may use the same values to test your application. 24|| | Output - UseBook (run) IDD zun: Book Details DD Author: N.O. Body Title: Intro to Programming Category: Non-fiction Year Prescribed: DISD1 Price: R350 Author: S.0. Mebody Title: Web Development Intermediate Category: Non-fiction Year Prescribed: DISD2 Price: R425 BUILD SUCCESSFUL (total time: 0 seconds)
Expert Solution
Java Program:

Book.java

public abstract class Book

{

public String author,title,category,price;

//constructor

public Book(String author,String title,String category)

{

this.author=author;

this.title=title;

this.category=category;

}

//setprice abstrac method

public abstract void setPrice(String price);

//get methods for all other variables

public String getAuthor() {

return this.author;

}

public String getTtile() {

return this.title;

}

public String getCategory() {

return this.category;

}

}

iPrintable.java

public interface iPrintable {
String DisplayDetails();
}

TextBool.java


public class TextBook extends Book implements iPrintable{
private String yearPrescribed;//instance varibale
//counstructor
public TextBook(String author, String title, String category,String year) {
super(author, title, category);
this.yearPrescribed=year;
}
//get yearPrescribed method
String getYearPrescribed()
{
return this.yearPrescribed;
}
@Override
public void setPrice(String price) {
this.price=price;
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  
}

@Override
public String DisplayDetails() {
String str="Author:"+getAuthor()+"\nTitel:"+getTtile()+"\nCategory:"+getCategory()+"\nYear Prescribed:"+getYearPrescribed()+"\nPrice:"+this.price;
return str;
}
  
}useBook.java


public class useBook {


public static void main(String[] args) {
TextBook book1=new TextBook("N.O.Body", "Intro to programming", "Non-fiction", "DISD1");
book1.setPrice("R350");
TextBook book2=new TextBook("S.O.Mebody","Web Development Intermediate","Non-fiction", "DISD2");
book2.setPrice("R350");
  
System.out.println("Book Details");
System.out.println(book1.DisplayDetails());
System.out.println("\n\n");
System.out.println(book2.DisplayDetails());
}
  
}

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY