Untitled
unknown
plain_text
a year ago
4.7 kB
5
Indexable
import java.util.Scanner;
public class Bank {
// This class is called the Bank class. This class allows users to manage and interact with their bank account.
// Its purpose is to simulate common banking applications such as depositing and withdrawing money, trasnferring funds between accounts and calculating the amount of interest.
// It also allows me to learn and become better at object oriented programming by allowing me to work with different OOP principles such as encapsulation, method overloading, and method overrides.
public static void main (String[] args){
// 2 default constructor objects
BankAccount bankAccount1 = new BankAccount();
BankAccount bankAccount2 = new BankAccount();
// 2 overloaded constructor objects
// Scanner for first object
Scanner scan = new Scanner(System.in);
System.out.println("Enter the account holder's name: ");
String bankAcc3Name = scan.nextLine();
System.out.println("Enter the account number: ");
int bankAcc3Num = scan.nextInt();
System.out.println("Enter the account balance: ");
double bankAcc3Bal = scan.nextDouble();
scan.nextLine();
System.out.println("What type of account is this? Savings/Checkings: ");
String bankAcc3Type = scan.nextLine();
// Object itself
BankAccount bankAccount3 = new BankAccount(bankAcc3Name, bankAcc3Num, bankAcc3Bal, bankAcc3Type);
// Scanner for second object
System.out.println("Enter the account holder's name: ");
String bankAcc4Name = scan.nextLine();
System.out.println("Enter the account number: ");
int bankAcc4Num = scan.nextInt();
System.out.println("Enter the account balance: ");
double bankAcc4Bal = scan.nextDouble();
System.out.println("What type of account is this? Savings/Checkings: ");
String bankAcc4Type = scan.nextLine();
// Object itself
BankAccount bankAccount4 = new BankAccount(bankAcc4Name, bankAcc4Num, bankAcc4Bal, bankAcc4Type);
// Testing getter on 1 object
System.out.println(bankAccount1.getNameAccountHolder());
System.out.println(bankAccount1.getAccountNumber());
System.out.println(bankAccount1.getBalance());
System.out.println(bankAccount1.getAccountType());
// Testing the getters
System.out.println("Account Holder: " + bankAccount1.getNameAccountHolder());
System.out.println("Account Balance: $" + bankAccount4.getBalance());
// Testing toString override
System.out.println(bankAccount3.toString());
// Testing the setters
bankAccount1.setAccountType("Checkings Account");
bankAccount2.setNameAccountHolder("Mark Bossman");
System.out.println(bankAccount1.getAccountType());
System.out.println(bankAccount2.getNameAccountHolder());
// Comparing the 2 default objects
if (bankAccount1.equals(bankAccount2)) {
System.out.println("The two default accounts are equal.");
} else {
System.out.println("The two default accounts are not equal.");
}
// Comparing the 2 overloaded constructor objects
if (bankAccount3.equals(bankAccount4)) {
System.out.println("The two default accounts are equal.");
} else {
System.out.println("The two default accounts are not equal.");
}
// Testing custom method 1
System.out.println("What is the amount of interest that you have? ");
double interestMonth = scan.nextDouble();
System.out.println("The interest will be: "+bankAccount4.calculateInterest(interestMonth));
// Testing custom method 2
System.out.println("What is the number of months you wil deposit money?");
int numMonths = scan.nextInt();
System.out.println("How much money are you going to deposit every month? ");
double depositMoney = scan.nextDouble();
System.out.println("The total balance after "+numMonths+" will approximately be: "+bankAccount4.estimateFutureBalance(numMonths, depositMoney));
// Testing custom method 3
System.out.println("How much money do you want to deposit? ");
double amtDeposit = scan.nextDouble();
bankAccount4.deposit(amtDeposit);
// Testing custom method 4
System.out.println("How much money do you want to withdraw?");
double withdrawMoney = scan.nextDouble();
bankAccount4.withdraw(withdrawMoney);
}
}
Editor is loading...
Leave a Comment