Could anyone please do this java programming : 1(a) write the code for the withd
ID: 3613274 • Letter: C
Question
Could anyone please do this java programming :1(a) write the code for the withdraw method so that it worksproperly. Make sure your code works as described by the commentabove the method. Also, in the Account class, write an accessormethod so that the owner of the bank account can be viewed fromanother class.
1(b)In a different Java file ,write the AccountTester class, whichuses the Account class. In
the main method of the AccountTester class, do the following (inthis order):
· Make two Account objects – each belonging to 2different people
· Add some money (a different amount) into both accounts
· Withdraw some money from one account
· Get the names and amount of money in each account, usingthe accessor methods,
and store these values into new variables that are declared in themain method
· For each account, use the above variables to print outonto the screen the owner’s
name and the amount of money in the account. Your output shouldlook
something like this:
Jason has $10.0
/**I really appreciate all the answer for this question
* This class represents a bank account
* @author:
*/
class Account
{
// Instance Variables
// Money in the bank account, in dollars
private double balance;
// Full name of the person who owns the account
private String owner;
// Constructor
/**
* Creates a new Account belonging to 'name'
*/
public Account(String name)
{
owner = name;
balance = 0;
}
// Instance Methods
/**
* Add 'amount' dollars into the account
* If amount < 0, then nothing happens
*/
public void deposit(double amount)
{
if (balance >= 0)
balance = balance + amount;
}
/**
* Deduct 'amount' dollars from the account
* If amount < 0, then nothing happens
* If there is not enough money in the account, then nothing happens
*/
public void withdraw(double amount)
{
// EXERCISE 1a: WRITE YOUR CODE HERE
}
public double getBalance()
{
return balance;
}
// EXERCISE 1b: WRITE YOUR METHOD HERE
Thank you so much
Explanation / Answer
please rate - thanks in addition to writting withdraw, you had no method to get thename. I added one /** * This class represents a bank account * @author: */ class Account { // Instance Variables // Money in the bank account, in dollars private double balance; // Full name of the person who owns the account private String owner; // Constructor /** * Creates a new Account belonging to 'name' */ public Account(String name) { owner = name; balance = 0; } // Instance Methods /** * Add 'amount' dollars into the account * If amount < 0, then nothing happens */ public void deposit(double amount) { if (balance >= 0) balance = balance + amount; } /** * Deduct 'amount' dollars from the account * If amount < 0, then nothing happens * If there is not enough money in the account, then nothinghappens */ public void withdraw(double amount) { // EXERCISE 1a: WRITE YOUR CODE HERE if(amountRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.