Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

No starter code this time. Create a new Java Project in eclipse. Create a new cl

ID: 3621566 • Letter: N

Question

No starter code this time. Create a new Java Project in eclipse. Create a new class and name it BankAccount. Do not include a main method.

Your BankAccount class must have these instance fields:
private double balance;
private int pin;
private int accountNo;
private String[] owners;


Your BankAccount class must have this class variable:
private static String branch = "BofA Corvallis Office";


Your BankAccount class must have 2 constructors. Do not print anything in these methods.
The first one must accept these parameters in this order:
an int used to initialize accountNo
an int used to initialze pin
a double used to initialize balance
a String used to put into owners at index 0
(You will have to create owners first -- length 2)
a String used to put into owners at index 1

The second one must accept these parameters in this order:
an int used to initialize accountNo
an int used to initialize pin
a double used to initialize balance
a String used to put into owners at index 0
(You will have to create owners first -- length 1)


Your BankAccount class must have getter methods for the following variables. Do not print anything in these methods.
balance
accountNo
owners
branch


Your BankAccount class must have setter methods for the following variables. Do not print anything in these methods.
pin
branch


Your BankAccount class must a non-static method named deposit that accepts a double and returns a double. The parameter double is the amount that the user is depositing to this bank account. If the parameter is negative, throw an IllegalArgumentException. The return double is the user's balance after this transaction. Obviously, this method changes the balance instance field. Do not print anything in this method.


Your BankAccount class must a non-static method named withdraw that accepts a double and returns a double. The parameter double is the amount that the user is withdrawing from this bank account. If the parameter is negative, throw an IllegalArgumentException. The return double is the user's balance after this transaction. Obviously, this method changes the balance instance field. Do not print anything in this method.


Your BankAccount class must a non-static method named transferFrom that accepts in this order a BankAccount object and a double and returns void. The parameter BankAccount is the account you should withdraw money from to add to this bank account. The parameter double is the amount that is transferring. If this parameter is negative, throw an IllegalArgumentException. Do not print anything in this method.


Your BankAccount class must a non-static method named matchesPin that accepts an int and returns a boolean. The parameter int is a pin number that we want to know if it matches (equals) the instance field pin. If they are the same, this method returns true. Otherwise it returns false. Do not print anything in this method.


Extra Credit: Your BankAccount class can contain a non-static method named addOwner that accepts a String and returns void. The parameter String is the name of an owner that we wish to add to the array of Strings named owner. The problem is that owner has no empty elements. You will have to create a new String[] that has length one bigger than owner, put all the Strings that are in owner inside your new String[], put the parameter String inside your new String[], and finally set owner equal to your new String[]. The goal is to have owner contain all the Strings it used to plus the parameter. It must have length 1 larger than it used to. Do not print anything in this method.


TEST YOUR CODE:
Create another class that has a main method. Instantiate BankAccount objects using your constructors. Call all your methods. Print the returns to see if everything worked.

Create another class that has a main method and add this code to test your transferFrom method.


BankAccount fred = new BankAccount( 100, 23, 120.50, "Fred Smith" ); // starts account with $120.50
BankAccount manOfSteel = new BankAccount( 115, 16, 99, "Superman", "Lois Lane" );  // starts account with $99

fred.transferFrom(manOfSteel , 19.50);
System.out.println( fred.getBalance() ); // should now have 120.5 + 19.50
System.out.println( manOfSteel .getBalance() );  // should now have 99 - 19.50

Explanation / Answer

This is what I have so far: import java.util.Arrays; public class BankAccount { private double balance; private int pin; private int accountNo; private String owners; // class variable: private static String branch = "BofA Corvallis Office"; public BankAccount(int account, int p, double bal, String string) { accountNo = account; pin = p; balance = bal; owners = string; } public BankAccount(int account, int p, int bal, String string, String string2) { accountNo = account; pin = p; balance = bal; owners = string; } public double getBalance() { return balance; } public int getAccountNo() { return accountNo; } public String getOwners() { return owners; } public String getBranch() { return branch; } public void setPin(int p){ pin = p; } public void setBranch(String Branch){ BankAccount.branch = Branch; } public double deposit(double x){ if(x
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote