Subject: Object Oriented Prgramming Language: Java Program Topic: Exception   Method withdraw throws an exception if amount is greater than balance.   public class Account{     private String accntNumber;     private String accntName;     private double balance;          public Account(){}     public Account(String num, String name, double bal){         accntNumber = num;         accntName = name;         balance = bal;     }          public double getBalance(){ return balance;} } //your class here

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter14: Exception Handling
Section: Chapter Questions
Problem 5PE
icon
Related questions
Question

Subject: Object Oriented Prgramming
Language: Java Program
Topic: Exception

 

Method withdraw throws an exception if amount is greater than balance.

 

public class Account{
    private String accntNumber;
    private String accntName;
    private double balance;
    
    public Account(){}
    public Account(String num, String name, double bal){
        accntNumber = num;
        accntName = name;
        balance = bal;
    }
    
    public double getBalance(){ return balance;}
}
//your class here

method withdraw throws an exception if amount is greater than balance.
For example:
Result
- new Account ("Acct-001", "Juan dela Cruz", 5000.0); Insufficient: Insufficient funds.
5500.0);
Balance: 5000.0
n ("Balance: "+account. getBalance ());
- new Account ("Acct-001", "Juan dela Cruz", 5000.0); Balance: 4500.0
500.0);
.n ("Balance: "+account.getBalance () );
Transcribed Image Text:method withdraw throws an exception if amount is greater than balance. For example: Result - new Account ("Acct-001", "Juan dela Cruz", 5000.0); Insufficient: Insufficient funds. 5500.0); Balance: 5000.0 n ("Balance: "+account. getBalance ()); - new Account ("Acct-001", "Juan dela Cruz", 5000.0); Balance: 4500.0 500.0); .n ("Balance: "+account.getBalance () );
method withdraw throws an exception if amount is greater than balance.
For example:
Test
Result
Account account = new Account ("Acct-001", "Juan dela Cruz", 5000.0); Insufficient: In:
account.withdraw (5500.0);
Balance: 5000.0
System.out.println ("Balance: "+account.getBalance () );
Account account = new Account ("Acct-001", "Juan dela Cruz", 5000.0); Balance: 4500.0
account.withdraw (500.0) ;
System.out.println ("Balance: "+account.getBalance () );
Transcribed Image Text:method withdraw throws an exception if amount is greater than balance. For example: Test Result Account account = new Account ("Acct-001", "Juan dela Cruz", 5000.0); Insufficient: In: account.withdraw (5500.0); Balance: 5000.0 System.out.println ("Balance: "+account.getBalance () ); Account account = new Account ("Acct-001", "Juan dela Cruz", 5000.0); Balance: 4500.0 account.withdraw (500.0) ; System.out.println ("Balance: "+account.getBalance () );
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Exception Handling Keywords
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
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT