WRITE A PROGRAM THAT STORES THE DETAILS OF THE SOFTWARE AND HARDWARE BOOKS. THE SOFTWARE BOOKS INCLUDES THE SOFTWARE VERSION AND SOFTWARE NAME. THE HARDWARE BOOK INCLUDES THE HARDWARE CATEGORY AND PUBLISHER. HOWEVER, BOTH THE BOOKS INCLUDE SOME COMMON DETAILS, SUCH AS AUTHOR NAME,TITLE,PRICE,AND NUMBER OF PAGES. THEREFORE, YOU NEED TO STORE AND DISPLAY THE BOOK DETAILS BY IMPLEMENTING THE CODE REUSABILITY IN THE PROGRAM.
ANSWER
class book {
string author;
string title;
int price;
int pages;
int stock;
public void getdetails(string at, string tt, int pr, int pg, int st) {
author = at;
title = tt;
price = pr;
pages = pg;
stock = st;
}
public void showdetails () {
system.out.println (" ");
system.out.println ("books information");
system.out.println ("============================");
system.out.println (" book author: " + author);
system.out.println (" book title: " + title);
system.out.println (" book price: " + price);
system.out.println (" number of pages: " + pages);
system.out.println (" book of stock: " + stock);
}
}
class hardwarebook extends book {
string hardwarecatagoery;
string publisher;
public void getdetails () {
super . getdetails ("mark franklin" , "all about pc", 120, 150, 80);
hardwarecategory = "machine";
publisher = "denmark";
}
public void showdetails() {
system.out.println (" ");
system.showdetails ();
system.out.println ("hardware category: " + hardwarecategory);
system.out.println ("publisher name: " + publisher);
system.out.println (" ");
}
}
public class bookdemo {
public static void main(string args []) {
softwarebook softdetails = new softwarebook ();
softdetails. getdetails ();
softdetails . showdetails ();
hardwarebook harddetails = new hardwarebook ();
harddetails . getdetails ();
harddetails . showdetails ();
}
}
ANSWER
class book {
string author;
string title;
int price;
int pages;
int stock;
public void getdetails(string at, string tt, int pr, int pg, int st) {
author = at;
title = tt;
price = pr;
pages = pg;
stock = st;
}
public void showdetails () {
system.out.println (" ");
system.out.println ("books information");
system.out.println ("============================");
system.out.println (" book author: " + author);
system.out.println (" book title: " + title);
system.out.println (" book price: " + price);
system.out.println (" number of pages: " + pages);
system.out.println (" book of stock: " + stock);
}
}
class hardwarebook extends book {
string hardwarecatagoery;
string publisher;
public void getdetails () {
super . getdetails ("mark franklin" , "all about pc", 120, 150, 80);
hardwarecategory = "machine";
publisher = "denmark";
}
public void showdetails() {
system.out.println (" ");
system.showdetails ();
system.out.println ("hardware category: " + hardwarecategory);
system.out.println ("publisher name: " + publisher);
system.out.println (" ");
}
}
public class bookdemo {
public static void main(string args []) {
softwarebook softdetails = new softwarebook ();
softdetails. getdetails ();
softdetails . showdetails ();
hardwarebook harddetails = new hardwarebook ();
harddetails . getdetails ();
harddetails . showdetails ();
}
}
3 comments:
how can we take details ?
no scanner
wrong code
where is software book class
Post a Comment