For this week\'s assignment, we will be creating a banking program. You will aga
ID: 3705000 • Letter: F
Question
For this week's assignment, we will be creating a banking program. You will again be working on a team with me to build this program I have written the BankAccount class that you can use to create a BankAccount object. The file named BankAccount.java is attached. Ask the user for their name, and then create an instance of the BankAccount object for the customer using their name and an account number of your choice. (You can just make one up.) Then ask the user whether they want to: 1) Make a Deposit 2) Make a Withdrawal 3) Print Account Information 4) Quit If the user chooses to make a deposit, ask them for the amount, and make the deposit to the bank account If the user chooses to make a withdrawal, ask them for the amount, and then make the withdrawal from the bank account If the user chooses to print account information, print the name on the account, the account number, and the account balance. If the user enters an invalid choice, prompt them to choose again. Repeat the options until the user chooses to quit.Explanation / Answer
Implemented code as per the requirement. Please comment if you want any modifcation.
Code:
====
import java.util.Scanner;
public class BankAccount {
private int acc_num;
private String accHolderName;
private Scanner sc;
private static int number = 100000;
private double balance = 0.0;
static BankAccount bc;
public static void main(String[] args) {
bc = new BankAccount();
bc.sc = new Scanner(System.in);
System.out.print("Enter account holder name: ");
bc.accHolderName = bc.sc.nextLine();
bc.acc_num = bc.generateAccNum();
operations();
}
private static void operations() {
String choice = "";
double amt = 0.0;
while(true){
System.out.println("1.Make a depposit 2.Make a withdrael 3.Print account information 4.Quit");
System.out.print("Enter your choice: ");
choice = bc.sc.nextLine();
if(choice.equals("1")){
System.out.print("Enter amount to be deposited: ");
bc.balance = bc.balance + Double.parseDouble(bc.sc.nextLine());
System.out.println("Amount deposited..");
}
else if(choice.equalsIgnoreCase("2")){
System.out.print("Enter amount to be withdrawn: ");
amt = Double.parseDouble(bc.sc.nextLine());
if((int)(bc.balance - amt)<0){
System.out.println("Insufficient funds.");
}
else{
bc.balance = bc.balance - amt;
System.out.println("Amount withdrawn");
}
}
else if(choice.equals("3")){
System.out.println("Account holder name: "+bc.accHolderName);
System.out.println("Account number: "+bc.acc_num);
System.out.println("Balance: "+bc.balance);
}
else if(choice.equals("4")){
System.out.println("Bye Bye..");
break;
}
else{
System.out.println("Invalid choice.. Please try again");
}
}
}
private int generateAccNum(){
return number+1;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.