calculate electricity bill when units consumed are provided as an input-programmingraja

 Aim:- Write a program to calculate electricity bill when units consumed are provided as an input. 

Unit          Rate
 0-100         1.0/unit 
101-200                 1.5/unit
 201-300              3.5/unit 
301 onward      4.5/unit


Software used:- Notepad, Command prompt


Program coding:-

class Bill 

        public static void main(String args[]) 

        {

  

int units;

units = Integer.parseInt(args[0]);


double bill=0;


        if(units<100)


bill=units*1.0;


else if(units<=200)


bill=100+(units-100)*1.5;


else if(units<=300)


bill=100+150+(units-200)*3.5;


else if(units>300)


bill=100+150+350+(units-300)*4.5;


      System.out.println("Bill is"+ bill); 

   } 

}


Output:-




Post a Comment

0 Comments