Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class bank { //instance variables, name, balance, homeAddress, accountNum private String name; private double balance; private String homeAddress; private int accountNum; //constructor public bank(String

image text in transcribed

public class bank {

//instance variables, name, balance, homeAddress, accountNum

private String name;

private double balance;

private String homeAddress;

private int accountNum;

//constructor

public bank(String name, double balance, String homeAddress, int accountNum){

this.name = name;

this.balance = balance;

this.homeAddress = homeAddress;

this.accountNum = accountNum;

}

//constructor2

public bank(String name, String homeAddress, int accountNum){

this.name = name;

this.homeAddress = homeAddress;

this.accountNum = accountNum;

}

//setters

public void sethomeAddress(String newhomeAddress){

this.homeAddress = newhomeAddress;

}

public void setbalance(double newBalance){

this.balance = newBalance;

}

public void setName(String newName){

this.name = newName;

}

public void setaccountNum(int newaccountNum){

this.accountNum = newaccountNum;

}

//getters

public void getBalance(){

StdOut.println("current balance is: " + balance);

}

public void getName(){

StdOut.println("name: " + name);

}

public void gethomeAddress(){

StdOut.println("Address: " + homeAddress);

}

public void getaccountNum(){

StdOut.println("your account number is: " + accountNum);

}

//methods

public boolean withdraw(double amount){

if(balance - amount

StdOut.println("cannot withdraw more than your balance");

return false;

}

else{

balance = balance - amount;

return true;

}

}

public boolean deposit(double amount){

if(amount

StdOut.println("cannot deposit no money");

return false;

}

else{

balance = balance + amount;

return true;

}

}

public boolean transfer(bank from, bank to, double amount){

if(from.withdraw(amount)){

to.deposit(amount);

return true;

}

return false;

}

}

help me explain everything on my code, i kinda confuse. and also why do we need two constructor ?

Problem You are in charge of designing software for a bank, to be used for managing customers' accounts. 1. You first must create a class that represents an individual bank account. . What data should your class store? o What operations should you class offer? Think about what people do with bank accounts. 2. Now, implement the class in Java with the behavior you outlined above. o Define fields for each of the pieces of data you decided to store. o Define and implement methods for each of the operations you decided to have your class offer. 3. Think of sequences of operations that would be good to try to test your methods. Justify your choices. o Can you think of a sequence of operations that may cause problems with a bank account? In essense, how can we break a bank account? 4. In another file, create a simple test drive class that creates an instance of your bank account class, executes the sequences you came up with in part 3, and display the results

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions