A electricity board charges the following rates to domestic users to charge large consumption of energy. For first 100 units - 40paise/ unit , for next 200 units – 50paise/ unit , for next or beyond 300 units – 60paise /unit, if the total bill is more than Rs.250 then an additional charge of 15% is added to the bill. Write a program that read the names of the users and number of units consumed and print the charges with names.

class Charge
   {
     public static void main(String[] args)
      {
       float p;
       int units=Integer.parseInt(System.console().readLine("enter the units="));
       String userName=System.console().readLine("entr the user name=");
        if(units<=100)
          {
            p=units*.4f;
            System.out.println("rs="+p);
           }
          else
            {
             if((units>100)&&(units<=300))
             {
                p=(100*.40f)+((units-100)*.50f);
                System.out.println("rs="+p);
             }
            else
               {
                 p=(100*(40/100f))+(200*(50/100f))+((units-300)*(60/100f));
                 System.out.println("rs="+p);
               }
             }
          if(p>250)
             {
               p=p+p*(15/100f);
               System.out.println("Bill="+p);
             }
        System.out.println("userName="+userName+" & Bill="+p);
      }
  }

              
          

2 comments: