Java Reference
In-Depth Information
Display 8.2
The Derived Class
DiscountSale
(part 2 of 2)
39
public double
getDiscount()
40 {
41
return
discount;
42 }
43
/**
44
Precondition: Discount is nonnegative.
45
*/
46
public void
setDiscount(
double
newDiscount)
47 {
48
if
(newDiscount >= 0)
49 discount = newDiscount;
50
else
51 {
52 System.out.println("Error: Negative discount.");
53 System.exit(0);
54 }
55 }
56
public
String toString()
57 {
58
return
(getName() + " Price = $" + getPrice()
59 + " Discount = " + discount + "%\n"
60 + " Total cost = $" + bill());
61 }
62
public boolean
equals(Object otherObject)
The rest of the definition of
equals
is located in Self-Test Exercise 4 .
63 }