Page 286 - CA_Blue( J )_Class9
P. 286

19              else
                   20              if(u<=350)

                   21                  billamount = (150 * 2.5) + (u-150)*4.5;
                   22              else

                   23              if(u<=850)
                   24                  billamount = (150 * 2.5) + (200 * 4.5) + (u-350)*7.5;
                   25              else

                   26                  billamount = (150 * 2.5) + (200 * 4.5) + (500*7.5) + (u-850)*8.5;

                   27              billamount = billamount + 250;
                   28              System.out.println("\n  Eletricity Bill");
                   29              System.out.println("Customer Name : "+name);  // Name of the customer

                   30              System.out.println("Bill Amount   : "+billamount); // Billamount
                   31          }

                   32      }

                  You will get the following output:
                         Enter Name of the customer : Amar
                         Enter previous meter reading : 245
                         Enter present meter reading : 380
                         Electricity Bill
                         Customer Name : Amar
                         Bill Amount   : 587.5

                                                         VARIABLE DESCRIPTION
                             NAME              DATATYPE                           DESCRIPTION
                        name             String                 Name of the customer
                        prv              int                    Previous Meter Reading
                        pre              int                    Present Meter Reading
                        u                int                    Units Consumed
                        billamount       double                 Bill Amount

                  (vi)  Programs based on switch case.

                                  Write a calculator program to input two numbers and print the following:
                   Program 10
                                  1.  Sum
                                  2.  Difference
                                  3.   Product
                                  4.  Quotient
                                  5.  Remainder
                     1     import java.util.*;                                  // Importing “util” package

                     2     class calculator                                     // Class name
                     3     {



                   284    Touchpad Computer Applications-IX
   281   282   283   284   285   286   287   288   289   290   291