Write a menu driven application to perform the banking operations using JAVA.
Your application must contain the following functionalities. Use constructors, getter
and setter functions wherever required.
In the menu give options for Account Creation, Balance Enquiry,
Deposit and
Withdrawal
Do not allow to withdraw money if the balance is < = 500
Initial balance must be a minimum of 500.
package bankaccount;
import java.util.Scanner;
public class BankAccount {
private String customerName;
private float balance;
private int accountNumber;
public BankAccount(String n,float b, int acc){
customerName = n;
balance = b;
accountNumber = acc;
}
public void setCustomerName(String n){
customerName = n;
}
public void setAccountNumber(int acc){
accountNumber = acc;
}
public void setBalance( float bal){
balance = bal;
}
public String getCustomerName(){
return customerName;
}
public double getBalance(){
return balance;
}
public int getAccountNumber(){
return accountNumber;
}
public double deposit(float amount){
return amount + balance;
}
public void withdraw(float amount){
if (amount <= 500){
System.out.println("Amount is less than 500");
}
else{
balance = balance - amount;
System.out.printf("You have successfully withdrew:\t %f"
+ "\n Your account balance is:\t %f", amount, balance );
}
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter customer name");
String name = input.next();
System.out.println("Enter initial customer initial balance");
// double balance = input.nextDouble();
float balance = input.nextFloat();
while(balance<500){
System.out.println("Initial balance must be exceed 500.");
}
System.out.println("Enter account number for the customer");
int accountNumber = input.nextInt();
BankAccount acc = new BankAccount(name ,balance, accountNumber);
System.out.println("1. Enter 1 for account creation");
System.out.println("2. Enter 2 for Balance enquiry");
System.out.println("3. Enter 3 for money Deposit");
System.out.println("4. Enter 4 for money Withdrawal");
int userChoice = input.nextInt();
switch(userChoice){
case 1:
System.out.println("Account Creation Selected\n");
System.out.printf("The customer name is:\t %s\n"
+ "The customer initial balance is:\t %f\n"
+ "The customer account number is:\t %d\n", acc.getCustomerName(), acc.getBalance(),acc.getAccountNumber() );
break;
case 2:
System.out.println("Balance enquiry selected");
System.out.println("Your balance is:\t"+acc.getBalance());
break;
case 3:
System.out.println("Money deposit selected");
System.out.println("Enter an amount to depost");
float amount = input.nextFloat();
System.out.printf("You have successfully deposited:\t %f"
+ "\n Your account balance is:\t %f", amount, acc.deposit(amount) );
break;
case 4:
System.out.println("Money withdrawal selected");
System.out.println("Enter an amount to depost");
float amount1 = input.nextFloat();
acc.withdraw(amount1);
break;
}
}
}
Comments
Leave a comment