Bank class must have the listed 2 constructors Default constructor sets variable
ID: 3938092 • Letter: B
Question
Bank class must have the listed 2 constructors Default constructor sets variables to john doe 0.0 2nd constructor accepts 3 parameters and sets up account variables to those values 3 getters and 3 setters add method- accepts one parameter (double) and adds that amount to balance of calling object withdraw Method-Accepts one PARAMETER (double) subtracts that amount from the balance only if the account balance is great enough -otherwise, print a "not enough funds method" message print method -displays account info in tabular form First name last name balance John Doe $0.00Explanation / Answer
Here is the code for you:
class Bank
{
String firstName;
String lastName;
double balance;
public Bank()
{
firstName = "John";
lastName = "Doe";
balance = 0.0;
}
public Bank(String fName, String lName, double bal)
{
firstName = fName;
lastName = lName;
balance = bal;
}
public void setFirstName(String fName)
{
firstName = fName;
}
public void setLastName(String lName)
{
lastName = lName;
}
public void setBalance(double bal)
{
balance = bal;
}
public String getFirstName()
{
return firstName;
}
public String getLastName()
{
return lastName;
}
public double getBalance()
{
return balance;
}
public void addBalance(double bal)
{
balance += bal;
}
public void withdraw(double bal)
{
if(balance >= bal)
balance -= bal;
else
System.out.println("Not enough funds.");
}
public void print()
{
System.out.println("First name Last name Balance");
System.out.printf("%s %s %.2f ", firstName, lastName, balance);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.