During a special sale at a store, a 10% discount is taken on purchases over ₹ 1000/-. Write a program that asks for the amount of purchases, then calculates the discounted price.

Java Programming Language Decision Making in java (Article) Decision Making in java (Program)

6

Given Input:


Expected Output:


Program:

import java.util.Scanner;

public class SpecialSale {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter purchase amount (?): ");
        double amount = sc.nextDouble();

        double discount = 0;
        double finalAmount;

        // Apply 10% discount if amount is more than 1000
        if (amount > 1000) {
            discount = amount * 0.10;
        }

        finalAmount = amount - discount;

        System.out.println("Original Amount: ?" + amount);
        System.out.println("Discount: ?" + discount);
        System.out.println("Amount to Pay: ?" + finalAmount);

        sc.close();
    }
}

Output:


                                        

Explanation:

Logic Used

  • If purchase amount > ?1000,
    → Discount = 10% of amount

  • Otherwise,
    → No discount

  • Final Amount = Amount − Discount


This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.