Knowee
Questions
Features
Study Tools

Write a java program to create a bank account with Name of the account holder, type of account(savings or  current), Account number and Balance amount in the account. Also, create 5 customers for the class Bank_account using array of objects. Access the customers to perform credit, debit and display of balance.Input 1:Enter the customers:ReenaSavings1231000RobinCurrent4562000PraveenSavings7893000SherinCurrent2342500DeenaSavings5672000Enter choice:1. Credit2. Debit

Question

Write a java program to create a bank account with Name of the account holder, type of account(savings or  current), Account number and Balance amount in the account. Also, create 5 customers for the class Bank_account using array of objects. Access the customers to perform credit, debit and display of balance.Input 1:Enter the customers:ReenaSavings1231000RobinCurrent4562000PraveenSavings7893000SherinCurrent2342500DeenaSavings5672000Enter choice:1. Credit2. Debit

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution 1

Here is a simple Java program that creates a BankAccount class and uses an array of objects to create 5 customers. It also includes methods for credit, debit, and displaying the balance.

class BankAccount {
    String holderName;
    String accountType;
    int accountNumber;
    double balance;

    BankAccount(String holderName, String accountType, int accountNumber, double balance) {
        this.holderName = holderName;
        this.accountType = accountType;
        this.accountNumber = accountNumber;
        this.balance = balance;
    }

    void credit(double amount) {
        balance += amount;
    }

    void debit(double amount) {
        if (balance >= amount) {
            balance -= amount;
        } else {
            System.out.println("Insufficient balance");
        }
    }

    void display() {
        System.out.println("Account Holder: " + holderName);
        System.out.println("Account Type: " + accountType);
        System.out.println("Account Number: " + accountNumber);
        System.out.println("Balance: " + balance);
    }
}

public class Main {
    public static void main(String[] args) {
        BankAccount[] customers = new BankAccount[5];
        customers[0] = new BankAccount("Reena", "Savings", 123, 1000);
        customers[1] = new BankAccount("Robin", "Current", 456, 2000);
        customers[2] = new BankAccount("Praveen", "Savings", 789, 3000);
        customers[3] = new BankAccount("Sherin", "Current", 234, 2500);
        customers[4] = new BankAccount("Deena", "Savings", 567, 2000);

        // Perform operations
        customers[0].credit(500);
        customers[1].debit(1000);
        customers[2].display();
    }
}

This program creates a BankAccount class with the necessary fields and methods. In the main method, it creates an array of BankAccount objects, each representing a customer. It then performs some operations on these customers, such as crediting an amount to the first customer, debiting an amount from the second customer, and displaying the details of the third customer.

Please note that this is a simple program and does not include user input for operations. If you want to include user input, you will need to use a Scanner object to read the user's input.

This problem has been solved

Solution 2

Here is a simple Java program that creates a BankAccount class and uses an array of objects to create 5 customers. It also includes methods for credit, debit, and displaying the balance.

class BankAccount {
    String holderName;
    String accountType;
    int accountNumber;
    double balance;

    BankAccount(String holderName, String accountType, int accountNumber, double balance) {
        this.holderName = holderName;
        this.accountType = accountType;
        this.accountNumber = accountNumber;
        this.balance = balance;
    }

    void credit(double amount) {
        balance += amount;
    }

    void debit(double amount) {
        if (amount <= balance) {
            balance -= amount;
        } else {
            System.out.println("Insufficient balance");
        }
    }

    void display() {
        System.out.println("Account Holder: " + holderName);
        System.out.println("Account Type: " + accountType);
        System.out.println("Account Number: " + accountNumber);
        System.out.println("Balance: " + balance);
    }
}

public class Main {
    public static void main(String[] args) {
        BankAccount[] customers = new BankAccount[5];
        customers[0] = new BankAccount("Reena", "Savings", 123, 1000);
        customers[1] = new BankAccount("Robin", "Current", 456, 2000);
        customers[2] = new BankAccount("Praveen", "Savings", 789, 3000);
        customers[3] = new BankAccount("Sherin", "Current", 234, 2500);
        customers[4] = new BankAccount("Deena", "Savings", 567, 2000);

        // Perform operations here based on user input
        // For example, to credit 500 to Reena's account:
        customers[0].credit(500);
        // And to debit 200 from Robin's account:
        customers[1].debit(200);

        // Display all customers
        for (BankAccount customer : customers) {
            customer.display();
        }
    }
}

This program creates a BankAccount class with the necessary fields and methods. In the main method, it creates an array of BankAccount objects, each representing a customer. It then performs credit and debit operations based on the example user input. Finally, it displays the details of all customers.

Please note that in a real-world application, you would want to get the user input dynamically (e.g., using a Scanner for console input), and you would also want to add more error checking and handling (e.g., for invalid input).

This problem has been solved

Solution 3

Here is a simple Java program that creates a BankAccount class and uses an array of objects to create 5 customers. It also includes methods for credit, debit, and displaying the balance.

class BankAccount {
    String holderName;
    String accountType;
    int accountNumber;
    double balance;

    BankAccount(String holderName, String accountType, int accountNumber, double balance) {
        this.holderName = holderName;
        this.accountType = accountType;
        this.accountNumber = accountNumber;
        this.balance = balance;
    }

    void credit(double amount) {
        balance += amount;
    }

    void debit(double amount) {
        if (amount <= balance) {
            balance -= amount;
        } else {
            System.out.println("Insufficient balance");
        }
    }

    void display() {
        System.out.println("Name: " + holderName);
        System.out.println("Account Type: " + accountType);
        System.out.println("Account Number: " + accountNumber);
        System.out.println("Balance: " + balance);
    }
}

public class Main {
    public static void main(String[] args) {
        BankAccount[] customers = new BankAccount[5];
        customers[0] = new BankAccount("Reena", "Savings", 123, 1000);
        customers[1] = new BankAccount("Robin", "Current", 456, 2000);
        customers[2] = new BankAccount("Praveen", "Savings", 789, 3000);
        customers[3] = new BankAccount("Sherin", "Current", 234, 2500);
        customers[4] = new BankAccount("Deena", "Savings", 567, 2000);

        // Perform operations here based on user input
        // For example, to credit 500 to Reena's account:
        customers[0].credit(500);
        // And to debit 200 from Robin's account:
        customers[1].debit(200);
        // And to display the balance of Praveen's account:
        customers[2].display();
    }
}

This program does not include user input functionality. You would need to add that if you want the user to be able to perform operations interactively.

This problem has been solved

Similar Questions

Write a Java program to manage billing information for customers. The program should allow the user to input details for multiple customers and bills. For each customer, the program should prompt the user to enter a customer ID and name. For each bill, the program should prompt the user to enter a bill number, amount, date, and the corresponding customer ID. Once the user has input all the necessary information, the program should allow the user to search for bills by customer ID. Upon entering a customer ID, the program should display all bill amounts, dates, and numbers associated with that customer ID. Frame the program using classes for Customer and Bill, and implement methods to retrieve customer and bill details. Sample Input 3 // Number of Customers 1  // Customer IDJai // Customer Name 2Sakthi 3John 5 // Number of Bills 11  // Bill Number45663 // Bill Amount02/12/2023 // Bill Date2 // Customer ID 4489609/12/20232 77896509/04/20231 99675404/11/20221 33876511/11/202332 Sample Output 1145663.002/12/202344896.009/12/2023

Create  a class for bank customer : Account number, phone number , name, Gender ( M/F). Create user name and password for online banking using following constraints.User name will  be three upper case letters of bank name followed by last three digit of account number then last  two character of name( upper case).For bank name  : if account number starts with ‘2’ then Indian bank, if it starts with ‘3’ then state bankPass word id middle four digit of phone number preceded by three characters “INB” for “Indian  bank and “ STB” for state bank , succeeded by “MA” for male or “ “FE” for female.Account number should be of five digit only ,else print “ Invalid Account Number”.Create three objects and display user name , password and how many accounts in  each bank.Example :Input252349034493459MadhavMOutputUser name :  IND234AVPass word :  INB4493MAINDIAN BANK:1STATE BANK:0

Write a program to create a bank customer information using array of structures, nested structures and functions.First structure should hold the following information: Customer personal details: Name, Gender, Account Number, DOB; Second structure should hold the following information: Customer account details: Type of account, opening balance, closing balance

// BankAccount.java// Parent class BankAccountpublic class BankAccount { private String accountNumber; private double balance; public BankAccount(String accountNumber, double balance) { this.accountNumber = accountNumber; this.balance = balance; } public void deposit(double amount) { balance += amount; } public void withdraw(double amount) { if (balance >= amount) { balance -= amount; } else { System.out.println("Insufficient balance"); } } public double getBalance() { return balance; }}Copy// SavingsAccount.java// Child class SavingsAccountpublic class SavingsAccount extends BankAccount { public SavingsAccount(String accountNumber, double balance) { super(accountNumber, balance); } @Override public void withdraw(double amount) { if (getBalance() - amount < 100) { System.out.println("Minimum balance of $100 required!"); } else { super.withdraw(amount); } }}Copy // Main.java// Main classpublic class Main { public static void main(String[] args) { System.out.println("Create a Bank Account object (A/c No. BA1234) with initial balance of $500:"); //Create a BankAccount object (A/c No. "BA1234") with initial balance of $500 BankAccount BA1234 = new BankAccount("BA1234", 500); // Deposit $1000 into account BA1234 System.out.println("Deposit $1000 into account BA1234:"); BA1234.deposit(1000); System.out.println("New balance after depositing $1000: $" + BA1234.getBalance()); // Withdraw $600 from account BA1234 System.out.println("Withdraw $600 from account BA1234:"); BA1234.withdraw(600); System.out.println("New balance after withdrawing $600: $" + BA1234.getBalance()); // Create a SavingsAccount object (A/c No. "SA1234") with initial balance of $450 System.out.println("\nCreate a SavingsAccount object (A/c No. SA1234) with initial balance of $450:"); SavingsAccount SA1234 = new SavingsAccount("SA1234",450); // Withdraw $300 from SA1234 SA1234.withdraw(300); System.out.println("Balance after trying to withdraw $300: $" + SA1234.getBalance()); // Create a SavingsAccount object (A/c No. "SA1000") with initial balance of $300 System.out.println("\nCreate a SavingsAccount object (A/c No. SA1000) with initial balance of $300:"); SavingsAccount SA1000 = new SavingsAccount("SA1000",300); // Withdraw $250 from SA1000 (balance falls below $100) System.out.println("Try to withdraw $250 from SA1000!"); SA1000.withdraw(250); System.out.println("Balance after trying to withdraw $250: $" + SA1000.getBalance()); }}

Assume that a bank maintains two kinds of accounts for customers, one called as savings account and the other as current account. The saving account provides compound interest (9%) and withdrawal facilities but not cheque book facility. The current account provides cheque book facility but no interest. Current account holders should also maintains a minimum balance of 500 and if the balance falls below this level, a service charge (Rs. 50) is imposed. Create a class Account as abstract that stores customer name, account number and opening balance (Rs. 500). From this derive the classes Current and Saving to make them more specific to their requirements. Include necessary member functions in order to achieve the following tasks:Get the account details using constructor.Display the account details using friend function.Deposit an amount (Rs. 10000) for a customer and update the balanceCompute and deposit interest. Now display the balance using inline function.Withdraw amount (Rs. 10200) for a customer after checking the balance and update the balance.Check for the minimum balance (for current account holders), impose penalty, if necessary, and update the balance.Count the number of transactions carried out using static member variable and display the count value by static member function    OUTPUTAmount deposited successfullyCurrent Balance:10500Interest deposited successfullyCurrent Balance:10695Insufficient balance. Penalty of 50 imposedCustomer Name:JohnAccount Number:123456Current Balance:10695Customer Name:JaneAccount Number:654321Current Balance:450Total number of transactions:3

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.