A software company sells a package that retails for 99 Quant
A software company sells a package that retails for $99. Quantity discounts are given according to the following table: Quantity Discount 1019 20% 2049 30% 5099 40% 100 or more 50% Design 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. Can you help me solve this?
Solution
import java.util.*; // importing scanner from util
public class Discountcalc {
public static void main(String[] args) {
System.out.println(\"package cost $99:\");
System.out.println(\"Enter Number of Packages you want to purchase?:\");
Scanner scan = new Scanner(System.in);// creating scan object from Scanner class
int quantity=scan.nextInt(); // declaring quantity variable and taking input from user
System.out.println(\"quantity:\\t\"+quantity);
if(quantity<10){ // if user buyes less than 10 packages
System.out.println(\"The total amount of the purchase after the discount:$\"+(quantity*99));
}else if(quantity>=10&& quantity<=19){ // if user buyes in between 10 to 19 packages
int actualprice= quantity*99; // calculating actualprice
int discount = actualprice*20/100; // calculating discount
int effectprice = actualprice- discount; // calculating effectprice
System.out.println(\"Actualprice:\\t$\"+actualprice);
System.out.println(\"Discount(20%):\\t$\"+discount);
System.out.println(\"The total amount of the purchase after the discount is:\\t$\"+effectprice);
}else if(quantity>=20&& quantity<=49){ // if user buyes in between 20 to 49 packages
int actualprice= quantity*99;
int discount = actualprice*30/100; // given discount is 30
int effectprice = actualprice- discount;
System.out.println(\"Actualprice:\\t\"+actualprice);
System.out.println(\"Discount(30%):\\t\"+discount);
System.out.println(\"The total amount of the purchase after the discount is:$\"+effectprice);
}else if(quantity>=50&& quantity<=99){ // if user buyes in between 50 to 99 packages
int actualprice= quantity*99;
int discount = actualprice*40/100; // given discount is 40
int effectprice = actualprice- discount;
System.out.println(\"Actualprice:\\t\"+actualprice);
System.out.println(\"Discount(40%):\\t\"+discount);
System.out.println(\"The total amount of the purchase after the discount is:$\"+effectprice);
}else if(quantity>=100){ // if more than or equals to 100
int actualprice= quantity*99;
int discount = actualprice*50/100;// // given discount is 50
int effectprice = actualprice- discount;
System.out.println(\"Actualprice:\\t\"+actualprice);
System.out.println(\"Discount(50%):\\t\"+discount);
System.out.println(\"The total amount of the purchase after the discount is:$\"+effectprice);
}
}
}
