I have a book class which is as follows class Book { private int numberOfPages;
ID: 3640693 • Letter: I
Question
I have a book class which is as follows
class Book
{
private int numberOfPages;
private boolean hardBack;
private String title;
private double price;
//constructors
Book()
{
title = "";
numberOfPages = 0;
hardBack = true;
price = 0.0;
}
Book(int n, boolean h, String t, double p)
{
numberOfPages = n;
hardBack = h;
title = t;
price = p;
}
int getPages()
{
return numberOfPages;
}
void setPage(int n)
{
numberOfPages = n;
}
boolean getBack()
{
return hardBack;
}
void setBack(boolean h)
{
hardBack = h;
}
String getTitle()
{
return title;
}
void setTitle(String t)
{
title = t;
}
double getPrice()
{
return price;
}
void setPrice( double p)
{
price = p;
}
@Override
public boolean equals(Object obj)
{
if (obj == this)
{
return true;
}
if (obj == null || obj.getClass() != this.getClass())
{
return false;
}
Book book = (Book) obj;
return (book.getPages() == this.getPages()
&& book.getPrice() == this.getPrice()
&& book.getBack() == this.getBack() && book.getTitle()
.equalsIgnoreCase(this.getTitle()));
}
@Override
public String toString()
{
return ("No Of Pages: " + this.getPages() + " " + "Price of Book: "
+ this.getPrice() + " " + "Hard Back: " + this.getBack()
+ " " + "Book Title: " + this.getTitle());
}
}
Now using this book class with a weel-defined equals method, create a Stack that holds at least 5 Book Objects. use each of the following Stack methods:
1) empty
2)peek
3)pop(demonstrate proper exception handling )
4)push
5)search
Can someone please help me with this ?