package bankingsystem;
/**
*
* @author Archangel Macsika
*/
public abstract class BankAccount {
private String accountName;
private int accountNumber;
private double accountBalance;
public BankAccount() {
System.out.println("Welcome, to the new bank");
}
public BankAccount(String accountName, int accountNumber, double accountBalance) {
this.accountName = accountName;
this.accountNumber = accountNumber;
this.accountBalance = accountBalance;
}
//define method to get customer's Account Name
public String getAccountName() {
return accountName;
}
//define method to set customer's Account Name
public void setAccountName(String accountName) {
this.accountName = accountName;
}
//define method to get customer's Account Number
public int getAccountNumber() {
return accountNumber;
}
//define method to set customer's Account Number
public void setAccountNumber(int accountNumber) {
this.accountNumber = accountNumber;
}
//define method to get customer's Account Balance
public double getAccountBalance() {
return accountBalance;
}
//define method to set customer's Account Balance
public void setAccountBalance(double accountBalance) {
this.accountBalance = accountBalance;
}
//define method for customer's withdrawal
public void withdrawal(double amountWithDrawn)
{
if (accountBalance > 0.0){
accountBalance -= amountWithDrawn;
}
else {
System.out.println("Sorry, you currently have no money in your account!");
}
}
//define method for customer's account deposit
public double deposit(double amountDeposited) {
return accountBalance += amountDeposited;
}
//define method to print customer's account information
@Override
public String toString() {
return "Bank Account Information" + "\nAccount Name: " + getAccountName() + "\nAccount Number: " + getAccountNumber() + "\nAccount Balance: " + getAccountBalance();
}
}
package bankingsystem;
/**
*
* @author Archangel Macsika
*/
public class CheckingAccount extends BankAccount{
private double interestRate;
private double minimumBalance;
private double serviceCharge;
public CheckingAccount(String accountName, int accountNumber, double accountBalance, double interestRate, double minimumBalance, double serviceCharge) {
super(accountName, accountNumber, accountBalance);
this.interestRate = interestRate;
this.minimumBalance = minimumBalance;
this.serviceCharge = serviceCharge;
}
//define method to get Interest Rate
public double getInterestRate() {
return interestRate;
}
//define method to set Interest Rate
public void setInterestRate(double interestRate) {
this.interestRate = interestRate;
}
//define method to get Minimum Balance
public double getMinimumBalance() {
return minimumBalance;
}
//define method to set Minimum Balance
public void setMinimumBalance(double minimumBalance) {
this.minimumBalance = minimumBalance;
}
//define method to get Service Charge
public double getServiceCharge() {
return serviceCharge;
}
//define method to set Service Charge
public void setServiceCharge(double serviceCharge) {
this.serviceCharge = serviceCharge;
}
//define method to add Interest Rate to Account Balance
public void postInterestRate() {
setAccountBalance(getAccountBalance() + this.interestRate);
}
//define method to check Balance Status
public boolean isAccountBalanceLessThanMinimumBalance() {
if(getAccountBalance() < this.minimumBalance){
return true; // Account balance is lower than minimum balance
}
else{
return false; // Account balance is good to go
}
}
//define method to print Balance Status
public void printBalanceStatus() {
if(isAccountBalanceLessThanMinimumBalance()){
System.out.println("Account balance is lower than minimum balance");
}
else{
System.out.println("Account balance is good to go");
}
}
//define method to write a check
public void writeCheck(double checkAmount) {
if(isAccountBalanceLessThanMinimumBalance()){
System.out.println("Checking Transaction Denied! Account balance is currently lower than minimum balance!");
}
else
{
if((getAccountBalance() - checkAmount) < this.minimumBalance){
setAccountBalance(getAccountBalance() - getServiceCharge());
System.out.println("You've been charged " + getServiceCharge() + " for service charges.");
}
else
{
setAccountBalance(getAccountBalance() - checkAmount);
System.out.println("Checking Transaction Successful! " + checkAmount + " Checked out.");
}
}
}
//define method to withdraw from account
public void withdrawal(double amountWithDrawn) {
if(isAccountBalanceLessThanMinimumBalance()){
System.out.println("Withdrawal Transaction Denied! Account balance is currently lower than minimum balance!");
}
else
{
if((getAccountBalance() - amountWithDrawn) < this.minimumBalance)
{
setAccountBalance(getAccountBalance() - getServiceCharge());
System.out.println("You've been charged " + getServiceCharge() + " for service charges.");
}
else
{
setAccountBalance(getAccountBalance() - amountWithDrawn);
System.out.println("Withdrawal Transaction Successful! " + amountWithDrawn + " withdrawn from account.");
}
}
}
//define method to print customer's account information
@Override
public String toString() {
return "Bank Account Information for Checking Account" + "\nAccount Name: " + getAccountName() + "\nAccount Number: " + getAccountNumber() + "\nAccount Balance: " + getAccountBalance() + "\nInterest Rate: " + interestRate + "\nMinimum Balance: " + minimumBalance + "\nService Charge: " + serviceCharge;
}
}
package bankingsystem;
/**
*
* @author Archangel Macsika
*/
public class BankingSystem {
public static void main(String[] args) {
// Program for CheckingAccount class
CheckingAccount checkAcc = new CheckingAccount("Nsikak Imoh", 123456789, 10000.95, 100.50, 2000.00, 5.00);
System.out.println(checkAcc.getInterestRate());
checkAcc.setInterestRate(200.89);
checkAcc.postInterestRate();
System.out.println(checkAcc.getMinimumBalance());
checkAcc.setMinimumBalance(5000.00);
System.out.println(checkAcc.getServiceCharge());
checkAcc.setServiceCharge(10.99);
checkAcc.printBalanceStatus();
checkAcc.writeCheck(8000.00);
checkAcc.deposit(20000.00);
checkAcc.withdrawal(10000.00);
System.out.println(checkAcc.toString());
System.out.println("\n\n");
// Program for SavingsAccount class
SavingsAccount savingsAcc = new SavingsAccount("Archangel Macsika", 987654321, 20000.95, 50.50);
System.out.println(savingsAcc.getInterestRate());
savingsAcc.setInterestRate(250.85);
savingsAcc.postInterestRate();
savingsAcc.withdrawal(10000.00);
savingsAcc.deposit(20000.00);
System.out.println(savingsAcc.toString());
}
}
package bankingsystem;
/**
*
* @author Archangel Macsika
*/
public class Banks {
public static void main(String[] args) {
// Declare variables for common values
double accountBalance, standardServiceCharge, highServiceCharge, standardInterestRate, highInterestRate;
String accountName = "Nsikak Imoh";
int accountNumber = 1234567890;
accountBalance = 1000.50;
standardServiceCharge = 100.00;
standardInterestRate = 50.50;
highInterestRate = standardInterestRate * 2;
int limit = 3;
// Program for ServiceChargeChecking Class
ServiceChargeChecking scc = new ServiceChargeChecking();
scc.setName(accountName);
scc.setAccountNumber(accountNumber);
scc.setBalance(accountBalance);
scc.setServiceCharge(standardServiceCharge);
scc.setLimit(limit);
scc.writeCheck(800.00);
scc.createMonthlyStatement();
// Program for NoServiceChargeChecking Class
NoServiceChargeChecking nscc = new NoServiceChargeChecking();
nscc.setName(accountName);
nscc.setAccountNumber(accountNumber);
nscc.setBalance(accountBalance);
nscc.setInterestRate(standardInterestRate);
nscc.writeCheck(800.00);
nscc.createMonthlyStatement();
// Program for HighInterestChecking Class
HighInterestChecking hic = new HighInterestChecking();
hic.setName(accountName);
hic.setAccountNumber(accountNumber);
hic.setBalance(accountBalance);
hic.setInterestRate(highInterestRate);
hic.writeCheck(800.00);
hic.createMonthlyStatement();
// Program for SavingsAccount Class
SavingsAccount sa = new SavingsAccount();
sa.setName(accountName);
sa.setAccountNumber(accountNumber);
sa.setBalance(accountBalance);
sa.setInterestRate(standardInterestRate);
sa.deposit(2000.00);
sa.withdrawal(3500.50);
sa.createMonthlyStatement();
// Program for HighInterestSavings Class
HighInterestSavings his = new HighInterestSavings();
his.setName(accountName);
his.setAccountNumber(accountNumber);
his.setBalance(accountBalance);
his.setInterestRate(highInterestRate);
his.createMonthlyStatement();
// Program for CertificateOfDeposit Class
CertificateOfDeposit cod = new CertificateOfDeposit();
cod.setName(accountName);
cod.setAccountNumber(accountNumber);
cod.setBalance(accountBalance);
cod.setInterestRate(standardInterestRate);
cod.setNumberOfCDMaturityMonths(10);
cod.setCurrentCDMonth(4);
cod.createMonthlyStatement();
}
}