Computer Science, asked by debjoym, 1 year ago

WAP in java for the following question.Best answer will be marked as brainliest...

Attachments:

Answers

Answered by QGP
2

Cloth Showroom Discounts - Java

We will first take in the user input for the total cost. After that, we would use a series of if-else blocks to assign values to discount rate and gift.

Finally, we calculate the amount to be paid and display it along with the gift to be given.

The Unicode for the INR Symbol (₹) is U+20B9. It has been typed in using the escape sequence \u20B9 so that it can be printed when we execute the program.

\rule{320}{1}

import java.util.Scanner;   //Import Scanner

public class ClothShowroom

{

   public static void main(String[] args)

   {

       Scanner scr = new Scanner(System.in);   //Creating Scanner object

       //Take user input for Total Cost

       //The Unicode for the INR symbol is U+20B9

       System.out.print("Enter the total cost: \u20B9");

       double totalCost = scr.nextDouble();

       double discountRate;

       String gift;

       if(totalCost > 0)   //Validate totalCost to be correct

       {

           if(totalCost <= 2000)

           {

               discountRate = 5;

               gift = "Calculator";

           }

           else if(totalCost <= 5000)

           {

               discountRate = 10;

               gift = "School Bag";

           }

           else if(totalCost <= 10000)

           {

               discountRate = 15;

               gift = "Wall Clock";

           }

           else

           {

               discountRate = 20;

               gift = "Wrist Watch";

           }

           //Calculate the amount to pay using the value of discount rate

           double amountToPay = ((100-discountRate)*totalCost)/100;

           //Print out the amount to pay and the gift

           System.out.println("Amount to be paid:\u20B9"+amountToPay);

           System.out.println("Gift: "+gift);

       }

       else    //Condition of totalCost <= 0

       {

           System.out.println("Invalid Total Cost.");

       }

   }

}

Attachments:
Similar questions