Computer Applications

A cloth showroom has announced festival discounts and the gifts on the purchase of items, based on the total cost as given below:

Total CostDiscountGift
Up to ₹ 2,0005%Calculator
₹ 2,001 to ₹ 5,00010%School Bag
₹ 5,001 to ₹ 10,00015%Wall Clock
Above ₹ 10,00020%Wrist Watch

Write a program to input the total cost. Compute and display the amount to be paid by the customer along with the gift.

Java

Java Conditional Stmts

205 Likes

Answer

import java.util.Scanner;

public class KboatClothDiscount
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter total cost: ");
        double cost = in.nextDouble();
        String gift;
        double amt;
        
        if (cost <= 2000.0) {
            amt = cost - (cost * 5 / 100);
            gift = "Calculator";
        }
        else if (cost <= 5000.0) {
            amt = cost - (cost * 10 / 100);
            gift = "School Bag";
        }
        else if (cost <= 10000.0) {
            amt = cost - (cost * 15 / 100);
            gift = "Wall Clock";
        }
        else {
            amt = cost - (cost * 20 / 100);
            gift = "Wrist Watch";
        }
        
        System.out.println("Amount to be paid: " + amt);
        System.out.println("Gift: " + gift);
        
    }
}

Variable Description Table

Program Explanation

Output

Answered By

85 Likes


Related Questions