Page 215 - ComputerScience_Class_11
P. 215

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(String args[])

                   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;

                                       System.out.print("Enter the month for which amount is to be calculated
                  10                     : ");
                  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;






                                                                                              Statements and Scope  213
   210   211   212   213   214   215   216   217   218   219   220