Sunday, 5 June 2011


THIS IS AN EXAMPLE OF SIMPLE JAVA PROGRAMING EXPLAINING THE CONCEPT OF NESTED IF-ELSE STATEMENT
Code shared by UMANG MISTRY X(VISSANJI ACADEMY)



This program calculate electricity bill based on unit of volts consumed,(all the rates are assumed    for demonstration purpose ). base amt = 200 for 100 units,if  100 >unit <200 = extra_units*5,
 * if  200 >unit <200 = extra_units*6(excluding base + 100 units),if  300 >unit = extra_units*8  (excluding base + 100 units + 100 units )

Code:
/**
 *
 *
 *
 *
 */
public class bill
{
   int bill;
   public void main(int units)
   {
      final  int base = 200;//DECLARING BASE AS THE CONSTANT VALUE
     
      if (units>100)
      {
       if (units>200)
       {
        if (units>300)
       {
          
      
           bill =base+(500)+(600)+ (units - 300)*8;//UNITS > 300, 500 AS (100*5) AND 600 AS (100*6)
         }
              else
              bill = base+(500)+(units -200)*6;//UNITS > 200, 500 AS (100*5)
              }
             else
             bill = base+(units-100)*5;//UNITS > THAN 100
            }
           else
           bill = base ;//UNITS > 0
System.out.println("MUMBAI ELECTRICITY LTD, MUMBAI "+bill);
System.out.println("_________________________");
System.out.println("Units Conseumed : "+units);
System.out.println("Total Bill : "+bill);
}
}

Comment bellow for your query and feedback... :)

Related Posts :



0 comments:

Confused? Feel free to ask

Post a Comment