Monday, April 15, 2013

Selenium : Units of Electricity bill

Calculate Units of Electricity bill

0-50      -> $.5/Unit
50-100  ->$1.5/Unit
100-200->$2 /unit
150-200->$3/Unit
>200    ->  $4/unit


import javax.swing.JOptionPane;

public class Electricity
{
 public static void main(String[] args)
 {
  int iUnit=Integer.parseInt(JOptionPane.showInputDialog("Enter units consumed"));

  if (iUnit<= 50) // ex 30 unit ==$0.5
  {
   System.out.print("Pay ="+"$.5");
 
  }
  else if (50  < iUnit && iUnit <=100 )  //Eg 70 Unit = 30.5
  {
   System.out.print("Pay =$"+(.5+(iUnit-50)*1.5));
  }
  else if (100  < iUnit && iUnit <=150 ) //Eg 120 Unit = 115.5
  {
   System.out.print("Pay =$"+( ((iUnit-100)*2) + ((50*1.5)) +(.5)));
  }
  else if (150  < iUnit && iUnit <=200 ) //Eg 170 Unit =$235.5
  {
   System.out.print("Pay =$"+((iUnit-150)*3+(50*2)+(50*1.5)+.5));
  }
  else if (iUnit >200 )  //Eg 210 units
  {
   System.out.print("Pay =$"+((iUnit-200)*4+(50*3)+(50*2)+(50*1.5)+.5));
  }
 }
}




No comments:

Post a Comment