Skip to content

Instantly share code, notes, and snippets.

@ellenia
Last active September 19, 2017 14:30
Show Gist options
  • Save ellenia/8132065010c97f507e58f21c95312518 to your computer and use it in GitHub Desktop.
Save ellenia/8132065010c97f507e58f21c95312518 to your computer and use it in GitHub Desktop.
/* 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 java.util.Scanner;
public class SoftwareSales2
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner( System.in );
int quantity;
float price = 99;
float orderAmount = 0;
float discountAmount = 0;
float totalAmount = 0;
//user's input
System.out.println("Enter the quantity of packages: ");
quantity = keyboard.nextInt();
if (quantity >= 0 && quantity <=9)
{
orderAmount = price * quantity;
discountAmount = orderAmount * 0;
totalAmount = orderAmount - discountAmount;
System.out.println("Your discount is 0%.");
}
if (quantity >= 10 && quantity <= 19)
{
orderAmount = price * quantity;
//discount = 20;
discountAmount = (float) (orderAmount * 0.20);
totalAmount = orderAmount - discountAmount;
System.out.println("Your discount is 20%.");
}
else if (quantity >= 20 && quantity <= 49)
{
orderAmount = price * quantity;
//discount = 30;
discountAmount = (float) (orderAmount * 0.30);
totalAmount = orderAmount - discountAmount;
System.out.println("Your discount is 30%.");
}
else if (quantity >= 50 && quantity <= 99)
{
orderAmount = price * quantity;
//discount = 40;
discountAmount = (float) (orderAmount * 0.40);
totalAmount = orderAmount - discountAmount;
System.out.println("Your discount is 40%.");
}
else if (quantity >=100)
{
orderAmount = price * quantity;
//discount = 50;
discountAmount = (float) (orderAmount * 0.50);
totalAmount = orderAmount - discountAmount;
System.out.println("Your discount is 50%.");
}
//orderAmount = quantity * price;
//discountAmount = orderAmount * discountAmount;
//totalAmount = orderAmount - discountAmount;
System.out.println("The discount amount is: $" + discountAmount + " and " +
"the total purchase amount after discount is: $" + totalAmount + "." +
"\nThank you.");
System.exit(0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment