KnowledgeBoat Logo

Computer Applications

Star mall is offering discount on various types of products purchased by its customers. Following table shows different type of products and their respective code along with the discount offered. Based on the code entered, the mall is calculating the total amount after deducting the availed discount. Create a program to calculate total amount to be paid by the customer.

ItemItem CodeDiscount
LaptopL5%
LCDD7%
XBoxX10%
PrinterP11%

Java

Java Conditional Stmts

10 Likes

Answer

import java.util.Scanner;

public class KboatStarMall
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter purchase amount: ");
        double amt = in.nextDouble();
        System.out.print("Enter item code: ");
        char code = in.next().charAt(0);
        int d = 0;
        switch (code) {
            case 'L':
            d = 5;
            break;
            
            case 'D':
            d = 7;
            break;
            
            case 'X':
            d = 10;
            break;
            
            case 'P':
            d = 11;
            break;
            
            default:
            System.out.println("Invalid Item Code");
        }
        
        double disc = amt * d / 100.0;
        double total = amt - disc;
        
        System.out.println("Total amount payable = " + total);
    }
}

Output

BlueJ output of Star mall is offering discount on various types of products purchased by its customers. Following table shows different type of products and their respective code along with the discount offered. Based on the code entered, the mall is calculating the total amount after deducting the availed discount. Create a program to calculate total amount to be paid by the customer.

Answered By

4 Likes


Related Questions