Page 191 - Cs_withBlue_J_C11_Flipbook
P. 191

Program 2      State Electricity Board calculates the electricity bill depending on the previous month and
                                 current month meter reading. The amount generated depends on the following criteria.
                                              Units(present-previous)              Per unit rate
                                              ---------------------------------------  -------------------
                                              100 units or below                   ` 2.25 / Unit
                                              Next 250 units                       ` 3.50 / Unit
                                              Next 250 units                       ` 4.75 / Unit
                                              More than 600 units                  ` 6 / Unit

                                 Write a Java program to generate the bill after taking Month name, Name of the consumer,
                                 Previous  and  Current  meter  reading  from  the  user.  The  bill  should  be  generated  in  the
                                 following format.
                                              Bill for State Electricity Board

                                              Month _____________
                                              Name of Consumer ___________
                                              Previous Meter Reading ___________
                                              Current Meter Reading ____________
                                              Bill Amount ____________
                   1      import java.util.*;
                   2      class Bill_Electricity

                   3          {

                   4              public static void main()
                   5              {
                   6                  Scanner sc= new Scanner(System.in);

                   7                  String mon_name, cus_name;
                   8                  int pr_read, cur_read, unit_con;

                   9                  double bill_amt=0.0;

                  10                   System.out.print("Enter the month for which amount is to be calculated
                                         : ");
                  11                  mon_name=sc.next();
                  12                  sc= new Scanner(System.in);

                  13                  System.out.print("Enter name of the consumer : ");
                  14                  cus_name=sc.nextLine();

                  15                  System.out.print("Enter previous meter reading : ");
                  16                  pr_read=sc.nextInt();
                  17                  System.out.print("Enter current meter reading : ");

                  18                  cur_read=sc.nextInt();

                  19                  unit_con=cur_read-pr_read;
                  20                  if(unit_con<=100)
                  21                      bill_amt = unit_con * 2.25;



                                                                                                                       189
                                                                                                 Statements and Scope  189
   186   187   188   189   190   191   192   193   194   195   196