fork download
  1. import java.io.*;
  2. class calculatebill
  3. {
  4. double billpay;
  5. void bill(long units)
  6. {
  7. if(units<100)
  8. billpay=units*1.20;
  9. else if(units<300)
  10. billpay=100*1.20+200*2+(units-100)*2;
  11. else if(units>300)
  12. billpay=100*1.20+200*2+(units-300)*3;
  13. }
  14. }
  15. class computeelectricitybill extends calculatebill
  16. {
  17. public static void main(String args[])
  18. {
  19. long units;
  20. System.out.println("calculate bill using inheritance");
  21. try
  22. {
  23. System.out.println("enter no of units:");
  24. units=Integer.parseInt(in.readLine());
  25. computeelectricitybill b= new computeelectricitybill();
  26. b.bill(units);
  27. System.out.println("bill to pay:"+b.billpay);
  28. }
  29. catch(Exception e){}
  30.  
  31.  
  32.  
  33. }
  34. }
Success #stdin #stdout 0.09s 52544KB
stdin
Standard input is empty
stdout
calculate bill using inheritance
enter no of units: