Java Reference
In-Depth Information
Display 8.1 The Base Class Sale (part 1 of 3)
1 /**
2 Class for a simple sale of one item with no tax, discount, or other
adjustments.
3 Class invariant: The price is always nonnegative; the name is a nonempty
string.
4 */
5 public class Sale
6 {
7 private String name; //A nonempty string
8 private double price; //nonnegative
9 public Sale()
10 {
11 name = "No name yet";
12 price = 0;
13 }
14 /**
15 Precondition: theName is a nonempty string; thePrice is nonnegative.
16 */
17 public Sale(String theName, double thePrice)
18 {
19 setName(theName);
20 setPrice(thePrice);
21 }
22 public Sale(Sale originalObject)
23 {
24 if (originalObject == null )
25 {
26 System.out.println("Error: null Sale object.");
27 System.exit(0);
28 }
29 //else
30 name = originalObject.name;
31 price = originalObject.price;
32 }
33 public static void announcement()
34 {
35 System.out.println("This is the Sale class.");
36 }
37 public double getPrice()
38 {
39
return price;
40 }
(continued)
Search WWH ::




Custom Search