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.
- Upto ₹500 discount will be 5%.
- From ₹501 to ₹1500 discount will be 8%.
- From ₹1501 to ₹5000 discount will be 10%.
- More than ₹5000 discount will be 15%.
Java
import java.util.*;
public 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-(price*0.05);
}
else if(price>500&&price<=1500)
{
bill=price-(price*0.08);
}
else if(price>1500&&price<=5000)
{
bill=price-(price*0.10);
}
else if(price>5000)
{
bill=price-(price*0.15);
}
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