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

File Account java contains a definition for a simple bank account class with met

ID: 3718431 • Letter: F

Question

File Account java contains a definition for a simple bank account class with methods to withdraw, deposit, get the balance and account number, and return a String representation. Note that the constructor for this class creates a random account number. Save this class to your directory and study it to see how it works. Then modify it as follows: 1. Overload the constructor as follows: public Account (double initBal, String owner, long number)- initializes the balance, owner, and account number as specified public Account (double initBal, String owner) - initializes the balance and owner as specified; randomly generates the account number. public Account (String owner) - initializes the owner as specified; sets the initial balance to 0 and randomly generates the account number.

Explanation / Answer

import java.util.Random; public class Account { private double balance; private String owner; private long number; public Account(double balance, String owner, long number) { this.balance = balance; this.owner = owner; this.number = number; } public Account(double balance, String owner) { this.balance = balance; this.owner = owner; this.number = new Random().nextInt(); } public Account(double balance) { this.balance = balance; this.owner = ""; this.number = new Random().nextInt(); } public double getBalance() { return balance; } public long getNumber() { return number; } public void withdraw(double amount) { balance -= amount; if(balance < 0) { balance = 0; } } public void deposit(double amount) { balance += amount; } @Override public String toString() { return "balance=" + balance + ", owner='" + owner + ''' + ", number=" + number; } }
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