Write a program to accept name, mobile number and the cost of purchased item from the user and calculate the payable amount after applying discount based on the given tariff.
- First ₹1 to ₹500 discount will be ₹0.
- Next ₹501 to ₹1000 discount will be ₹100.
- Next ₹1001 to ₹ 5000 discount will be ₹300.
- Next ₹5001 to ₹10000 discount will be ₹600.
- More than ₹10000 discount will be ₹1000
Java
import java.util.*;
class ShowRoom
{
public static void main(String args[])
{
String name="";
long mobile=0;
double cost,d,amount=0.0;
Scanner sc=new Scanner(System.in);
System.out.print("Consumer name: ");
name=sc.nextLine();
System.out.print("Consumer's mobile number: ");
mobile=sc.nextLong();
System.out.print("Cost of the item purchased: ");
cost=sc.nextDouble();
System.out.println();
if(cost<500)
{
amount=cost-0;
}
else if(cost>=500&&cost<=1000)
{
amount=cost-100-0;
}
else if(cost>1000&&cost<=5000)
{
amount=cost-300-100-0;
}
else if(cost>5000&&cost<=10000)
{
amount=cost-600-300-100-0;
}
else if(cost>10000)
{
amount=cost-1000-600-300-100-0;
}
else
{
System.out.println("Cost can not be zero or negative");
}
System.out.println("Customer's Name: "+name);
System.out.println("Customer's Mobile Number: "+mobile);
System.out.println("Cost of the product: "+cost);
System.out.println("Amount to be paid after discount: "+amount);
}
}Java