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
NARA [144]
4 years ago
14

The Account class contains a definition for a simple bank account class with methods to withdraw, deposit, get the balance and a

ccount number, and return a String representation. Modify the file as follows:1. Overload the constructor as follows:a. public Account (double initBal, String owner, long number) - initializes the balance, owner, and account number as specified.b. public Account (double initBal, String owner) - initializes the balance and owner as specified; randomly generates the account number.c. public Account (String owner) - initializes the owner as specified; sets the initial balance to 0 and randomly generates the account number.2. Overload the withdraw method with one that also takes a fee and deducts that fee from the account.
Computers and Technology
1 answer:
melamori03 [73]4 years ago
8 0

Answer:

I've updated the Account class as per the instructions. The instructions mention "the constructor for this class creates a random account number" although I didn't find where that was. As a result, I created a simple method to generates the account number (located at the bottom of the class). Be sure you understand the changes (highlighted in yellow) and feel free to ask follow-up questions:

Explanation:

//*******************************************************

// Account.java

//

// A bank account class with methods to deposit to, withdraw from,

// change the name on, and get a String representation

// of the account.

//*******************************************************

import java.util.Random;   // Used for Random # generator

public class Account

{

      private double balance;

  private String name;

     private long acctNum;

      //----------------------------------------------

 //Constructor -- initializes balance, owner, and account number

  //----------------------------------------------

 public Account(double initBal, String owner, long number)

{

        balance = initBal;

               name = owner;

            acctNum = number;

}

// !!!!!! New Constructor !!!!!!

public Account(double initBal, String owner)

     {

        balance = initBal;

               name = owner;

            acctNum = generateAccountNumber();

       }

  // !!!!!! New Constructor !!!!!!

 public Account(String owner)

     {

        balance = 0;

             name = owner;

            acctNum = generateAccountNumber();

       }

   //----------------------------------------------

 // Checks to see if balance is sufficient for withdrawal.

// If so, decrements balance by amount; if not, prints message.

  //----------------------------------------------

 public void withdraw(double amount)

      {

        if (balance >= amount)

                balance -= amount;

               else

                     System.out.println("Insufficient funds");

}

 // !!!!!! New withdraw() method !!!!!!

   public void withdraw(double amount, double fee)

  {

        double amountWithFee = amount + fee;

               if (balance >= amountWithFee)

                 balance -= amountWithFee;

        else

                     System.out.println("Insufficient funds");

}

   //----------------------------------------------

 // Adds deposit amount to balance.

       //----------------------------------------------

 public void deposit(double amount)

       {

        balance += amount;

       }

  //----------------------------------------------

 // Returns balance.

      //----------------------------------------------

 public double getBalance()

       {

        return balance;

  }

    //----------------------------------------------

 // Returns a string containing the name, account number, and balance.

    //----------------------------------------------

 public String toString()

 {

        return "Name:" + name +

          "\nAccount Number: " + acctNum +

         "\nBalance: " + balance;

 }

 // !!!! NEW PRIVATE HELPER METHOD TO GENERATE ACCOUNT NUMBERS !!!!!

//-------------------------------------------------------

// Returns a random account number between 10000 - 99999

 //--------------------------------------------------------

       private long generateAccountNumber()

     {

        Random r = new Random();        // Seed the random number genertor with the system time

         return 10000 + r.nextInt(89999);        // .nextInt(89999) will return a value between 0 and 89999)

      }

}

You might be interested in
Which is an example of an incremental approach to solving a problem?
zvonat [6]

Explanation:

One of the things I’ve been writing and talking about a lot lately is the fact that solving problems collaboratively is an incremental process. In fact, in my book, Lost at School, I made mention of the fact that the model could just as easily have been called Incremental Problem Solving or Progressive Problem Solving. I thought the collaborative aspect of the model was the most important to emphasize, but that doesn’t mean that the incremental component isn’t almost as crucial. Often people who are new to the model enter the process of resolving a problem as if it’s a one-shot deal. If you have experience in using Plan B, you already know that most problems require more than one visit to Plan B to resolve. In other words, longstanding, complicated problems aren’t likely to be resolved the first time you try to discuss them. There’s a lot of information to be processed before a given problem can be solved. You need to gather information so as to achieve the clearest possible understanding of the kid’s concern or perspective on the problem (for the unfamiliar, that’s called the Empathy step). Then, you need to be clear about and articulate your own concern (that’s the Define the Problem step). Then, you’ll want to brainstorm with the kid so as to consider the array of potential solutions that could be applied to the problem and consider whether each solution truly addresses the concerns of both parties (that’s the Invitation). There’s a good chance you won’t even make it through all three steps of Plan B in the first attempt on a given unsolved problem (nor should you necessarily even try). If Plan B were a “technique,” then disappointment over not making it through all three steps in one conversation would be understandable. But Plan B is not a technique, it’s a process. As I’ve often emphasized, if you only make it through the Empathy step in the first attempt at Plan B on a given problem but you emerge with a clear sense of a kid’s concern or perspective on a problem that’s been causing significant angst or conflict, that’s quite an accomplishment. You’ll get back to the remaining steps at your earliest opportunity. There’s also an excellent chance the first solution you and the kid agree on won’t solve the problem durably. As you may know, this is usually because the original solution wasn’t as realistic and mutually satisfactory as the two parties first thought. But it could also be because the concerns weren’t as clear or simple as it first seemed. If a solution doesn’t stand the test of time, your goal is to figure out why, which means gathering additional information about the concerns of the two parties and why the solution may not be working so well. Plan B should always conclude with both parties agreeing to return to the problem if the solution being agreed upon doesn’t solve the problem durably. So if your enthusiasm for Plan B waned because your first solution didn’t stand the test of time, take heart: that’s not unusual. Many people enter Plan B with great hope, eager to see their new approach to helping a challenging kid pay quick dividends. In fact, Plan B may well pay quick dividends…not necessarily because the problem is yet durably solved, but because of the relationship- and communication-enhancing that occurs. And while the occasional problem – often simple ones – can be resolved with one visit to Plan B, now you know that several repetitions of Plan B may be necessary on each unsolved problem. Thanks for reading.

8 0
3 years ago
A,B, or C. pls help me out!!!!!!!!!!
schepotkina [342]

<span>Bitmap images are A. best suited for three-dimensional designs and graphics with color blends found in web pages. </span>

<span>
Taken for granted that Maria’s work is original work, Bitmap images are the best to use on a website. Bitmap is a format for photographs and graphics with a wide range of colours and effects (for example a button with a shadow), which creates realistic images.</span>

 

6 0
3 years ago
Which of the following reflects the order of operations
lorasvet [3.4K]

Answer: PEMDAS

Parenthesis, Exponents, Multiplication, Division, Addition, Subtraction

Explanation:

3 0
3 years ago
Read 2 more answers
Which of these social news sites promotes itself as supporting free speech and will remove videos with self-harm or that feature
LUCKY_DIMON [66]

Fark is the social news sites promotes itself as supporting free speech and will remove videos with self-harm or that feature racist or violent content.

<h3>Describe Fark.</h3>

A daily batch of news stories and other material from many websites are posted to the community website Fark, which was developed by Drew Curtis. The website receives a lot of story submissions every day, and about 100 of them are publicly shown on the site, spread out throughout the home page, and have many topical tabs (arranged as business, sports, geek, entertainment, and geek). Although Curtis claims there is no political bias in the selection of the tales, he does try to publish both far-left and far-right material.

As popularity and engagement increased, more features like forums and link submissions were added. The main goal of the makeover was to make the site more user-friendly and intuitive. Fark is the a news social networking site that promote itself as supporting free speech and will remove videos with self-harm or that feature racist or violent content.

To learn more about social networking sites, visit:

brainly.com/question/13307340

#SPJ1

5 0
2 years ago
ASAP 20 Points please hurry
inna [77]

Answer:

All you got to do is type System.out printIn("Study English) etc...

Explanation:

Look at the answer to see if it is right.

7 0
4 years ago
Other questions:
  • A large flowing network of streams and rivers moving across a land area is a ______________________.
    15·1 answer
  • Choose all that apply.
    6·2 answers
  • Eric has asked you to help him build a new gaming computer so that he can play the newest games available. He also wants the com
    6·1 answer
  • 40 points to answer ALL
    9·2 answers
  • What is not true about field properties in Access?
    13·1 answer
  • One disadvantage of online information sharing is that:
    14·2 answers
  • Write a method named printGPA that takes in as a parameter a Scanner to read in user input, and calculates a student's grade poi
    8·1 answer
  • The meaning of docile can be determined by the... context clue. synonym atonym or explanation
    14·2 answers
  • BUYING A NEW COMPUTER
    15·1 answer
  • What type of software is used to create letters and papers? ​
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!