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...

  • NOTE: Use the Account class codes in the section below these questions. Modify the main method...

    NOTE: Use the Account class codes in the section below these questions. Modify the main method in the CheckingAccountDemo class: Take out all previous code. Declare an object array with 10 accounts. Create a for loop to ask user to input each account’s information (name, account number, and initial balance) from keyboard and then initialize for each account object. Create a while loop to allow one to work on depositing and withdrawing operations on any account till one want to...

  • 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...

  • Download BankAccount.java and BankAccountTester.java starting files and drag and drop them into your eclipse project. The...

    Download BankAccount.java and BankAccountTester.java starting files and drag and drop them into your eclipse project. The BankAccount class declaration in file BankAccount.java is the blueprint of a BankAccount object. Check out the design of a BankAccount class. 1. In BankAccount.java class, all of the method stubs ( methods with a header but empty bodies ) are present to help you get started. Your task is to complete the method bodies. All comments in red in the diagram above indicates what...

  • 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...

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

    Add appropriate descriptive comments to each line of code in the project explaining why the code is in the application. public class FutureValueFrame extends JFrame { private JTextField investmentField; private JTextField interestRateField; private JComboBox yearsComboBox; private JList futureValueList; private DefaultListModel futureValueModel; public FutureValueFrame() { initComponents(); } private void initComponents() { try { UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { System.out.println(e); } setTitle("Future Value Calculator"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationByPlatform(true); investmentField = new JTextField(); interestRateField = new JTextField();...

  • 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...

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