fork(2) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. interface Account
  6. {
  7. public void calculateInterest();
  8. public double getInterest();
  9. public String getType();
  10. }
  11.  
  12. class SavingsAccount implements Account
  13. {
  14. public void calculateInterest() { }
  15. public double getInterest() { return 6.5; }
  16. public String getType() { return "SavingsAccount"; }
  17. }
  18.  
  19. class LoanAccount implements Account
  20. {
  21. public void calculateInterest() { }
  22. public double getInterest() { return 11.5; }
  23. public String getType() { return "LoanAccount"; }
  24. }
  25.  
  26. class InterestCalculation
  27. {
  28. public void getInterestRate(Account objAccount)
  29. {
  30. System.out.print ("Interest Rate for "+objAccount.getType()+" is ");
  31. System.out.print (objAccount.getInterest());
  32. System.out.println (" %");
  33. }
  34.  
  35. }
  36.  
  37. class IdeOne
  38. {
  39. public static void main(String[] args)
  40. {
  41. InterestCalculation objIntCal = new InterestCalculation();
  42. objIntCal.getInterestRate(new LoanAccount());
  43. objIntCal.getInterestRate(new SavingsAccount());
  44. }
  45. }
  46.  
Success #stdin #stdout 0.07s 2841600KB
stdin
Standard input is empty
stdout
Interest Rate for LoanAccount is 11.5 %
Interest Rate for SavingsAccount is 6.5 %