Java NetBeans Create a new project that allows you to create new accounts. Add a
ID: 3876021 • Letter: J
Question
Java
NetBeans
Create a new project that allows you to create new accounts. Add accounts to ArrayList, then apply deposit and withdraw from any account.
Add class Account: accountNumber, balance,bankName Pre-create a list of accounts in an array list.
Provide GUI to add a new account to list.
Provide GUI to display all the accounts in a table.
Display currency values with $ sign.
It needs to be able to deposit and withdraw amounts from the selected row.
Also needs to be able to get the selected row and read its column values.
Explanation / Answer
Account.java : --------------------->>>>>>>>>>>>>>>
public class Account{
private int accNo;
private double balance;
private String bName;
public Account(int ac,double b,String bn){
accNo = ac;
balance = b;
bName = bn;
}
public int getAcc(){
return accNo;
}
public double getBalance(){
return balance;
}
public String getBankName(){
return bName;
}
public void withdraw(double am){
if(am <= balance){
balance = balance - am;
}
else{
System.out.println("Withdraw amount is larger than balance ");
}
}
public void deposit(double am){
balance = balance + am;
}
}
Bank.java : ------------------>>>>>>>>>>>>>>
import java.util.*;
public class Bank{
private ArrayList<Account> accounts;
Scanner sc;
public Bank(){
accounts = new ArrayList<>();
}
public void addAccount(){
sc = new Scanner(System.in);
String bn;
int acNo;
double bal;
System.out.println("Enter the Account No. ");
acNo = sc.nextInt();
System.out.println("Enter the bank name : ");
bn = sc.next();
System.out.println("Enter the Initial Balance : ");
bal = sc.nextDouble();
Account temp = new Account(acNo,bal,bn);
accounts.add(temp);
}
public void dispalyAllAccount(){
System.out.println("-------------------------Table Of All Accounts-----------------------");
System.out.println("sl no acc No Balance Bank ");
for(int i = 0;i<accounts.size();i++){
System.out.println((i+1)+" "+accounts.get(i).getAcc()+" "+accounts.get(i).getBalance()+"$ "+accounts.get(i).getBankName()+" ");
}
}
public Account selectAccount(int n){
if(n <= accounts.size())
return accounts.get(n-1);
else{
System.out.println("wrong row selected ");
return null;
}
}
}
BankMain.java : ------------------->>>>>>>>>>>>>.
import java.util.Scanner;
public class BankMain{
public static void main(String[] args) {
Bank b1 = new Bank();
Scanner sc = new Scanner(System.in);
int n = 0;
while(n != 3){
System.out.println("1. Add Account ");
System.out.println("2. Display All Account ");
System.out.println("3. Exit");
n = sc.nextInt();
if(n == 1){
b1.addAccount();
System.out.println("Your Account is added ");
}
if(n == 2){
b1.dispalyAllAccount();
System.out.println("Enter sl no. to select a row ");
int ch = sc.nextInt();
Account temp = b1.selectAccount(ch);
if(temp != null){
ch = 0;
while(ch != 3){
System.out.println("1. Withdraw ");
System.out.println("2. Deposit ");
System.out.println("3. Exit");
ch = sc.nextInt();
if(ch == 1){
double am;
System.out.println("Enter Amount : ");
am = sc.nextDouble();
temp.withdraw(am);
}
if(ch == 2){
double am;
System.out.println("Enter Amount : ");
am = sc.nextDouble();
temp.deposit(am);
}
}
}
else{
System.out.println("Row Selection was Wrong");
}
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.