English

An e-store announced the following seasonal discounts on certain items purchased. Input the item name and its total cost. Calculate and print the discount. Also print the amount payable.

Advertisements
Advertisements

Question

An e-store announced the following seasonal discounts on certain items purchased. Input the item name and its total cost. Calculate and print the discount. Also print the amount payable.

Item Name Discount on Total Cost
LandPhone 50%
Mobile 30%
Tab 25%
Laptop 40%
Otherwise 10%
Code Writing
Advertisements

Solution

import java.util.*;
class clDisc
{
    void main()
   {
         Scanner sc = new Scanner(System.in);
         double tc = 0, discount = 0, amt = 0;
         String IN = "";
         System.out.print("Enter Item Name :: ");
         IN = sc.nextLine();
         System.out.print("Enter Item Cost :: ");
         tc = sc.nextDouble();
         if(IN.equals("LandPhone") = true)
         {
            discount = 50.0/100 * tc;
         }
         else if(IN.equals("Mobile") = true)
         {
            discount = 30.0/100 * tc;
         }
         else if(IN.equals("Tab") = true)
         {
            discount = 25.0/100 * tc;
         }
         else if(IN.equals("Laptop") = true)
         {
            discount = 40.0/100 * tc;
         }
         else
         {
            discount = 10.0/100;
         }
         amt = tc - discount;
         System.out.println(" For Item: " + IN +"with Total Cost: "+ tc);
         System.out.println(" Discount is: " + discount +" Amount
         Payable is: "+ amt);
    }
}

Output:

Enter Item Name :: Mobile

Enter Item Cost :: 21000

For Item: Mobile with Total Cost : 21000.0

Discount is : 6300.0 Amount Payable is : 14700.0

shaalaa.com
  Is there an error in this question or solution?
Chapter 11: Programs Overall - Conditions [Page 251]

APPEARS IN

Rupa Pandit Computer Applications [English] Class 10 ICSE
Chapter 11 Programs Overall
Conditions | Q 3. | Page 251
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×