Java Reference
In-Depth Information
Display 8.1
The Base Class Sale (part 3 of 3)
79 /*
80 Returns true if the names are the same and the bill for the calling
81 object is equal to the bill for otherSale; otherwise returns false.
82 Also returns false if otherObject is null.
83 */
84 public boolean equalDeals(Sale otherSale)
85 {
86 if (otherSale == null )
87 return false ;
88 else
89 return (name.equals(otherSale.name)
90 && bill() == otherSale.bill());
91 }
When invoked, these methods
will use the definition of
the method bill that
is appropriate for each of
the objects.
92 /*
93 Returns true if the bill for the calling object is less
94 than the bill for otherSale; otherwise returns false.
95 */
96 public boolean lessThan ( Sale otherSale)
97 {
98 if (otherSale == null )
99 {
100 System.out.println("Error: null Sale object.");
101 System.exit(0);
102 }
103
//else
104
return (bill() < otherSale.bill());
105 }
106 public boolean equals(Object otherObject)
107 {
108 if (otherObject == null )
109 return false ;
110 else if (getClass() != otherObject.getClass())
111 return false ;
112 else
113 {
114 Sale otherSale = (Sale)otherObject;
115 return (name.equals(otherSale.name)
116 && (price == otherSale.price));
117 }
118 }
119 }
 
Search WWH ::




Custom Search