297,934 views
6 votes
6 votes
In the file BankAccount.java, build a class called BankAccount that manages checking and savings accounts. The class has three private member fields: a customer name (String), the customer's savings account balance (double), and the customer's checking account balance (double).

Implement the following Constructor and instance methods as listed below:
public BankAccount(String newName, double amt1, double amt2) - set the customer name to parameter newName, set the checking account balance to parameter amt1 and set the savings account balance to parameter amt2. (amt stands for amount)
public void setName(String newName) - set the customer name
public String getName() - return the customer name
public void setChecking(double amt) - set the checking account balance to parameter amt
public double getChecking() - return the checking account balance
public void setSavings(double amt) - set the savings account balance to parameter amt
public double getSavings() - return the savings account balance
public void depositChecking(double amt) - add parameter amt to the checking account balance (only if positive)
public void depositSavings(double amt) - add parameter amt to the savings account balance (only if positive)
public void withdrawChecking(double amt) - subtract parameter amt from the checking account balance (only if positive)
public void withdrawSavings(double amt) - subtract parameter amt from the savings account balance (only if positive)
public void transferToSavings(double amt) - subtract parameter amt from the checking account balance and add to the savings account balance (only if positive)

User Kotchwane
by
2.6k points

2 Answers

4 votes
4 votes

Answer:

public class BankAccount {

private String customerName;

private double savingsBalance;

private double checkingsBalance;

public BankAccount(String newName, double amt1, double amt2) {

this.customerName = newName;

this.checkingsBalance = amt1;

this.savingsBalance = amt2;

}

public void setName(String newName) {

this.customerName = customerName;

}

public String getName() {

return customerName;

}

public void setChecking(double checkingsBalance) {

this.checkingsBalance = checkingsBalance;

}

public double getChecking() {

return checkingsBalance;

}

public void setSavings(double savingsBalance) {

this.savingsBalance = savingsBalance;

}

public double getSavings() {

return savingsBalance;

}

public void depositChecking(double amt) {

if (amt > 0) {

this.checkingsBalance += amt;

}

}

public void depositSavings(double amt) {

if (amt > 0) {

this.savingsBalance += amt;

}

}

public void withdrawChecking(double amt) {

if (amt > 0) {

this.checkingsBalance -= amt;

}

}

public void withdrawSavings(double amt) {

if (amt > 0) {

this.savingsBalance -= amt;

}

}

public void transferToSavings(double amt) {

if (amt > 0 ) {

this.checkingsBalance -= amt;

this.savingsBalance += amt;

}

}

}

User Pepe Alvarez
by
2.6k points
24 votes
24 votes

Answer:

Step-by-step explanation:

The following code is written in Java and creates the BankAccount class with all of the requested methods, including the constructor, getter and setter methods, withdraw methods, and even the transferToSavings method. A preview can be seen in the attached image below.

class BankAccount {

private String customerName;

private double savingsBalance, checkingsBalance;

public BankAccount(String newName, double amt1, double amt2) {

this.customerName = newName;

this.checkingsBalance = amt1;

this.savingsBalance = amt2;

}

public String getCustomerName() {

return customerName;

}

public void setCustomerName(String customerName) {

this.customerName = customerName;

}

public double getSavingsBalance() {

return savingsBalance;

}

public void setSavingsBalance(double savingsBalance) {

this.savingsBalance = savingsBalance;

}

public double getCheckingsBalance() {

return checkingsBalance;

}

public void setCheckingsBalance(double checkingsBalance) {

this.checkingsBalance = checkingsBalance;

}

public void depositChecking(double amt) {

if (amt > 0) {

this.checkingsBalance += amt;

}

}

public void depositSavings(double amt) {

if (amt > 0) {

this.savingsBalance += amt;

}

}

public void withdrawChecking(double amt) {

if (amt > 0) {

this.checkingsBalance -= amt;

}

}

public void withdrawSavings(double amt) {

if (amt > 0) {

this.savingsBalance -= amt;

}

}

public void transferToSavings(double amt) {

if (amt > 0 ) {

this.checkingsBalance -= amt;

this.savingsBalance += amt;

}

}

}

In the file BankAccount.java, build a class called BankAccount that manages checking-example-1
User Piku
by
3.2k points