Write a program to accept customer name, book name and price of the book from the user and calculate the payable amount after applying discount based on the given tariff.
- First ₹1 to ₹500 discount will be ₹100.
- Next ₹501 to ₹1500 discount will be ₹200.
- Next ₹1501 to ₹5000 discount will be ₹500.
- More than ₹5000 discount will be ₹1000.
Java
import java.util.*;
class BookShop
{
public static void main(String args[])
{
String bName,cName="";
double price,bill=0.0;
Scanner sc=new Scanner(System.in);
System.out.print("Customer name: ");
cName=sc.nextLine();
System.out.print("Name of the book: ");
bName=sc.nextLine();
System.out.print("Price of the book: ");
price=sc.nextDouble();
System.out.println();
if(price>0&&price<=500)
{
bill=price-100;
}
else if(price>500&&price<=1500)
{
bill=price-200-100;
}
else if(price>1500&&price<=5000)
{
bill=price-500-200-100;
}
else if(price>5000)
{
bill=price-1000-500-200-100;
}
else
{
System.out.println("Price of book can not be zero or negative");
}
System.out.println("Customer Name: "+cName);
System.out.println("Name of the book: "+bName);
System.out.println("Price of the book: "+price);
System.out.println("Price after discount: "+bill);
}
}Java