Dremendo Tag Line

Input purchase price and calculate discount in Java

if else if - Question 11

In this question, we will see how to input the purchase amount and print the discount amount and the net bill amount after deducting the discount amount in Java programming using the if else if statement. To know more about if else if statement click on the if else if statement lesson.

Q11) A showroom gives discount according to the following slab rates on the purchase amount.

Purchase Amount Discount
Up to 5,000 No Discount
5,001 to 10,000 10% of the amount exceeding 5000
10,001 to 20,000 20% of the amount exceeding 10,000
20,001 to 30,000 30% of the amount exceeding 20,000
More than 30,000 40% of the amount exceeding 30,000

Write a program in Java to input the purchase amount and print the discount amount and the net bill amount after deducting the discount amount.

Program

import java.util.Scanner;

public class Q11
{
    public static void main(String args[])
    {
        int p;
        float dis;
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter purchase amount ");
        p=sc.nextInt();

        if(p<=5000)
        {
            dis=0;
        }
        else if(p>5000 && p<=10000)
        {
            dis=(p-5000)*(10/100.0f);
        }
        else if(p>10000 && p<=20000)
        {
            dis=(p-10000)*(20/100.0f);
        }
        else if(p>20000 && p<=30000)
        {
            dis=(p-20000)*(30/100.0f);
        }
        else
        {
            dis=(p-30000)*(40/100.0f);
        }

        System.out.println("Discount Amount = " + dis);
        System.out.print("Net Bill Amount = " + (p-dis));
    }
}

Output

Enter purchase amount 25648
Discount Amount = 1694.4
Net Bill Amount = 23953.6
video-poster