Advertisement
vallec

Untitled

Jan 24th, 2024
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 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. if(creditType == CreditType.STUDENT) {
  31. this.interest = 10.0;
  32. } else if (creditType == CreditType.HOUSE) {
  33. this.interest = 7.0;
  34. } else if (creditType == CreditType.AUTO) {
  35. this.interest = 5.0;
  36. }
  37.  
  38. }
  39.  
  40. @Override
  41. public String toString() {
  42. return "Credit type: " + getCreditType() + " Interest " + getInterest() + "%";
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement