For each method add a precise description of its purpose, input and output. Expl
ID: 3731342 • Letter: F
Question
For each method add a precise description of its purpose, input and output.
Explain the purpose of each member variable.
/* ADD COMMENTS TO THIS CLASS, DO NOT CHANGE ANY CODE! */
import java.util.*;
public class BankAccount {
private int accountNumber;
private String ownerName;
private double balance;
private String type; // Personal, Business, Charitable
public BankAccount() {
accountNumber = 0;
ownerName = "";
balance = 0.0;
type = "Personal";
}
public BankAccount(int number, String name, double initialDeposit, String type) {
accountNumber = number;
ownerName = name;
balance = initialDeposit;
this.type = type; // Why does 'this' need to be used here??
}
public int getAccountNumber() {
return accountNumber;
}
public void setAccountNumber(int number) {
accountNumber = number;
}
public String getOwnerName() {
return ownerName;
}
public void setOwnerName(String name) {
ownerName = name;
}
public double getBalance() {
return balance;
}
public void setBalance(double newAmount) {
balance = newAmount;
}
public String getType() {
return type;
}
public void deposit(double amount) {
balance += amount;
}
public void withdrawl(double amount) {
balance -= amount;
}
public String toString() {
return type + ": " + accountNumber + " " + ownerName + " " + balance;
}
}
For each method add a precise description of its purpose, input and output.
Explain the purpose of each member variable.
/* ADD COMMENTS TO THIS CLASS, DO NOT CHANGE ANY CODE! */
import java.util.*;
public class BankAccount {
private int accountNumber;
private String ownerName;
private double balance;
private String type; // Personal, Business, Charitable
public BankAccount() {
accountNumber = 0;
ownerName = "";
balance = 0.0;
type = "Personal";
}
public BankAccount(int number, String name, double initialDeposit, String type) {
accountNumber = number;
ownerName = name;
balance = initialDeposit;
this.type = type; // Why does 'this' need to be used here??
}
public int getAccountNumber() {
return accountNumber;
}
public void setAccountNumber(int number) {
accountNumber = number;
}
public String getOwnerName() {
return ownerName;
}
public void setOwnerName(String name) {
ownerName = name;
}
public double getBalance() {
return balance;
}
public void setBalance(double newAmount) {
balance = newAmount;
}
public String getType() {
return type;
}
public void deposit(double amount) {
balance += amount;
}
public void withdrawl(double amount) {
balance -= amount;
}
public String toString() {
return type + ": " + accountNumber + " " + ownerName + " " + balance;
}
}
Explanation / Answer
BankAccount.java
/* ADD COMMENTS TO THIS CLASS, DO NOT CHANGE ANY CODE! */
import java.util.*;
public class BankAccount {
private int accountNumber;//instance variable to hold account number
private String ownerName;//instance variable to hold owner name
private double balance; //instance variable to hold balance
private String type; // Personal, Business, Charitable. instance variable to hold account type
public BankAccount() { //default constructor
accountNumber = 0;//Initialising with value 0
ownerName = "";//Initialising with value ""
balance = 0.0;//Initialising with value 0.0
type = "Personal";//Initialising with value "Personal"
}
public BankAccount(int number, String name, double initialDeposit, String type) {//Parameterised constructor
accountNumber = number;
ownerName = name;
balance = initialDeposit;
this.type = type; // Why does 'this' need to be used here?? this.type indicates instance variable. type indicates contructor parameter
}
public int getAccountNumber() {//get method to return account number
return accountNumber;
}
public void setAccountNumber(int number) {//set method to set account number
accountNumber = number;
}
public String getOwnerName() {//get method to return owner name
return ownerName;
}
public void setOwnerName(String name) {//set method to set owner name
ownerName = name;
}
public double getBalance() {//get method to return balance
return balance;
}
public void setBalance(double newAmount) {//Set method to set amount
balance = newAmount;
}
public String getType() {//get method to return account type
return type;
}
public void deposit(double amount) {//method to add account amount
balance += amount;
}
public void withdrawl(double amount) {//method to remove amount
balance -= amount;
}
public String toString() {//method to return the class properties
return type + ": " + accountNumber + " " + ownerName + " " + balance;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.