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 Output :ReenaSavings1232000
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 Output :ReenaSavings1232000
Solution
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 name;
String accountType;
int accountNumber;
double balance;
BankAccount(String name, String accountType, int accountNumber, double balance) {
this.name = name;
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(name + "\t" + accountType + "\t" + accountNumber + "\t" + 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 credit, debit and display operations here
// For example, to credit 1000 to Reena's account:
customers[0].credit(1000);
customers[0].display();
}
}
This program creates a BankAccount class with fields for the name, account type, account number, and balance. The BankAccount constructor initializes these fields. The credit method adds an amount to the balance, the debit method subtracts an amount from the balance if there are sufficient funds, and the display method prints the account details.
In the main method, an array of BankAccount objects is created and initialized with 5 customers. The credit method is then called on the first customer (Reena) to add 1000 to her balance, and her account details are printed.
Please note that this is a simple program and does not include user input or error checking. In a real-world application, you would want to include these features and also protect the account details with appropriate access modifiers and methods.
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
// 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()); }}
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
Program that creates a class Account that stores a variable balance. The class has methods to startaccount, to deposit money, to withdraw money and tell the current balance amoun
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.