Advertisement
vallec

Credit

Jan 24th, 2024
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. public class Credit {
  2. public enum CreditType {
  3. STUDENT,
  4. HOUSE,
  5. AUTO
  6. }
  7.  
  8. private CreditType creditType;
  9. private double interest;
  10.  
  11. public Credit(CreditType creditType) {
  12. this.creditType = creditType;
  13. setInterest(creditType);
  14. }
  15.  
  16. public CreditType getCreditType() {
  17. return creditType;
  18. }
  19.  
  20. public void setCreditType(CreditType creditType) {
  21. this.creditType = creditType;
  22. setInterest(creditType);
  23. }
  24.  
  25. public double getInterest() {
  26. return interest;
  27. }
  28.  
  29. private void setInterest(CreditType creditType) {
  30. switch (creditType) {
  31. case STUDENT:
  32. this.interest = 10.0;
  33. break;
  34. case HOUSE:
  35. this.interest = 7.0;
  36. break;
  37. case AUTO:
  38. this.interest = 5.0;
  39. break;
  40. }
  41. }
  42.  
  43. @Override
  44. public String toString() {
  45. return "Credit type: " + getCreditType() + " Interest " + getInterest() + "%";
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement