Question

Banking System (Java Programming) 1 bank (Bank) has 5 accounts holder (Account) also designing te...

Banking System (Java Programming)

1 bank (Bank) has 5 accounts holder (Account)

also designing textbased menu (switch case):

Main Menu:

1. Admin Login

2. User Login

3. Exit

Admin Menu:

1. Add an Account

2. Remove an Account

3. Print total balance

4. Print total balance per city

5. Go back to main menu

User Login

1. Withdraw //also redo last withdraw

2. Deposit //also redo last deposit

3. print account

4. Go back to main menu

Designing class Account for:

- (field: name, ID, balance, city, username, password), constructors, mutators, assessors

1. withdraw

2. redo last withdraw

3. deposit

4. redo last deposit

5. login validation

6. when bank is adding a new account, account ID will automatically be generated incrementally

Designing class Bank for:

- (field: private username, private password, private ArrayList accounts //list all accounts ), constructors, mutators, assessors

1. login validation

2. addAccount // when creating an account, the username and password will be written in the code

3. removeAccount (by using account ID)

4. calculate all total balance

5. generateReport (all total balance per city) (have a list of the city in the field)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Account.java

package com.test;

public class Account {

   private String name;
   private int ID = 0;
   private Double balance;
   private String city;
   private String username;
   private String password;
   private Double lastDeposit = 0.0;
   private Double lastWithdraw = 0.0;
   public Account(String name, Double balance, String city, String username, String password) {
       super();
       this.name = name;
       this.ID++; ////6. when bank is adding a new account, account ID will automatically be generated incrementally
       this.balance = balance;
       this.city = city;
       this.username = username;
       this.password = password;
   }
   public String getName() {
       return name;
   }
   public int getID() {
       return ID;
   }
   public Double getBalance() {
       return balance;
   }
   public String getCity() {
       return city;
   }
   public String getUsername() {
       return username;
   }
   public String getPassword() {
       return password;
   }
   public void setName(String name) {
       this.name = name;
   }

   public void setBalance(Double balance) {
       this.balance = balance;
   }
   public void setCity(String city) {
       this.city = city;
   }
   public void setUsername(String username) {
       this.username = username;
   }
   public void setPassword(String password) {
       this.password = password;
   }
  
   //1. withdraw
   public void withdraw(double amount){
       if(amount < this.balance)
           this.balance -= amount;
       lastWithdraw = amount;
   }
  
   //2. redo last withdraw
   public void reDoWithdraw(){
       this.balance += lastWithdraw;
   }

   //3. deposit
   public void deposit(double amount){
       this.balance += amount;
       lastDeposit =amount;
   }
   //4. redo last deposit
   public void reDoDeposit(){
       this.balance -= lastDeposit;
   }
   //5. login validation
   public Boolean loginValidation(String username, String pass){
       if(this.username == username && this.password == pass)
           return true;
       return false;
   }
   @Override
   public String toString() {
       return "Account [name=" + name + ", ID=" + ID + ", balance=" + balance + ", city=" + city + ", username="
               + username + ", password=" + password + ", lastDeposit=" + lastDeposit + ", lastWithdraw="
               + lastWithdraw + "]";
   }
  
}

//Bank.java

package com.test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class Bank {

   private String username;
   private String password;
   private ArrayList<Account> accounts;
   public Bank(String username, String password, ArrayList<Account> accounts) {
       super();
       this.username = username;
       this.password = password;
       this.accounts = accounts;
   }
   public String getUsername() {
       return username;
   }
   public String getPassword() {
       return password;
   }
   public ArrayList<Account> getAccounts() {
       return accounts;
   }
   public void setUsername(String username) {
       this.username = username;
   }
   public void setPassword(String password) {
       this.password = password;
   }
   public void setAccounts(ArrayList<Account> accounts) {
       this.accounts = accounts;
   }
  
   //1. login validation
   public Boolean loginValidation(String bankUser, String pass){
       if(this.username == bankUser && this.password == pass)
           return true;
       return false;
   }
   //2. addAccount // when creating an account, the username and password will be written in the code
   public void addAccount(Account acc) {
       this.accounts.add(acc);
   }

   //3. removeAccount (by using account ID)
   public Boolean removeAccount(int ID) {
       for(Account acc:this.accounts) {
           if(acc.getID() == ID) {
               return this.accounts.remove(acc);
           }
       }
       return false;
   }

   //4. calculate all total balance
   public Double totalBalance() {
       Double balanceSum = 0.0;
       for(Account acc:this.accounts) {
           balanceSum += acc.getBalance();
       }
       return balanceSum;
   }

   //5. generateReport (all total balance per city) (have a list of the city in the field)
   public void generateReport(ArrayList<String> cities) {
       Map<String,Double> report = new HashMap<>();
      
       for(Account acc:this.accounts) {
           if(cities.contains(acc.getCity())) {
               if(report.containsKey(acc.getCity())) {
                   double bal = report.get(acc.getCity());
                   report.replace(acc.getCity(), bal + acc.getBalance());
               }else {
                   report.put(acc.getCity(), acc.getBalance());
               }
           }
       }
   }
}

//Main.java

package com.test;

import java.util.ArrayList;
import java.util.Scanner;

public class Main {
  
   public static void main(String[] args) {
      
       ArrayList<Account> acc = new ArrayList<>();
      
       Bank bankName = new Bank("USBI", "123456", acc);
      
       while(true)
       {
           System.out.println("Main Menu:\n1. Admin Login\n" +
                   "2. User Login\n" +
                   "3. Exit\n");
           Integer choice1, choice2;
           String name,city,username,password;
           Double bal;
          
           Scanner sc = new Scanner(System.in);
           choice1 = Integer.parseInt(sc.nextLine());
          
           if(choice1.equals(1)) {
               System.out.println("Admin Menu:\r\n" +
                       "1. Add an Account\r\n" +
                       "2. Remove an Account\r\n" +
                       "3. Print total balance\r\n" +
                       "4. Print total balance per city\r\n" +
                       "5. Go back to main menu\n");
               choice2 = Integer.parseInt(sc.nextLine());
               switch (choice2) {
               case 1:
                   System.out.print("\nEnter account name:");
                   name = sc.nextLine();
                   System.out.print("\nEnter account initial Ballance:");
                   bal = Double.parseDouble(sc.nextLine());
                   System.out.print("\nEnter City name:");
                   city = sc.nextLine();
                   System.out.print("\nEnter account username:");
                   username = sc.nextLine();
                   System.out.print("\nEnter account password:");
                   password = sc.nextLine();
                  
                   Account account = new Account(name, bal, city, username, password);
                   bankName.addAccount(account);
                   break;
               case 2:
                   System.out.println("\nEnter account id to remove: ");
                   int id = sc.nextInt();
                   acc.remove(id);
                   break;
               case 3:
                   System.out.println("\nTotal Account Balance: " + bankName.totalBalance());
                   break;
               case 4:
                   System.out.println("\nTotal Account Balance as per cities: " );
                   ArrayList<String> cities = new ArrayList<>();
                   cities.add("Pune");
                   bankName.generateReport(cities);
                   break;
               case 5:
                   break;

               default:
                   break;
               }
              
              
           }else if(choice1 == 2) {
               System.out.println("User Login\r\n" +
                       "1. Withdraw //also redo last withdraw\r\n" +
                       "2. Deposit //also redo last deposit\r\n" +
                       "3. print account\r\n" +
                       "4. Go back to main menu\n");
               choice2 = sc.nextInt();
               int id;
               double amount;
               switch (choice2) {
               case 1:
                   System.out.println("Enter account ID:");
                   id = sc.nextInt();
                   System.out.println("Enter amount to withdraw:");
                   amount = sc.nextDouble();
                  
                   for(Account ac : bankName.getAccounts()) {
                       if(ac.getID() == id) {
                           ac.withdraw(amount);
                           break;
                       }
                   }
                   break;
               case 2:
                   System.out.println("Enter account ID:");
                   id = sc.nextInt();
                   System.out.println("Enter amount to Deposit:");
                   amount = sc.nextDouble();
                  
                   for(Account ac : bankName.getAccounts()) {
                       if(ac.getID() == id) {
                           ac.deposit(amount);
                           break;
                       }
                   }
                   break;
               case 3:
                   System.out.println("Enter account ID:");
                   id = sc.nextInt();
                   for(Account ac : bankName.getAccounts()) {
                       if(ac.getID() == id) {
                           System.out.println(ac);
                           break;
                       }
                   }
                   break;
               case 4:

                   break;
               default:
                   break;
               }
           }else if(choice1 == 3) {
               break;
           }else {
               System.out.println("Please enter valid input.");
           }
       }
   }
}

//output:

Main Menu:
1. Admin Login
2. User Login
3. Exit

1
Admin Menu:
1. Add an Account
2. Remove an Account
3. Print total balance
4. Print total balance per city
5. Go back to main menu

1

Enter account name:sitaram

Enter account initial Ballance:100

Enter City name:pune

Enter account username:surya

Enter account password:12345
Main Menu:
1. Admin Login
2. User Login
3. Exit

2
User Login
1. Withdraw //also redo last withdraw
2. Deposit //also redo last deposit
3. print account
4. Go back to main menu

3
Enter account ID:
1
Account [name=sitaram, ID=1, balance=100.0, city=pune, username=surya, password=12345, lastDeposit=0.0, lastWithdraw=0.0]
Main Menu:
1. Admin Login
2. User Login
3. Exit

3

Add a comment
Know the answer?
Add Answer to:
Banking System (Java Programming) 1 bank (Bank) has 5 accounts holder (Account) also designing te...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • this is for java programming Please use comments Use the Account class created in homework 8_2...

    this is for java programming Please use comments Use the Account class created in homework 8_2 to simulate an ATM machine. Create ten checking accounts in an array with id 0, 1, …, 9, initial balance of $100, and annualInterestRate of 0. The system prompts the user to enter an id between 0 and 9, or 999 to exit the program. If the id is invalid (not an integer between 0 and 9), ask the user to enter a valid...

  • In this, you will create a bank account management system according to the following specifications: BankAccount...

    In this, you will create a bank account management system according to the following specifications: BankAccount Abstract Class contains the following constructors and functions: BankAccount(name, balance): a constructor that creates a new account with a name and starting balance. getBalance(): a function that returns the balance of a specific account. deposit(amount): abstract function to be implemented in both Checking and SavingAccount classes. withdraw(amount): abstract function to be implemented in both Checking and SavingAccount classes. messageTo Client (message): used to print...

  • The code is attached below has the Account class that was designed to model a bank account.

    IN JAVAThe code is attached below has the Account class that was designed to model a bank account. An account has the properties account number, balance, annual interest rate, and date created, and methods to deposit and withdraw funds. I need creat program using the 2 java programs.Create two subclasses for checking and savings accounts. A checking account has an overdraft limit, but a savings account cannot be overdrawn.I need to write a test program that creates objects of Account,...

  • NETBEANS JAVA BANK PROGRAM (TAKE SCREENSHOTS FROM NETBEANS INCLUDING OUTPUT PLEASE) Display the accounts for the...

    NETBEANS JAVA BANK PROGRAM (TAKE SCREENSHOTS FROM NETBEANS INCLUDING OUTPUT PLEASE) Display the accounts for the current displayed customer PLEASEEEEEEEEEE package bankexample; import java.util.UUID; public class Customer { private UUID id; private String email; private String password; private String firstName; private String lastName;    public Customer(String firstName, String lastName, String email, String password) { this.id = UUID.randomUUID(); this.firstName = firstName; this.lastName = lastName; this.email = email; this.password = password; } public String getFirstName() { return firstName; } public void setFirstName(String...

  • You are to write a banking application in c# that keeps track of bank accounts. It will consist of three classes, Account, Bank and BankTest. The Account class is used to represent a savings account i...

    You are to write a banking application in c# that keeps track of bank accounts. It will consist of three classes, Account, Bank and BankTest. The Account class is used to represent a savings account in a bank. The class must have the following instance variables: a String called accountID                       a String called accountName a two-dimensional integer array called deposits (each row represents deposits made in a week). At this point it should not be given any initial value. Each...

  • C++ Design a class bankAccount that defines a bank account as an ADT and implements the...

    C++ Design a class bankAccount that defines a bank account as an ADT and implements the basic properties of a bank account. The program will be an interactive, menu-driven program. a. Each object of the class bankAccount will hold the following information about an account: account holder’s name account number balance interest rate The data members MUST be private. Create an array of the bankAccount class that can hold up to 20 class objects. b. Include the member functions to...

  • Design a class named BankAccount that contains: 1. A private int data field named accountId for...

    Design a class named BankAccount that contains: 1. A private int data field named accountId for the account. 2. A private double data field named accountBalance for the account (default 0). 3. A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. 4. A private Date data field named dateCreated that stores the date when the account was created. 5. A private int data field named numberOfDeposits...

  • must be written in c# using windows application Scenario: Samediff bank has a 25-year old banking...

    must be written in c# using windows application Scenario: Samediff bank has a 25-year old banking account system. It was created using procedural programming. Samediff bank needs to improve the security and maintainability of the system using an object-oriented programming (OOP) approach. Their bank manager has decided to hire you to develop, implement, and test a new OOP application using efficient data structures and programming techniques.Samediff banks manager is excited to consider updating their account system. An expert has advised...

  • Lance 1. Write a C++ program that manages a user's bank account. The program must but...

    Lance 1. Write a C++ program that manages a user's bank account. The program must but not limited to: (a) Display a menu for the user once the program runs. The menu display should be done through a user defined function with no parameters. The display should look like the below snapshot. (3 marks) ***********Welcome to the Bank Account Manager program helps you make cash withdrawals and deposits (b) Ask the user for his/her full name. (1.5 marks) (c) Ask...

  • Design a bank account class named Account that has the following private member variables:

    Need help please!.. C++ programDesign a bank account class named Account that has the following private member variables: accountNumber of type int ownerName of type string balance of type double transactionHistory of type pointer to Transaction structure (structure is defined below) numberTransactions of type int totalNetDeposits of type static double.The totalNetDeposits is the cumulative sum of all deposits (at account creation and at deposits) minus the cumulative sum of all withdrawals. numberAccounts of type static intand the following public member...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT