Last active
September 19, 2017 02:21
-
-
Save ellenia/86b2711370705b5ebd1b9ff4df1b9793 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* A software company sells a package that retails for $99. Quantity discounts are given according to the | |
* the following table: | |
* | |
* Quantity Discount | |
* 10-19 20% | |
* 20-49 30% | |
* 50-99 40% | |
* 100 or more 50% | |
* | |
* Write a program that asks 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. | |
* | |
*/ | |
import javax.swing.JOptionPane; | |
public class SoftwareSales1 | |
{ | |
public static void main(String [] args) | |
{ | |
double price = 99; | |
int quantity; | |
double orderAmount = 0; | |
double discountAmount = 0; | |
double totalAmount = 0; | |
String inputQuantity; | |
String output; | |
//user's input | |
inputQuantity = JOptionPane.showInputDialog("Enter the quantity of packages: "); | |
quantity = Integer.parseInt(inputQuantity); | |
if (quantity < 10) | |
{ | |
orderAmount = price * quantity; | |
discountAmount = price * 0; | |
totalAmount = orderAmount - discountAmount; | |
} | |
else if (quantity >= 10 && quantity <= 19) | |
{ | |
orderAmount = price * quantity; | |
discountAmount = 0.20 * orderAmount; | |
totalAmount = orderAmount - discountAmount; | |
} | |
else if (quantity >= 20 && quantity <= 49) | |
{ | |
orderAmount = price * quantity; | |
discountAmount = 0.30 * orderAmount; | |
totalAmount = orderAmount - discountAmount; | |
} | |
else if (quantity >= 50 && quantity <= 99) | |
{ | |
orderAmount = price * quantity; | |
discountAmount = 0.40 * orderAmount; | |
totalAmount = orderAmount - discountAmount; | |
} | |
else if (quantity >= 100) | |
{ | |
orderAmount = price * quantity; | |
discountAmount = 0.50 * orderAmount; | |
totalAmount = orderAmount - discountAmount; | |
} | |
output = String.format("Order amount: $%,.2f.\nDiscount amount: $%,.2f.\nTotal amount: $%,.2f.", | |
quantity, orderAmount, discountAmount, totalAmount); | |
JOptionPane.showMessageDialog(null,output); | |
System.exit(0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment