Question: Please Simple JAVA I/O exception question Please follow the bolded instruction of # of lines required etc TY /** A bank account has a balance

Please Simple JAVA I/O exception question

Please follow the bolded instruction of # of lines required etc TY

/**

A bank account has a balance that can be changed by

deposits and withdrawals.

This version throws an exception in the constructor.

*/

class BankAccount

{

//instance variables

private double balance; //the money in the account

/**

Constructs a bank account with a zero balance.

*/

public BankAccount()

{

balance = 0;

}

/**

Constructs a bank account with a given balance.

@param aBalance the initial balance

*/

public BankAccount(double aBalance)

{

//-----------Start below here. To do: approximate lines of code = 2

// 1. Throw an IllegalArgumentException if the initial balance is negative

//2. otherwise do the usual thing

//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.

}

/**

Deposits money into the bank account.

@param amount the amount to deposit, which cannot be negative

*/

public void deposit(double amount)

{

//-----------Start below here. To do: approximate lines of code = 1

// 3. Throw an IllegalArgumentException if the amount is negative

//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.

double newBalance = balance + amount;

balance = newBalance;

}

/**

Withdraws money from the bank account.

@param amount the amount to withdraw

*/

public void withdraw(double amount)

{

//-----------Start below here. To do: approximate lines of code = 1

// 4. Throw an IllegalArgumentException if the amount is too much or if amount is negative

//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.

balance -= amount ;

}

/**

Gets the current balance of the bank account.

@return the current balance

*/

public double getBalance()

{

return balance;

}

/**

Gives a string representation of the bankaccount,

but in this case the string is just the balance.

@return the balance as a string

*/

public String toString()

{

return "" + balance ;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Completed Java Code Snippet for IO Exception Handling Below is the required code for the specified S... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!