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.
- Upto ₹1000 discount will be 3%.
- From ₹1001 to ₹5000 discount will be 5%.
- From ₹5001 to ₹ 10000 discount will be 8%.
- More than ₹10000 discount will be 10%.
Java
import java.util.*;
public class ShowRoom
{
public static void main(String args[])
{
String name="";
long mobile=0;
double cost,amount,d=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>0&&cost<=1000)
{
d=cost*0.03;
}
else if(cost>1000&&cost<=5000)
{
d=cost*0.05;
}
else if(cost>5000&&cost<=10000)
{
d=cost*0.08;
}
else if(cost>10000)
{
d=cost*0.1;
}
else
{
System.out.println("Cost can not be zero or negative");
}
amount=cost-d;
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