In: Computer Science
CODE IN JAVA
A computer company sells software and computer packages for $75. Quantity discounts are given based on the following criteria:
Quantity Discount
10 -
19
20%
20 -
49
30%
50 -
99
40%
100 or more 50%
Be sure the user is presented with all necessary information, then prompt the user for the quantity of packages. Display the total cost of the purchase making sure to apply appropriate discounts.
Example Output:
Demon software and computers is offering discounts on the Vic Package. This package includes a computer and needed software to perform basic daily functions. The Vic package sells for $75.00. Discounts are given based on quantity. The discounts are listed below:
10 - 19 gives a 20% discount
20 - 49 gives a 30% discount
50 - 99 gives a 40% discount
100 or more gives a 50% discount
How many would you like to purchase?
25
You purchased 25 packages. Your total is $1312.50
package stock;
import java.util.Scanner;
public class Stock {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in); // object to take input
//prompting the user with required output
System.out.println("Demon software and computers is offering discounts on the Vic Package. This package includes a \n computer and needed software to perform basic daily functions. The Vic package sells for $75.00.\n Discounts are given based on quantity. The discounts are listed below:");
System.out.println("10 - 19 gives a 20% discount");
System.out.println("20 - 49 gives a 30% discount");
System.out.println("50 - 99 gives a 40% discount");
System.out.println("100 or more gives a 50% discount");
System.out.println("How many would you like to purchase?");
int quantity = sc.nextInt(); //taking quantity input
double purchase;
purchase = quantity * 75; //calculating price
//giving discount according to order
if(quantity >= 10 && quantity <= 19)
purchase = purchase - (purchase * 0.20);
if(quantity >= 20 && quantity <= 49)
purchase = purchase - (purchase * 0.30);
if(quantity >= 50 && quantity <= 99)
purchase = purchase - (purchase * 0.40);
if(quantity >= 100)
purchase = purchase - (purchase * 0.50);
//required output
System.out.println("You purchased " + quantity + " packages. Your total is $" + purchase);
}
}
\n is use in print statement to break line so that the bigger line can be printed and can be adjusted in output window,
Note:- Please comment down if you face any problem. :)