Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Simple Banking Management System (Java) can someone please FIX! CODE 1: TestMain.java public class TestMain { public static void main(String[] args) { Bank bank =
Simple Banking Management System (Java)
can someone please FIX!
CODE 1: TestMain.java
- public class TestMain {
- public static void main(String[] args) {
- Bank bank = new Bank("username", "password");
- // adding account to list of accounts in Bank object
- Address address1 = new Address(1, "street", "subhurb", "city");
- Account account1 = new Account("name1", 1, 20000, address1);
- bank.addAccount(account1);
- Address address2 = new Address(2, "street2", "subhurb2", "city2");
- Account account2 = new Account("name2", 2, 50000, address2);
- bank.addAccount(account2);
- // total balance of all account
- System.out.println(bank.calcTotalBalance());
- // printing all account information
- bank.printAllAccounts();
- // get account by id
- Account accoundFound = bank.findAccount(1);
- // deposit money to account
- accoundFound.deposit(3000);
- System.out.println(accoundFound.getBalance());
- //making purchase from account 10000
- accoundFound.makePurchase(1,"city", "description", 10000);
- // printing all transation of account
- accoundFound.printTransactions();
- accoundFound.makePurchase(2,"city2", "description2", 50000);
- // printing all transation of account
- accoundFound.printTransactions();
- System.out.println(accoundFound.getBalance());
- }
- }
CODE 2; Account.java
- import java.util.ArrayList;
- public class Account {
- private String name; // the name of the account holder
- private int ID; // the account ID/number
- private double balance; // balance of the account
- private Address address; // you need to define the Address class as described later
- public Account(String name, int iD, double balance, Address address) {
- super();
- this.name = name;
- ID = iD;
- this.balance = balance;
- this.address = address;
- }
- ArrayList
transactionList = new ArrayList (); - public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public int getID() {
- return ID;
- }
- public void setID(int iD) {
- ID = iD;
- }
- public double getBalance() {
- return balance;
- }
- public void setBalance(double balance) {
- this.balance = balance;
- }
- public Address getAddress() {
- return address;
- }
- public void setAddress(Address address) {
- this.address = address;
- }
- public ArrayList
transactions() { - return transactionList;
- }
- public boolean withdraw(double amount) {
- if (getBalance() >= amount && amount > 0) {
- this.balance -= amount;
- return true;
- }
- return false;
- }
- public boolean deposit(double amount) {
- if (amount > 0) {
- this.balance += amount;
- return true;
- }
- return false;
- }
- public void print() {
- System.out.println(
- "Account [name=" + name + ", ID=" + ID + ", balance=" + balance + ", " + address.printAddress() + "]");
- }
- public void printTransactions() {
- ArrayList
transactionList = transactions(); - for (Transaction transaction : transactionList) {
- transaction.print();
- }
- }
- public boolean makePurchase(int ID, String city, String description, double amount) {
- if (getBalance() > amount) {
- this.balance -= amount;
- Transaction transaction = new Transaction(ID, city, description, amount);
- transactionList.add(transaction);
- }
- return true;
- }
- }
CODE 3: Address.java
- public class Address {
- private int streetNum;
- private String street;
- private String suburb;
- private String city;
- public Address(int streetNum, String street, String suburb, String city) {
- super();
- this.streetNum = streetNum;
- this.street = street;
- this.suburb = suburb;
- this.city = city;
- }
- public int getStreetNum() {
- return streetNum;
- }
- public void setStreetNum(int streetNum) {
- this.streetNum = streetNum;
- }
- public String getStreet() {
- return street;
- }
- public void setStreet(String street) {
- this.street = street;
- }
- public String getSuburb() {
- return suburb;
- }
- public void setSuburb(String suburb) {
- this.suburb = suburb;
- }
- public String getCity() {
- return city;
- }
- public void setCity(String city) {
- this.city = city;
- }
- public String printAddress() {
- return "Address [streetNum=" + streetNum + ", street=" + street + ", suburb=" + suburb + ", city=" + city + "]";
- }
- }
CODE 4: Bank.java
- import java.util.ArrayList;
- public class Bank {
- private ArrayList
accountList =new ArrayList ();// list of all the accounts for this bank - private String adminUsername;
- private String adminPassword;
- public ArrayList
getAccountList() { - return accountList;
- }
- public void setAccountList(ArrayList
accountList) { - this.accountList = accountList;
- }
- public String getAdminUsername() {
- return adminUsername;
- }
- public void setAdminUsername(String adminUsername) {
- this.adminUsername = adminUsername;
- }
- public String getAdminPassword() {
- return adminPassword;
- }
- public void setAdminPassword(String adminPassword) {
- this.adminPassword = adminPassword;
- }
- public Bank(String adminUsername, String adminPassword) {
- super();
- this.adminUsername = adminUsername;
- this.adminPassword = adminPassword;
- }
- public boolean validateAdmin(String username, String password) {
- if (getAdminUsername().equals(username) && getAdminPassword().equals(password)) {
- return true;
- }
- return false;
- }
- public boolean addAccount(Account account) {
- if (accountList != null) {
- for (Account acc : accountList) {
- if (acc.getID() == account.getID()) {
- return false;
- }
- }
- }
- accountList.add(account);
- return true;
- }
- public Account findAccount(int accountID) {
- for (Account acc : accountList) {
- if (acc.getID() == accountID) {
- return acc;
- }
- }
- return null;
- }
- public double calcTotalBalance() {
- double totalBalance = 0;
- for (Account acc : accountList) {
- totalBalance += acc.getBalance();
- }
- return totalBalance;
- }
- public void printAllAccounts() {
- for (Account acc : accountList) {
- acc.print();
- }
- }
- }
CODE 5: Transaction.java
- public class Transaction {
- private int ID;
- private String city;
- private String description;
- private double amount;
- public Transaction(int iD, String city, String description, double amount) {
- super();
- ID = iD;
- this.city = city;
- this.description = description;
- this.amount = amount;
- }
- public int getID() {
- return ID;
- }
- public void setID(int iD) {
- ID = iD;
- }
- public String getCity() {
- return city;
- }
- public void setCity(String city) {
- this.city = city;
- }
- public String getDescription() {
- return description;
- }
- public void setDescription(String description) {
- this.description = description;
- }
- public double getAmount() {
- return amount;
- }
- public void setAmount(double amount) {
- this.amount = amount;
- }
- public void print() {
- System.out.println("Transaction [ID=" + ID + ", city=" + city + ", description=" + description + ", amount=" + amount + "]");
- }
- }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started