Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

=+Do you use TiVo or some other way to record shows?

Answered: 1 week ago