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)

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;

}

public void withdrawal (double amount) {

balance -=amount;

}

public String ToString() {

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

}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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;

}

}

Add a comment
Know the answer?
Add Answer to:
Hello everybody. Below I have attached a code and we are supposed to add comments explaining...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • /* * To change this license header, choose License Headers in Project Properties. * To change...

    /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package checkingaccounttest; // Chapter 9 Part II Solution public class CheckingAccountTest { public static void main(String[] args) {    CheckingAccount c1 = new CheckingAccount(879101,3000); c1.deposit(350); c1.deposit(220); c1.withdraw(100); c1.deposit(1100); c1.deposit(700); c1.withdraw(350); c1.withdraw(220); c1.withdraw(100); c1.deposit(1100); c1.deposit(700); c1.deposit(1000); System.out.println(c1); System.out.println("After calling computeMonthlyFee()"); c1.computeMonthlyFee(); System.out.println(c1); } } class BankAccount { private int...

  • Add appropriate descriptive comments to each line of the code, explaining why the code is in...

    Add appropriate descriptive comments to each line of the code, explaining why the code is in the application. import java.text.NumberFormat; public class LineItem implements Cloneable { private Product product; private int quantity; private double total; public LineItem() { this.product = new Product(); this.quantity = 0; this.total = 0; } public LineItem(Product product, int quantity) { this.product = product; this.quantity = quantity; } public void setProduct(Product product) { this.product = product; } public Product getProduct() { return product; } public void...

  • TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static...

    TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static constant FEE that represents the cost of clearing onecheck. Set it equal to 15 cents. Write a constructor that takes a name and an initial amount as parameters. Itshould call the constructor for the superclass. It should initializeaccountNumber to be the current value in accountNumber concatenatedwith -10 (All checking accounts at this bank are identified by the extension -10). There can be only one...

  • I need to update the code listed below to meet the criteria listed on the bottom....

    I need to update the code listed below to meet the criteria listed on the bottom. I worked on it a little bit but I could still use some help/corrections! import java.util.Scanner; public class BankAccount { private int accountNo; private double balance; private String lastName; private String firstName; public BankAccount(String lname, String fname, int acctNo) { lastName = lname; firstName = fname; accountNo = acctNo; balance = 0.0; } public void deposit(int acctNo, double amount) { // This method is...

  • Use the Java codes below (Checking Account and Checking Account Demo), and work on these problems....

    Use the Java codes below (Checking Account and Checking Account Demo), and work on these problems. You have to do both of your java codes based on the two provided Java codes. Create one method for depositing and one for withdrawing. The deposit method should have one parameter to indicate the amount to be deposited. You must make sure the amount to be deposited is positive. The withdraw method should have one parameter to indicate the amount to be withdrawn...

  • The code is attached below has the Account class that was designed to model a bank account.

    IN JAVAThe code is attached below has the Account class that was designed to model a bank account. An account has the properties account number, balance, annual interest rate, and date created, and methods to deposit and withdraw funds. I need creat program using the 2 java programs.Create two subclasses for checking and savings accounts. A checking account has an overdraft limit, but a savings account cannot be overdrawn.I need to write a test program that creates objects of Account,...

  • What is wrong with this Code? Fix the code errors to run correctly without error. There...

    What is wrong with this Code? Fix the code errors to run correctly without error. There are two parts for one code (one question) the two parts branch off, one part has 2 sheets of code, the other has 3 sheets of code, all are small code segments for one question. Pt.1 - 2 sheets of code: public class Computer { private String make; private String type; private String modelNumber; private double cpuSpeed_GHz; private int ramSize_GB; private int hardDriveSize_GB; private...

  • Write a unit test to test the following class. Using Java : //Test only the debit...

    Write a unit test to test the following class. Using Java : //Test only the debit method in the BankAccount. : import java.util.*; public class BankAccount { private String customerName; private double balance; private boolean frozen = false; private BankAccount() { } public BankAccount(String Name, double balance) { customerName = Name; this.balance = balance; } public String getCustomerName() { return customerName; } public double getBalance() { return balance; } public void setDebit(double amount) throws Exception { if (frozen) { throw...

  • I need help modifying this code please ASAP using C++ Here is what I missed on this code below Here are the instruction...

    I need help modifying this code please ASAP using C++ Here is what I missed on this code below Here are the instructions Here is the code Produce correct70 pts O pts Full Marks No Marks results and statisfy requirements view longer Comments 1. Your display amount is not readable 2. I withdraw more than my balance, but I didn't see any error message description Documentations10 pts 0 pts Full Marks No Marks : comment i code and block comment...

  • C++ Please create the class named BankAccount with the following properties below: // The BankAccount class...

    C++ Please create the class named BankAccount with the following properties below: // The BankAccount class sets up a clients account (name & ID), keeps track of a user's available balance. // It also keeps track of how many transactions (deposits and/or withdrawals) are made. public class BankAccount { Private String name private String id; private double balance; private int numTransactions; // Please define method definitions for Accessors and Mutator functions below Private member variables string getName(); // No set...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT