I have to create book managing program using inheritence using a java . Book cla
ID: 3558840 • Letter: I
Question
I have to create book managing program using inheritence using a java .
Book class is parents class international , standar classes are going to be a child classes.
My code is executing but function is not working. please check it thanks.
Here is my code
public void setBookName(String bookName) {
this.bookName = bookName;
}
public String getAuthors() {
return authors;
}
public void setAuthors(String authors) {
this.authors = authors;
}
public String getPublication() {
return publication;
}
public void setPublication(String publication) {
this.publication = publication;
}
public double getCost() {
return cost;
}
public void setCost(double cost) {
this.cost = cost;
}
public Calendar getPurchaseDate() {
return purchaseDate;
}
public void setPurchaseDate(Calendar purchaseDate) {
this.purchaseDate = purchaseDate;
}
public String getBookType() {
return bookType;
}
public void setBookType(String bookType) {
this.bookType = bookType;
}
public boolean equals(Object obj)
{
Book book=(Book)obj;
if(bookName.equals(book.getBookName()))
return true;
else
return false;
}
@Override
public String toString() {
return "Book [isbn=" + isbn + ", bookName=" + bookName + ", authors="
+ authors + ", publication=" + publication + ", cost=" + cost
+ ", purchaseDate=" + purchaseDate + ", bookType=" + bookType
+ ", getIsbn()=" + getIsbn() + ", getBookName()=" + getBookName()
+ ", getAuthors()=" + getAuthors() + ", getPublication()="
+ getPublication() + ", getCost()=" + getCost()
+ ", getPurchaseDate()=" + getPurchaseDate() + ", getBookType()="
+ getBookType() + "]";
}
}
package book;
import java.io.DataInputStream;
import java.util.Vector;
public class Books {
public static DataInputStream dis;
public Books(){
dis= new DataInputStream(System.in);
}
public Books(int i) {
// TODO Auto-generated constructor stub
}
public static void addbook()
{
System.out.println("adding a book");
}
public static void getbook()
{
System.out.println("Seaching a book");
}
public static void delbook()
{
System.out.println("deleting a book");
}
}
package book;
import java.util.Calendar;
import java.util.ListIterator;
import java.util.Vector;
import java.util.Iterator;
public class InternationalBook extends Books {
static Vector v;
public static InternationalBook uniq;
String language;
String region;
private Object bookName;
//double cost;
public static InternationalBook getInstance()
{
if(uniq!=null)
return uniq;
else
{
uniq=new InternationalBook();
return uniq;
}
}
public InternationalBook()
{
v=new Vector();
}
public InternationalBook(int size)
{
super(100);
v=new Vector();
}
@SuppressWarnings({ "deprecation", "unchecked" })
public static void add()
{
Book item= new Book();
try{
System.out.println("Adding a book ");
System.out.println("Title of book: ");
System.out.println("Cost: ");
System.out.println("Language: ");
System.out.println("Region: ");
item.setBookName(new String(dis.readLine().getBytes("8859_1"),"KSC5601"));
v.add(item);
}
catch(Exception e){}
}
public static void getRecord()
{
String strBook = " ";
try
{
System.out.println("Search:");
System.out.println("Title:");
strBook= new String(dis.readLine().getBytes("8859_1"),"KSC5601");
}
catch(Exception e){}
for(int i=0;i< v.size();i++)
{
Book item=(Book)v.get(i);
if(item.getBookName().equals(strBook))
{
System.out.println("Result ");
System.out.println("Title: "+ item.getBookName());
System.out.println("Authors: "+ item.getAuthors());
break;
}
}
}
public static void list()
{
System.out.println(" List of book: ");
for(Iterator it=v.iterator();it.hasNext();)
{
System.out.println((Book)it.next());
}
}
/*public static void delete()
{
String strBook=" ";
try{
System.out.println("Delete");
System.out.println("Title:");
strBook=new String(dis.readLine().getBytes("8859_1"),"KSC5601");
}catch(Exception e){}
for(int i=0;i {
Book item=(Book)v.get(i);
if(item.getBookName().equals(strBook))
{
v.remove(i);
break;
}
}
}*/
public Vector getBookList(){
return v;
}
public static void menu(){
int ch=0;
System.out.println("Menu ");
System.out.println("1. Add book ");
System.out.println("2. List of book ");
System.out.println("3. Exit ");
System.out.println("4. Choose menu: ");
do{
switch(ch){
case 1: add();
break;
case 2: getRecord();
break;
case 3: System.out.println("Bye");
break;
default: return;
}
}while(ch!=0);
}
}
package book;
import java.io.DataInputStream;
import java.util.Calendar;
import java.util.Vector;
public class managingBook {
public static void main(String[]args){
InternationalBook book=null;
boolean flag=true;
int choose=0;
DataInputStream dis= new DataInputStream(System.in);
while(flag)
{
try{
System.out.print("Select menu 0.international 1.standard 2.Exit Choose:");
choose= Integer.parseInt(dis.readLine());
}
catch(Exception e){}
switch(choose)
{
case 0:
InternationalBook.menu();
break;
/* case 1: InternationalBook.getRecord();
break;
case 2: InternationalBook.delete();
break;
case 3: InternationalBook.list();
break;
case 4: flag=true;
break;*/
case 2: System.out.println("BYE");
return;
default: return;
}
}
/* if(choose==1)
{
book= InternationalBook.getInstance();
flag=false;
while(!flag)
{
book.menu();
}
}*/
}
}
Explanation / Answer
Try This It should help you.Enjoy