-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSoftwareSales.java
89 lines (73 loc) · 1.63 KB
/
SoftwareSales.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package chapter4;
/** This class stores the number of units sold and
* calculates the total cost of the purchase.
*
*/
public class SoftwareSales
{
private int sold; // Number of units sold
private double discount; // Discount based on units sold
private double retail; // Cost of units sold
private double total; // Calculate total with discount
private double discountAmount; // Shows discount dollar value
/** The constructor uses two parameters to accept
* arguments: s. The value in s is assigned
* to the sold field. The calculateTotal method
* is called.
*/
public SoftwareSales(int s)
{
sold = s;
calculateTotal();
}
/**
* The setDiscount method sets the discount
* based on the amount of units sold.
* This method is called from the
* calculateTotal method
*/
private void setDiscount()
{
if (sold < 10)
discount = 0;
else if (sold < 20)
discount = .20;
else if (sold < 50)
discount = .30;
else if (sold < 100)
discount = .40;
else
discount = .50;
}
/** The calculateTotal method calculates the discount amount
* and the total amount of the sale.
*/
private void calculateTotal()
{
setDiscount();
retail = sold * 99;
discountAmount = discount * retail;
total = (retail)-(discountAmount);
}
/**
* The getTotal method returns the total field.
*/
public double getCost()
{
return total;
}
/**
* The getSold method return the sold field
*/
public int getUnitsSold()
{
return sold;
}
/**
* The getDiscount method returns the discount field
*/
public double getDiscount()
{
return discountAmount;
}
}