Back to Examples
package edu.iuk.BankProject1;
import java.io.Serializable;
import javax.swing.JOptionPane;
//Jacob Morris
public abstract class Account implements Serializable {
//Declare Variables
private String accountNumber;
protected double accountBalance;
private Customer customer;
protected int transCounter;
/**
*
* Account constructor requiring three
* attributes to create. Subclasses will be forced to call
* this constructor and set these required values.
*
* @param accountNumber String the account number
* @param accountBalance double the account balance
* @param customer Customer the customer information
*/
//Constructors
public Account(){
this.accountNumber="";
this.accountBalance = 0.0;
this.customer = null;
}
public Account(String accountNumber, double accountBalance, Customer customer){
this.accountNumber = accountNumber;
this.accountBalance = accountBalance;
this.customer = customer;
}
//Gets and Sets
public String getAccountNumber(){
return this.accountNumber;
}
public double getAccountBalance(){
return this.accountBalance;
}
public Customer getCustomer(){
return customer;
}
public void setAccountNumber(String accountNumber){
this.accountNumber = accountNumber;
}
public void setAccountBalance(double accountBalance){
this.accountBalance = accountBalance;
}
public void setCustomer(Customer customer){
this.customer = customer;
}
/**
*
* depositCurrency is used to add funds to an account
*
* @param deposit double the amount to add to the account
*
**/
public void depositCurrency(double deposit){
this.accountBalance += deposit;
//add a checking transaction
if(this.getClass()== Checking.class) {
this.transCounter++;
}
}
/**
*
* withdrawalCurrency is used to remove funds from an account
*
* @param withdrawal double the amount to remove from the account
*
**/
public void withdrawalCurrency(double withdrawal){
if(this.getClass()== Checking.class) {
if ((this.accountBalance - withdrawal) < 0){
System.out.println("\nInsufficient Funds. Only $" + this.accountBalance + " was withdrawn");
this.accountBalance = 0;
} else {
this.accountBalance = this.accountBalance - withdrawal;
}
//add a checking transaction
this.transCounter ++;
} else if(this.getClass()== Gold.class) {
this.accountBalance = this.accountBalance - withdrawal;
} else if(this.getClass()== Regular.class) {
if ((this.accountBalance - withdrawal) < 0) {
System.out.println("\nInsufficient Funds. Only $" + this.accountBalance + " was withdrawn");
this.accountBalance = 0;
} else {
this.accountBalance = this.accountBalance - withdrawal;
}
}
}
/**
*
* displayAccountInformation is used to display the account information in the console.
*
* No parameters
*
**/
public String displayAccountInformation(){
String output = "Account Information:\n";
output += "Account Number:" + this.accountNumber;
output += "\nAccount Balance:" + this.accountBalance + "\n";
//Display customer information
output += customer.displayCustomerInformation();
//Return the information in a string
return output;
}
}
//Checking Account
class Checking extends Account{
//Constructor
public Checking(){
super();
}
//Constructor
public Checking(String accountNumber, double accountBalance, Customer customer){
super(accountNumber, accountBalance, customer);
}
/**
*
* addFees is used to Add Withdrawal Fees. The first two are free. Each transaction after the first two is $3.
*
* no parameters
*
**/
public void addFees(){
if (transCounter >2) {
this.accountBalance-= (transCounter-2)*3;
}
//Reset the counter for number of transactions since you've already charged them for the month.
transCounter = 0;
}
}
//Gold Account
class Gold extends Account{
//Constructor
public Gold(){
super();
}
//Constructor
public Gold(String accountNumber, double accountBalance, Customer customer){
super(accountNumber, accountBalance, customer);
}
/**
*
* addGoldInterest is used to add interest to a gold account
*
*no parameters
*
**/
public void addGoldInterest(){
this.accountBalance= (this.accountBalance - Math.abs(this.accountBalance * .05));
}
}
//Regular Account
class Regular extends Account{
//Constructor
public Regular(){
super();
}
//Constructor
public Regular(String accountNumber, double accountBalance, Customer customer){
super(accountNumber, accountBalance, customer);
}
/**
*
* addRegularInterest is used to add interest to an regular account
*
* no parameters
*
**/
public void addRegularInterest(){
if ((this.accountBalance)*.06 >10) {
this.accountBalance = this.accountBalance -(this.accountBalance * .06);
} else {
this.accountBalance -= 10;
}
}
}
Back to Examples