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