Page 184 - CA_Blue( J )_Class9
P. 184

You will get the following output:


















                                  Write a program to input the units of electricity consumed by a customer and print the bill
                   Program 6
                                  amount to be paid according to the following criteria.
                                  Units of electricity         Rate per unit
                                  First 100 units              4.5 per unit
                                  next 250 units               5.5 per unit
                                  next 300 units               7 per unit
                                  above 650 units              9 per unit

                     1     import java.util.*;
                     2     class electricity_consumed

                     3     {
                     4         public static void main()

                     5         {
                     6             Scanner sc=new Scanner(System.in);

                     7             int u;
                     8             double b;

                     9             System.out.println("Enter unit consumed ");
                    10             u=sc.nextInt();

                    11             if(u<=100)
                    12                 b=u*4.5;

                    13             else if(u<=350)
                    14                 b=(100*4.5)+(u-100)*5.5;

                    15             else if(u<=650)
                    16                 b=(100*4.5)+(250*5.5)+(u-350)*7;

                    17             else
                    18                 b=(100*4.5)+(250*5.5)+(300*7)+(u-650)*9;

                    19             System.out.println("Bill amount "+b);
                    20         }
                    21     }



                   182    Touchpad Computer Applications-IX
   179   180   181   182   183   184   185   186   187   188   189