-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathSoftwareSales.java
More file actions
54 lines (44 loc) · 1.73 KB
/
Copy pathSoftwareSales.java
File metadata and controls
54 lines (44 loc) · 1.73 KB
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
import javax.swing.JOptionPane;
/**@author Lemuel M. Uhuru
* @Date June 11, 2013
* Book Title: From Control Structures through Objects by Tony Gaddis
* Page: 189 Problem 8: Software Sales
*
* @Description Write a program that ask the user to enter the number
* of packages purchased. The program should then display the amount of
* the discount (if any) and the total amount of the purchase after the
* discount.
*/
public class SoftwareSales {
public static void main(String[] args) {
// Declare PRICE constant to hold the retail price of the package
int PRICE = 99;
// Declare qty variable to store the quantity of package desired by the user
int qty;
// Declare variable for user input
String input;
// Prompt user for pacakge quantity and store in the variable input
input = JOptionPane.showInputDialog("Enter the quantity of packages");
// Convert input into data-type int
qty = Integer.parseInt(input);
// Design decision structure to determine user discount prices
if(qty < 100){
if (qty >= 50){
JOptionPane.showMessageDialog(null, " Quantity: " + qty + "\n Discount: " + " 40% Off" +
" \n Discount Price: " + ((qty*PRICE)-(qty*PRICE*.40)));
}
else if (qty >= 20){
JOptionPane.showMessageDialog(null, " Quantity: " + qty + "\n Discount: " + " 30% Off" +
" \n Discount Price: " + ((qty*PRICE)-(qty*PRICE*.30)));
}
else{
JOptionPane.showMessageDialog(null, " Quantity: " + qty + "\n Discount: " + " 20% Off" +
" \n Discount Price: " + ((qty*PRICE)-(qty*PRICE*.20)));
}
}
else{
JOptionPane.showMessageDialog(null, " Quantity: " + qty + "\n Discount: " + " 50% Off" +
" \n Discount Price: " + ((qty*PRICE)-(qty*PRICE*.50)));
}
}
}