In: Computer Science
Assume you have created the following data definition class:
public class Book {
private String title;
private double cost;
public String getTitle() { return this.title;
}
public double getCost() { return this.cost;
}
public void setTitle(String title) {
this.title = title;
}
// Mutator to return true/false instead of using exception
handling
public boolean setCost(double cost) {
if (cost >= 0 &&
cost < 100) {
this.cost =
cost;
return
true;
}
else {
return
false;
}
}
public double calculateSalePrice(double tax)
{
return this.getCost() *
(1+tax);
}
}
Change the mutator, setTitle(String title), to be a mutator that returns a Boolean if a title could be set, if it contains at least 10 characters
public class Book { private String title; private double cost; public String getTitle() { return this.title; } public double getCost() { return this.cost; } public boolean setTitle(String title) { if (title.length() >= 10) { this.title = title; return true; } return false; } // Mutator to return true/false instead of using exception handling public boolean setCost(double cost) { if (cost >= 0 && cost < 100) { this.cost = cost; return true; } else { return false; } } public double calculateSalePrice(double tax) { return this.getCost() * (1 + tax); } }