Java: An Introduction to Problem Solving and Programming (7th Edition)
Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
bartleby

Concept explainers

Expert Solution & Answer
Book Icon
Chapter 9, Problem 2P

Explanation of Solution

Modified code:

“Account.java”:

//Class Account

public class Account

{

    //Private variable

    private double balance;

    //Define a constructor

    public Account()

    {

        //Initialize the amount value

        balance = 0;

    }

    //Parameterized constructor

    public Account(double initialDeposit)

    {

        //Assign the value

        balance = initialDeposit;

    }

    //Function to get balance

    public double getBalance()

    {

        //Return the amount

        return balance;

    }

    //Function to deposit the amount

public double deposit(double amount) throws NegativeAmountException

    {

        //Check if amount is greater than 0

        if (amount > 0)

            //Add the value to the balance

            balance += amount;

        //Else

        Else

            //return -1;

            //Throw an exception

            throw new NegativeAmountException();

        //Return the balance

        return balance;

    }

    //Function definition to withdraw the amount

public double withdraw(double amount) throws InsufficentBalanceException, NegativeAmountException

    {

        //Check if amount is greater than balance

        if (amount > balance)

            //throw an exception

            throw new InsufficentBalanceException();

        //Check if amount is less than 0

        else if (amount < 0)

            //Throw an exception

            throw new NegativeAmountException();

        //Else

        else

            //Calculate the balance

            balance -= amount;

        //Return the balance amount

        return balance;

    }

    //Main method

    public static void main(String[] args)

    {

        //Create an object for the class

        Account a = new Account(10);

        //Try block

        try

        {

            //Deposit the value

            a...

Blurred answer
Students have asked these similar questions
Of the five primary components of an information system (hardware, software, data, people, process), which do you think is the most important to the success of a business organization? Part A - Define each primary component of the information system. Part B - Include your perspective on why your selection is most important. Part C - Provide an example from your personal experience to support your answer.
Management Information Systems
Q2/find the transfer function C/R for the system shown in the figure Re ད

Chapter 9 Solutions

Java: An Introduction to Problem Solving and Programming (7th Edition)

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,