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

Hello everybody. Below I have attached a code and we are supposed to add comment

ID: 3734362 • Letter: H

Question

Hello everybody. Below I have attached a code and we are supposed to add comments explaining what each line of code does. For each method add a precise description of its purpose, input and output. Explain the purpose of each member variable. . Some help would be greaty appreciated. (I have finished the code below with typing as my screen wasnt big enough to fit the whole code image)

}

public void withdrawal (double amount) {

balance -=amount;

}

public String ToString() {

return type + ": " + accountNumber + " " + ownerName + " " + balance;

}

}

ADD COMMENTS TO THIS CLASS, DO NOT CHANGE ANY CODE! import java.util.*; public class BankAccount private int accountNumber; priva private double balance private String type; // Personal, Business, Charitable ownerName: public BankAccount) accoun tNumber- ownerName -""; balance0.0 type "Personal"; public BankAccount (int number, String name, double initialDeposit, string type) ( accoun tNumber ownerName - name/ balance -initialDeposit; this.type - type // Why does 'this' need to be used here?? = number; public int getAccountNumber) ( return accountNumber public void setAccountNumber (int number) ( number ; accoun tNumber public String getownerName) return ownerName public void setownerName (String name) ownerName - name/ public double getBalance () return balance; public void setBalance (double newAmount) ( balancenewAmount public String getType ) return type; public void deposit (double amount) balance += amount;

Explanation / Answer

public class BankAccount {

//private data members, means accessible to only this class

private int accountNumber; // Holds account number of user

private String ownerName; // Holds name of user

private double balance; // Holds total balance in account

private String type; // Personal, business, Charitable

// Default constructor

// This constructor initializes data members with some default values

public BankAccount() {

accountNumber=0;

ownerName="";

balance=0.0;

type="Personal";

}

// Parameterized constructor

// This constructor initializes data members with values passed in arguments

public BankAccount(int number, String name, double initialDeposit, String type) {

accountNumber = number; // Sets account number with number

ownerName = name; // Sets owner name with name

balance = initialDeposit;// Set balance with initial deposit

// Here, this is used because the variable name of data member and parameter is same

// "this" here refers to the current object for which the constructor is called

this.type = type; // Sets type with passed value type

}

// Getter method which returns account number

public int getAccountNumber() {

return accountNumber;

}

// Setter method which can be used to set a new account number

public void setAccountNumber(int number) {

accountNumber = number;

}

// Getter method which returns owner name

public String getOwnerName() {

return ownerName;

}

// Setter method which can be used to set a new owner name

public void setOwnerName(String name) {

ownerName = name;

}

// Getter method which returns balance in account

public double getBalance() {

return balance;

}

// Setter method which can be used to set new balance

public void setBalance(double newAmount) {

balance = newAmount;

}

// Getter method which returns tyoe of account

public String getType() {

return type;

}

// This method add passed amount to balance and updates balance

public void deposit(double amount) {

balance+=amount;

}

// This method subtract passed amount from balance and updates balance

public void withdrawal (double amount) {

balance -=amount;

}

// This method returns a string with following details -

// type : accountNumber ownerName balance

// Example - Personal: 12345 Max 25000

public String ToString() {

return type + ": " + accountNumber + " " + ownerName + " " + balance;

}

}

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