Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- import java.text.NumberFormat;
- public abstract class Account {
- Random generator = new Random();
- protected int accountNumber;
- protected double balance;
- protected String account;
- public Account(int initialDeposit){
- balance = initialDeposit;
- accountNumber = generator.nextInt(89999);
- accountNumber += 10000;
- }
- public final void deposit(int amount){
- balance += amount;
- }
- public String toString(){
- NumberFormat Balance = NumberFormat.getInstance();
- return "Account: " + Balance.format( accountNumber)+ " " +"The Balance is " + Balance.format(balance)+ " ";
- }
- public double accountBalance(double accountBalance){
- balance = accountBalance;
- return balance;
- }
- public abstract double withdraw();
- }
- public class CheckingAccount extends Account
- {
- private final int MINIMUM_BALANCE = 100;
- private final int OVERDRAFT_FEE = 25;
- double deposit;
- //-----------------------------------------------------------------
- // Constructor: Sets up this checking account using the specified
- // information
- //-----------------------------------------------------------------
- public CheckingAccount(int initialDeposit)
- {
- super(initialDeposit);
- }
- //-----------------------------------------------------------------
- // withdraws amount from the account. If an overdraft occurs
- // a fee is deducted from the account
- //-----------------------------------------------------------------
- public double withdraw(int amount)
- {
- balance -= amount;
- System.out.println("Withdrew: " +amount + " Dollars From Chequing");
- if(balance < MINIMUM_BALANCE){
- System.out.println("You have overdrafted your minimum balance: " + OVERDRAFT_FEE + " dollar overdraft fee has been added");
- balance -= OVERDRAFT_FEE;
- }
- return amount;
- }
- public String toString()
- {
- String output= super.toString();
- output += "The minimum balance is " + MINIMUM_BALANCE;
- return output;
- }
- import java.text.NumberFormat;
- public class SavingsAccount extends Account
- {
- private double interestRate = 1.5;
- //-----------------------------------------------------------------
- // Constructor: Sets up this savings account using the specified
- // information
- //-----------------------------------------------------------------
- public SavingsAccount(int initialDeposit)
- {
- super(initialDeposit);
- }
- //-----------------------------------------------------------------
- // withdraws amount from the account if there is enough to draw
- // against
- //-----------------------------------------------------------------
- public double withdraw(int amount)
- {
- if( amount > super.balance)
- {
- System.out.println("There is not enought money in your account");
- }
- else
- {
- super.balance -= amount;
- System.out.println("Withdrew: " +amount + " Dollars From Savings");
- }
- return amount;
- }
- //-----------------------------------------------------------------
- // Recalculates the balance by applying interest monthly
- //-----------------------------------------------------------------
- public void recalculateBalance()
- {
- balance = balance * interestRate;
- }
- public String toString()
- {
- String output= super.toString();
- output += "The interest rate is " + interestRate;
- return output;
- }
- }
Add Comment
Please, Sign In to add comment