Advertisement
tjb1

Untitled

Nov 19th, 2012
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1.  
  2. public class SavingsAccount {
  3.  
  4. //data members
  5. // are the basic characteristics of the object
  6. private double interest;
  7. private double balance;
  8.  
  9.  
  10.  
  11. //method members
  12. //are the functionalities of the object
  13.  
  14. //constructors These methods create (instantiate) an instance of the object
  15.  
  16. /**
  17. * Default constructor sets the packageWeight to 0 and the miles to 0
  18. */
  19. public SavingsAccount(){
  20. interest = 0;
  21. balance = 0;
  22.  
  23. }
  24.  
  25. /**
  26. * full constructor sets the interest and the balance according to the parameters
  27. * @param interest is the interest rate
  28. * @param balance is the account balance
  29. */
  30. public SavingsAccount(double interest, double balance){
  31. this.interest = interest;
  32. this.balance = balance;
  33.  
  34. }
  35.  
  36. //getters
  37.  
  38. /**
  39. * this method returns the interest
  40. * @return the interest
  41. */
  42. public double getinterest(){
  43. return interest;
  44. }
  45.  
  46.  
  47. /**
  48. * this method returns the account balance
  49. * @return the balance
  50. */
  51. public double getbalance(){
  52. return balance;
  53. }
  54.  
  55.  
  56. //setters
  57.  
  58. /**
  59. * This method resets the interest and account balance according to the parameter
  60. * @param value will be set as the new value
  61. */
  62. public void setinterest( double value ) {
  63. this.interest = value;
  64. }
  65.  
  66. public void setbalance( double value ) {
  67. this.balance = value;
  68. }
  69.  
  70.  
  71. //toString method
  72.  
  73. public String toString(){
  74. String str;
  75.  
  76. str = ("\tInterest - " + interest
  77. + "\tBalance - " + balance);
  78. return str;
  79. }
  80.  
  81. //all other object specific methods
  82.  
  83.  
  84. public double deposit(){
  85. double deposit = 0;
  86.  
  87.  
  88. return balance += deposit;
  89.  
  90. }
  91.  
  92. public double withdrawal(){
  93. double withdrawal = 0;
  94.  
  95.  
  96. return balance -= withdrawal;
  97.  
  98. }
  99.  
  100.  
  101. public double newBalance() {
  102.  
  103. return balance += ((interest/12)*balance);
  104. }
  105.  
  106.  
  107. }//end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement