1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
STatiana [176]
3 years ago
9

Write a Java class called BankAccount (Parts of the code is given below), which has two private fields: name (String) and balanc

e (double), and three methods: deposit(double amount), withdraw(double amount) and toString(). Write the necessary constructors, accessor methods and mutator methods. The deposit() method adds the amount to the account causing the current balance to increase, withdraw() method subtracts the amount causing the current balance to decrease and toString() method should return the name and the current balance separated by a comma. For example, if you print out the object with name Jake and balance 40.0 then it should print:

Computers and Technology
1 answer:
NemiM [27]3 years ago
3 0

Answer:

Here is the Bank Account class:

public class Bank Account {   //class definition

   private String name;  //private String type field to hold name

   private double balance;    // private double type field to hold balance

    public Bank Account(String name, double balance) {  // parameter constructor that takes

//this keyword is used to refer to the data members name and balance and to avoid confusion between name, balance private member fields and constructor arguments name, balance

 this.name = name;  

 this.balance = balance;  }    

   public void deposit(double amount) {   //method to deposit amount

               balance = balance + amount;     }    // adds the amount to the account causing the current balance to increase

   public void withdraw(double amount) {  //method to withdraw amount

 balance = balance - amount;   }   //subtracts the amount causing the current balance to decrease

    public String toString() {  // to display the name and current balance

              return name + " , $" + balance; }  } //returns the name and the current balance separated by a comma and dollar

Explanation:

The explanation is provided in the attached document due to some errors in uploading the answer.

You might be interested in
Write a program that calculates the cost of a phone call. The user enters a positive integer that
san4es73 [151]
Add the following constants in the class definition, before the main method:

    private final static float START_COST = 1.5f;
    private final static float HIGH_TARIFF = 0.5f;
    private final static float LOW_TARIFF = 0.25f;
    private final static int FIXED_MINS = 2;
    private final static int HIGH_TARIFF_MINS = 10;

Then add this to the main method you already had:

        float price = START_COST;
        if (x > FIXED_MINS) {
            if (x <= HIGH_TARIFF_MINS) {
                price += HIGH_TARIFF*(x-FIXED_MINS);
            }
            else {
                price += HIGH_TARIFF*(HIGH_TARIFF_MINS-FIXED_MINS) 
                    + LOW_TARIFF*(x-HIGH_TARIFF_MINS);
            }
        }   
        System.out.printf("A %d minute call costs %.2f", x, price);      

5 0
2 years ago
The function of network switch is to _____.
enyata [817]

Answer:Its C.

Explanation:

3 0
3 years ago
Why the computer is known as versatile and diligent device ? explain.<br>​
Scrat [10]

Answer:

Computer is called versatile and diligent device because it is used in almost all the fields for various purposes and it can perform the task repeatedly without loosing its speed and accuracy for long time.

5 0
2 years ago
What type of object can offer the most effective way to display data and calculations in a presentation?
poizon [28]

This is definitely an opinion, but an excel you can do A and D and just about the same as B also

<u>So i'd say C </u>

8 0
2 years ago
What are the layers in the internet protocol stack? what are the principle responsibilities of each of these layers?
Andrew [12]
1: Application
2: Presentation
3:Session
4: Transport
5:Network 
6: Data link 
7: Physical

Application is a Interface Layer and responsible Layer
<span />
3 0
3 years ago
Other questions:
  • In a paragraph of no less than 125 words, explain what netiquette is and how it improves efficiency and productivity in the work
    14·1 answer
  • What are the core scripting and coding technolies used to build ai platforms?
    14·1 answer
  • What are the problems with security when working on a Web Page?
    13·2 answers
  • Explain how Deep Packet Inspection works (DPI). How is this technology beneficial to Perimeter Security? Lastly, describe a scen
    6·1 answer
  • To close the ____ view, click File on the Ribbon or click the preview of the document in the Info gallery to return to the docum
    9·1 answer
  • can you give me a tip to fix my SIM card becuaus when i put it on my phone it has no signal , can anyone fix this , thank you.​
    9·2 answers
  • When would you use the AutoFit to Contents option?
    15·1 answer
  • A program that doesn’t work properly needs to be debugged. true or false
    8·1 answer
  • In confirmatory visualization Group of answer choices Users expect to see a certain pattern in the data Users confirm the qualit
    9·1 answer
  • Brianna is taking a backpacking trip in the wilderness and wants to back up the photos from her camera. Which type of storage de
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!