Page 193 - Cs_withBlue_J_C11_Flipbook
P. 193

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;
                  22                  if(unit_con>100 && unit_con<=350)

                  23                      bill_amt = (100 * 2.25)+(unit_con-100)*3.50;
                  24                  if(unit_con>351 && unit_con<=600)

                  25                      bill_amt = (100*2.25) + (250 * 3.50) + (unit_con-350)* 4.75;
                  26                  if(unit_con>600)

                  27                       bill_amt = (100*2.25) + (250 * 3.50) + (250* 4.75) + (unit_con
                                             - 600) * 6;
                  28                  System.out.println("\tSTATE ELECTRICITY BOARD");

                  29                  System.out.println("Month : "+mon_name);
                  30                  System.out.println("Name of Consumer : "+ cus_name);
                  31                  System.out.println("Previous Meter Reading : "+ pr_read);

                  32                  System.out.println("Current Meter Reading : "+cur_read);

                  33                  System.out.println("Amount : " + bill_amt);
                  34              }
                  35          }



                  Program 4      Write a Java program that takes a number from the user and generates an integer between
                                 1 and 7 and displays the name of the weekday.
                   1      import java.util.*;

                   2      class switch_dayname
                   3       {

                   4        public static void main(String[] args)


                                                                                                                       191
                                                                                                 Statements and Scope  191
   188   189   190   191   192   193   194   195   196   197   198