Question: Given the following data definition class and implementation class shell, write a create() method that will create and return an object to model a Book
Given the following data definition class and implementation class shell, write a create() method that will create and return an object to model a Book with an ISBN number of 12345.
public class Book { private String isbn; private double cost; private boolean isNew; public Book() { this.isNew = true; } public Book(String isbn) { this(); this.isbn = isbn; } public Book(String isbn, double cost) { this(); this.isbn = isbn; this.cost = cost; } public String getIsbn() { return this.isbn; } public double getCost() { return this.cost; } public boolean isNew() { return this.isNew; } public void setIsbn(String isbn) { this.isbn = isbn; } public boolean setCost(double cost) { if (cost >= 0) { this.cost = cost; return true; } else { return false; } } public void setIsNew(boolean isNew) { this.isNew = isNew; } public boolean discount(double percentage) { if (percentage > 0) { setCost(this.getCost() - this.getCost() * (percentage/100)); return true; } else { return false; } } }
import javax.swing.JOptionPane; public class Bookstore { public static void main(String[] args) { Book myBook = create(); } // write the create() method }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
