must be in java: Create a BankAccountPlusTester (this should be the main) Import
ID: 3719901 • Letter: M
Question
must be in java:
Create a BankAccountPlusTester (this should be the main)
Import Scanner
Create a Scanner object
Create a name and balance local variable.
Create 3 BankAccountPlus objects by:
Ask the user for a name and add it to the variable name.
Ask the user for an opening balance and add it to the variable balance.
Create the account with the information provided from the user.
Don’t forget you many need to add extra in.nextLine() like we did in a previous lab.
Create a fourth BankAccountPlus object that will have the name dummy and no balance.
Call payFees for each account.
Print the name and balance for each account. Be sure and use words to describe what each output means.
the code I have:
import java.util.Scanner;
public class BankAccountPlusTester
{
public static void main (String[] args)
{
Scanner in = new Scanner(System.in);
String name;
double balance;
// create 3 BankAccountPlus object s
BankAccountPlus account1,account2, account3;
for(int i=1;i<=3;i++)
{
System.out.println("For Account # "+i);
System.out.println("Please enter your name : ");
name=in.nextLine();
System.out.println("Please enter Initial Balance : ");
balance =in.nextDouble();
//clear the Buffer
in.nextLine();
if(i==1)
{
//Create account and call pay fees
account1=new BankAccountPlus (balance, name);
account1.payFees();
System.out.println(account1);
}
if(i==2)
{
//Create account
account2=new BankAccountPlus(balance, name);
account2.payFees();
System.out.println(account2);
}
if(i==3)
{
//Create account
account3=new BankAccountPlus(balance, name);
account3.payFees();
System.out.println(account3);
}
}
}
}
Explanation / Answer
public class BankAccountPlus { private String accountName; private double balance; public BankAccountPlus(double initialBalance, String name) { accountName=name; balance= initialBalance; } public void payFees(){ if(this.balance>0 && this.balance 2000 && this.balance20000){ } } public String getAccountName() { return accountName; } public void setAccountName(String accountName) { this.accountName = accountName; } public void deposit(double amount) { balance= balance + amount; } public void withdraw(double amount) { balance = balance - amount; } public double getBalance() { return balance; } @Override public String toString() { return "Name: "+accountName+", Balance: "+balance; } }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.