Guest User

Untitled

a guest
Jan 21st, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. import java.util.Random;
  2. import java.text.NumberFormat;
  3.  
  4. public abstract class Account {
  5. Random generator = new Random();
  6. protected int accountNumber;
  7. protected double balance;
  8. protected String account;
  9.  
  10.  
  11.  
  12.  
  13. public Account(int initialDeposit){
  14. balance = initialDeposit;
  15. accountNumber = generator.nextInt(89999);
  16. accountNumber += 10000;
  17.  
  18.  
  19. }
  20.  
  21. public final void deposit(int amount){
  22. balance += amount;
  23.  
  24. }
  25.  
  26. public String toString(){
  27.  
  28. NumberFormat Balance = NumberFormat.getInstance();
  29. return "Account: " + Balance.format( accountNumber)+ " " +"The Balance is " + Balance.format(balance)+ " ";
  30.  
  31. }
  32. public double accountBalance(double accountBalance){
  33. balance = accountBalance;
  34.  
  35. return balance;
  36.  
  37.  
  38. }
  39.  
  40. public abstract double withdraw();
  41.  
  42.  
  43. }
  44.  
  45.  
  46.  
  47. public class CheckingAccount extends Account
  48. {
  49. private final int MINIMUM_BALANCE = 100;
  50. private final int OVERDRAFT_FEE = 25;
  51. double deposit;
  52.  
  53. //-----------------------------------------------------------------
  54. // Constructor: Sets up this checking account using the specified
  55. // information
  56. //-----------------------------------------------------------------
  57. public CheckingAccount(int initialDeposit)
  58. {
  59. super(initialDeposit);
  60. }
  61.  
  62. //-----------------------------------------------------------------
  63. // withdraws amount from the account. If an overdraft occurs
  64. // a fee is deducted from the account
  65. //-----------------------------------------------------------------
  66. public double withdraw(int amount)
  67. {
  68. balance -= amount;
  69. System.out.println("Withdrew: " +amount + " Dollars From Chequing");
  70. if(balance < MINIMUM_BALANCE){
  71. System.out.println("You have overdrafted your minimum balance: " + OVERDRAFT_FEE + " dollar overdraft fee has been added");
  72. balance -= OVERDRAFT_FEE;
  73. }
  74. return amount;
  75. }
  76.  
  77. public String toString()
  78. {
  79.  
  80. String output= super.toString();
  81. output += "The minimum balance is " + MINIMUM_BALANCE;
  82. return output;
  83. }
  84.  
  85.  
  86.  
  87. import java.text.NumberFormat;
  88.  
  89. public class SavingsAccount extends Account
  90. {
  91. private double interestRate = 1.5;
  92.  
  93. //-----------------------------------------------------------------
  94. // Constructor: Sets up this savings account using the specified
  95. // information
  96. //-----------------------------------------------------------------
  97. public SavingsAccount(int initialDeposit)
  98. {
  99. super(initialDeposit);
  100. }
  101.  
  102. //-----------------------------------------------------------------
  103. // withdraws amount from the account if there is enough to draw
  104. // against
  105. //-----------------------------------------------------------------
  106.  
  107. public double withdraw(int amount)
  108. {
  109. if( amount > super.balance)
  110. {
  111. System.out.println("There is not enought money in your account");
  112. }
  113. else
  114. {
  115. super.balance -= amount;
  116. System.out.println("Withdrew: " +amount + " Dollars From Savings");
  117. }
  118. return amount;
  119. }
  120.  
  121. //-----------------------------------------------------------------
  122. // Recalculates the balance by applying interest monthly
  123. //-----------------------------------------------------------------
  124. public void recalculateBalance()
  125. {
  126. balance = balance * interestRate;
  127. }
  128.  
  129. public String toString()
  130. {
  131. String output= super.toString();
  132. output += "The interest rate is " + interestRate;
  133. return output;
  134.  
  135. }
  136. }
Add Comment
Please, Sign In to add comment