Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. public class Account{
  2. //fields
  3. public static int NumberOfAccounts;
  4. public static int Id;
  5. public static double Balance;
  6. public static double AnnualInterestRate;
  7.  
  8. // constructor with no arg
  9. Account(){
  10. NumberOfAccounts = 0;
  11. Id = 0;
  12. Balance = 0;
  13. AnnualInterestRate = 0;
  14. }
  15. //constructor
  16. public Account(int Id, double newBal, double annIntRate){
  17. Id = NumberOfAccounts+1;
  18. Balance = newBal;
  19. AnnualInterestRate = annIntRate;
  20. NumberOfAccounts++;
  21. }
  22. //methods
  23. public int getId(){
  24. return Id;
  25. }
  26.  
  27. public double getBalance(){
  28. return Balance;
  29. }
  30.  
  31. public double getAnnualInterestRate(){
  32. return AnnualInterestRate;
  33. }
  34.  
  35. public void setID(int newID){
  36. newID = NumberOfAccounts + 1;
  37. Id = newID;
  38. }
  39.  
  40. public void setBalance(double newBal){
  41. if (newBal > 0){
  42. Balance = newBal;
  43. }
  44. else{
  45. System.out.print("Balance cannot be set below zero");
  46. }
  47. }
  48.  
  49.  
  50. public void setAnnualInterestRate(double userAnnualInterestRate){
  51. if(userAnnualInterestRate > 0){
  52. AnnualInterestRate = userAnnualInterestRate;
  53. }
  54. else{
  55. System.out.print("You cannot set an interest rate below zero");
  56. }
  57. }
  58.  
  59. public double getMonthlyInterestRate(){
  60. return AnnualInterestRate/12;
  61. }
  62.  
  63. public void withdraw(double amount){
  64. if(amount <= 0){
  65. System.out.print("You must withdraw an amount greater than zero");
  66. }
  67.  
  68. if(Balance < amount){
  69. System.out.print("Insufficient funds");
  70. }
  71. else{
  72. Balance = Balance - amount;
  73. }
  74.  
  75. }
  76. public void deposit(double amount){
  77. if(amount < 0){
  78. System.out.print("You must deposit an amount greater than zero");
  79. }
  80. else{
  81. Balance += amount;
  82. }
  83. }
  84.  
  85. public int getNumberOfAccounts(){
  86. return NumberOfAccounts;
  87. }
  88.  
  89. public void transfer(Account x, double amount){
  90. withdraw(amount);
  91. x.deposit(amount);
  92. }
  93.  
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement