Question 2: write a java program
A Hypermarket makes an offer for its customers according to the number of items to be bought as follows:
Number of purchased items |
Discount percentage |
Less than 25 |
2.5% |
25 – 50 |
5.0% |
51 – 100 |
6.25% |
Greater than 100 |
7.5% |
The hypermarket also adds 2% city taxes to the purchases after the sale discount.
Net Purchase Amount = Purchase amount after discount + City Tax
//importing package which contains Scanner class
import java.util.*;
//class
class Market
{
//main function
public static void main(String args[])
{
int n;
double price,discount,total_cost;
//creating Scanner class object
Scanner s=new Scanner(System.in);
//asking user to enter number of items
System.out.print("Enter the number of items to be purchased:
");
//storing integer input in n
n=s.nextInt();
//asking user to enter item price
System.out.print("Enter the item price: ");
//storing double input in price
price=s.nextDouble();
//calculate and print original purchase cost for n items each
having cost as price
total_cost=price*n;
System.out.println("Original Purchase cost: "+total_cost);
//calculate the discount amount
//the below if else control statements are written according to the
table given in question
if(n<25)
discount=2.5*(total_cost)/100;
else if(n>=25 && n<=50)
discount=5.0*(total_cost)/100;
else if(n>=51 && n<=100)
discount=6.25*(total_cost)/100;
//case when n>100
else
discount=7.5*(total_cost)/100;
//print the discount amount
System.out.println("Discount amount: "+discount);
//calculate new purchase cost after subtracting discount
total_cost=total_cost-discount;
//printing cost after discount
System.out.println("New purchase cost after discount:
"+total_cost);
//calculate net purchase amount after adding city tax of 2%
total_cost=total_cost+(2*total_cost)/100;
//printing cost after adding city tax
System.out.println("Net purchase amount after adding city tax:
"+total_cost);
}
}
Get Answers For Free
Most questions answered within 1 hours.