Answered step by step
Verified Expert Solution
Link Copied!

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

  1. public class TestMain {
  2. public static void main(String[] args) {
  3. Bank bank = new Bank("username", "password");
  4. // adding account to list of accounts in Bank object
  5. Address address1 = new Address(1, "street", "subhurb", "city");
  6. Account account1 = new Account("name1", 1, 20000, address1);
  7. bank.addAccount(account1);
  8. Address address2 = new Address(2, "street2", "subhurb2", "city2");
  9. Account account2 = new Account("name2", 2, 50000, address2);
  10. bank.addAccount(account2);
  11. // total balance of all account
  12. System.out.println(bank.calcTotalBalance());
  13. // printing all account information
  14. bank.printAllAccounts();
  15. // get account by id
  16. Account accoundFound = bank.findAccount(1);
  17. // deposit money to account
  18. accoundFound.deposit(3000);
  19. System.out.println(accoundFound.getBalance());
  20. //making purchase from account 10000
  21. accoundFound.makePurchase(1,"city", "description", 10000);
  22. // printing all transation of account
  23. accoundFound.printTransactions();
  24. accoundFound.makePurchase(2,"city2", "description2", 50000);
  25. // printing all transation of account
  26. accoundFound.printTransactions();
  27. System.out.println(accoundFound.getBalance());
  28. }
  29. }

CODE 2; Account.java

  1. import java.util.ArrayList;
  2. public class Account {
  3. private String name; // the name of the account holder
  4. private int ID; // the account ID/number
  5. private double balance; // balance of the account
  6. private Address address; // you need to define the Address class as described later
  7. public Account(String name, int iD, double balance, Address address) {
  8. super();
  9. this.name = name;
  10. ID = iD;
  11. this.balance = balance;
  12. this.address = address;
  13. }
  14. ArrayList transactionList = new ArrayList();
  15. public String getName() {
  16. return name;
  17. }
  18. public void setName(String name) {
  19. this.name = name;
  20. }
  21. public int getID() {
  22. return ID;
  23. }
  24. public void setID(int iD) {
  25. ID = iD;
  26. }
  27. public double getBalance() {
  28. return balance;
  29. }
  30. public void setBalance(double balance) {
  31. this.balance = balance;
  32. }
  33. public Address getAddress() {
  34. return address;
  35. }
  36. public void setAddress(Address address) {
  37. this.address = address;
  38. }
  39. public ArrayList transactions() {
  40. return transactionList;
  41. }
  42. public boolean withdraw(double amount) {
  43. if (getBalance() >= amount && amount > 0) {
  44. this.balance -= amount;
  45. return true;
  46. }
  47. return false;
  48. }
  49. public boolean deposit(double amount) {
  50. if (amount > 0) {
  51. this.balance += amount;
  52. return true;
  53. }
  54. return false;
  55. }
  56. public void print() {
  57. System.out.println(
  58. "Account [name=" + name + ", ID=" + ID + ", balance=" + balance + ", " + address.printAddress() + "]");
  59. }
  60. public void printTransactions() {
  61. ArrayList transactionList = transactions();
  62. for (Transaction transaction : transactionList) {
  63. transaction.print();
  64. }
  65. }
  66. public boolean makePurchase(int ID, String city, String description, double amount) {
  67. if (getBalance() > amount) {
  68. this.balance -= amount;
  69. Transaction transaction = new Transaction(ID, city, description, amount);
  70. transactionList.add(transaction);
  71. }
  72. return true;
  73. }
  74. }

CODE 3: Address.java

  1. public class Address {
  2. private int streetNum;
  3. private String street;
  4. private String suburb;
  5. private String city;
  6. public Address(int streetNum, String street, String suburb, String city) {
  7. super();
  8. this.streetNum = streetNum;
  9. this.street = street;
  10. this.suburb = suburb;
  11. this.city = city;
  12. }
  13. public int getStreetNum() {
  14. return streetNum;
  15. }
  16. public void setStreetNum(int streetNum) {
  17. this.streetNum = streetNum;
  18. }
  19. public String getStreet() {
  20. return street;
  21. }
  22. public void setStreet(String street) {
  23. this.street = street;
  24. }
  25. public String getSuburb() {
  26. return suburb;
  27. }
  28. public void setSuburb(String suburb) {
  29. this.suburb = suburb;
  30. }
  31. public String getCity() {
  32. return city;
  33. }
  34. public void setCity(String city) {
  35. this.city = city;
  36. }
  37. public String printAddress() {
  38. return "Address [streetNum=" + streetNum + ", street=" + street + ", suburb=" + suburb + ", city=" + city + "]";
  39. }
  40. }

CODE 4: Bank.java

  1. import java.util.ArrayList;
  2. public class Bank {
  3. private ArrayList accountList =new ArrayList();// list of all the accounts for this bank
  4. private String adminUsername;
  5. private String adminPassword;
  6. public ArrayList getAccountList() {
  7. return accountList;
  8. }
  9. public void setAccountList(ArrayList accountList) {
  10. this.accountList = accountList;
  11. }
  12. public String getAdminUsername() {
  13. return adminUsername;
  14. }
  15. public void setAdminUsername(String adminUsername) {
  16. this.adminUsername = adminUsername;
  17. }
  18. public String getAdminPassword() {
  19. return adminPassword;
  20. }
  21. public void setAdminPassword(String adminPassword) {
  22. this.adminPassword = adminPassword;
  23. }
  24. public Bank(String adminUsername, String adminPassword) {
  25. super();
  26. this.adminUsername = adminUsername;
  27. this.adminPassword = adminPassword;
  28. }
  29. public boolean validateAdmin(String username, String password) {
  30. if (getAdminUsername().equals(username) && getAdminPassword().equals(password)) {
  31. return true;
  32. }
  33. return false;
  34. }
  35. public boolean addAccount(Account account) {
  36. if (accountList != null) {
  37. for (Account acc : accountList) {
  38. if (acc.getID() == account.getID()) {
  39. return false;
  40. }
  41. }
  42. }
  43. accountList.add(account);
  44. return true;
  45. }
  46. public Account findAccount(int accountID) {
  47. for (Account acc : accountList) {
  48. if (acc.getID() == accountID) {
  49. return acc;
  50. }
  51. }
  52. return null;
  53. }
  54. public double calcTotalBalance() {
  55. double totalBalance = 0;
  56. for (Account acc : accountList) {
  57. totalBalance += acc.getBalance();
  58. }
  59. return totalBalance;
  60. }
  61. public void printAllAccounts() {
  62. for (Account acc : accountList) {
  63. acc.print();
  64. }
  65. }
  66. }

CODE 5: Transaction.java

  1. public class Transaction {
  2. private int ID;
  3. private String city;
  4. private String description;
  5. private double amount;
  6. public Transaction(int iD, String city, String description, double amount) {
  7. super();
  8. ID = iD;
  9. this.city = city;
  10. this.description = description;
  11. this.amount = amount;
  12. }
  13. public int getID() {
  14. return ID;
  15. }
  16. public void setID(int iD) {
  17. ID = iD;
  18. }
  19. public String getCity() {
  20. return city;
  21. }
  22. public void setCity(String city) {
  23. this.city = city;
  24. }
  25. public String getDescription() {
  26. return description;
  27. }
  28. public void setDescription(String description) {
  29. this.description = description;
  30. }
  31. public double getAmount() {
  32. return amount;
  33. }
  34. public void setAmount(double amount) {
  35. this.amount = amount;
  36. }
  37. public void print() {
  38. System.out.println("Transaction [ID=" + ID + ", city=" + city + ", description=" + description + ", amount=" + amount + "]");
  39. }
  40. }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions