<< Back to Object Oriented Programming Portfolio
Book Assignment
public class Book
{
private String name;
private String author;
private boolean isHardcover;
private double price;
private int numberOfPages;
private int numberOfTimesRead;
public Book(String name, String author, boolean isHardcover, double price, int numberOfPages)
{
this.name = name;
this.author = author;
this.isHardcover = isHardcover;
this.price = price;
this.numberOfPages = numberOfPages;
this.numberOfTimesRead = 0;
}
public void newRead()
{
this.numberOfTimesRead++;
}
public double getTimeToRead()
{
return numberOfPages / 0.8;
}
public String getShouldIReadIt()
{
double timeToRead = getTimeToRead();
return (timeToRead < 61) ? "You can read this" : (timeToRead <= 240) ? "Are you sure you want to read this now?" : "You should not start reading this right now";
}
public String getName()
{
return name;
}
public String getAuthor()
{
return author;
}
public boolean isHardcover()
{
return isHardcover;
}
public double getPrice()
{
return price;
}
public int getNumberOfPages()
{
return numberOfPages;
}
public int getNumberOfTimesRead()
{
return numberOfTimesRead;
}
}