SlideShare a Scribd company logo
1 of 5
Download to read offline
Object Oriented Programming
COSC-1202
Laboratory Manual
Fall 2017
LAB 13
Packages in Exception Handling Java
Instructor: Sameen Fatima
_______________________
TEACHING ASISTANT SIGNATURE & DATE
MARKS AWARDED: /10
__________________________________________________________________
KHAWAJA FAREED UNIVERSITY OF ENGINEERING AND INFORMATION TECHNOLOGY
Last Edited By Ms. Sameen Fatima Version 01
Prepared By Ms. Sameen Fatima Date 08 Aug, 2017
LAB 13 Interfaces and Packages in Java
Lab Objectives:
1. Understanding the concept of Interfaces in Java
Software Required:
Netbeans IDE
Packages
The package is both a naming and a visibility control mechanism. You can define classes inside
a package that are not accessible by code outside that package. You can also define class
members that are exposed only to other members of the same package. This allows your classes
to have intimate knowledge of each other, but not expose that knowledge to the rest of the world.
Because of the interplay between classes and packages, Java addresses four categories of
visibility for class members:
 Subclasses in the same package
 Non-subclasses in the same package
 Subclasses in different packages
 Classes that are neither in the same package nor subclasses
TASK 01: Create packages and try to access private, protected, public and default data members in
another package. Also create subclasses a class outside its package and try to access private, protected,
default and public data members.
EXCEPTIONS
Exception handling is a very important yet often neglected aspect of writing robust software. When an
error occurs in a Java program it usually results in an exception being thrown. How you throw, catch and
handle these exception matters. Runtime errors appear in Java as exceptions, exception is a special type of
classes that could be thrown to indicate a runtime error and provide additional data about that error. If a
method is declared to throw an exception, any other method calls it should deal with this exception by
throwing it (if it appears) or handle it.
Three categories of errors (syntax errors, runtime errors, and logic errors):
1. Syntax errors arise because the rules of the language have not been followed. They are detected
by the compiler.
2. You can use the debugging techniques to find logic errors.
3. Exception handling to deal with runtime errors and using assertions to help ensure program
correctness.
TASK 02: Run following code
TASK 03: Run the following code
TASK 04: Run the following code
// File Name InsufficientFundsException.java
import java.io.*;
public class InsufficientFundsException extends Exception {
private double amount;
public InsufficientFundsException(double amount) {
this.amount = amount;
}
public double getAmount() {
return amount;
}
}
// File Name CheckingAccount.java
import java.io.*;
public class CheckingAccount {
private double balance;
private int number;
public CheckingAccount(int number) {
this.number = number;
}
public void deposit(double amount) {
balance += amount;
}
public void withdraw(double amount) throws InsufficientFundsException {
if(amount <= balance) {
balance -= amount;
}else {
double needs = amount - balance;
throw new InsufficientFundsException(needs);
}
}
public double getBalance() {
return balance;
}
public int getNumber() {
return number;
}
}
// File Name BankDemo.java
public class BankDemo {
public static void main(String [] args) {
CheckingAccount c = new CheckingAccount(101);
System.out.println("Depositing $500...");
c.deposit(500.00);
try {
System.out.println("nWithdrawing $100...");
c.withdraw(100.00);
System.out.println("nWithdrawing $600...");
c.withdraw(600.00);
} catch (InsufficientFundsException e) {
System.out.println("Sorry, but you are short $" + e.getAmount());
e.printStackTrace();
}
}
}
TASK 05: Write a program that counts even numbers between minimum and maximum values.
Maximum and minimum values are provided by user. If minimum value is greater than or equal to
maximum value, the program should throw an InvalidRange exception and handle it to display a message
to the user on the following format: Invalid range: minimum is greater than or equal to maximum.

More Related Content

What's hot

Operators, control statements represented in java
Operators, control statements  represented in javaOperators, control statements  represented in java
Operators, control statements represented in javaTharuniDiddekunta
 
Java căn bản - Chapter8
Java căn bản - Chapter8Java căn bản - Chapter8
Java căn bản - Chapter8Vince Vo
 
Bt0074 oops with java2
Bt0074 oops with java2Bt0074 oops with java2
Bt0074 oops with java2Techglyphs
 
Introduction
IntroductionIntroduction
Introductionrichsoden
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handlingkamal kotecha
 
Intro to programing with java-lecture 1
Intro to programing with java-lecture 1Intro to programing with java-lecture 1
Intro to programing with java-lecture 1Mohamed Essam
 
JAVA - Throwable class
JAVA - Throwable classJAVA - Throwable class
JAVA - Throwable classasifpatel20
 
Exception Handling in C#
Exception Handling in C#Exception Handling in C#
Exception Handling in C#Abid Kohistani
 
Exception handling
Exception handlingException handling
Exception handlingzindadili
 
GENERIC CODE CLONING METHOD FOR DETECTION OF CLONE CODE IN SOFTWARE DEVELOPMENT
GENERIC CODE CLONING METHOD FOR DETECTION OF CLONE CODE IN SOFTWARE DEVELOPMENT GENERIC CODE CLONING METHOD FOR DETECTION OF CLONE CODE IN SOFTWARE DEVELOPMENT
GENERIC CODE CLONING METHOD FOR DETECTION OF CLONE CODE IN SOFTWARE DEVELOPMENT IAEME Publication
 
Dot net softvamp techno solutions_technical interview questions 2 years exper...
Dot net softvamp techno solutions_technical interview questions 2 years exper...Dot net softvamp techno solutions_technical interview questions 2 years exper...
Dot net softvamp techno solutions_technical interview questions 2 years exper...SoftvampTechnoSoluti
 

What's hot (20)

Operators, control statements represented in java
Operators, control statements  represented in javaOperators, control statements  represented in java
Operators, control statements represented in java
 
Java scjp-part1
Java scjp-part1Java scjp-part1
Java scjp-part1
 
Java căn bản - Chapter8
Java căn bản - Chapter8Java căn bản - Chapter8
Java căn bản - Chapter8
 
Bt0074 oops with java2
Bt0074 oops with java2Bt0074 oops with java2
Bt0074 oops with java2
 
Introduction
IntroductionIntroduction
Introduction
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
Java
JavaJava
Java
 
Creating your own exception
Creating your own exceptionCreating your own exception
Creating your own exception
 
Getting Program Input
Getting Program Input Getting Program Input
Getting Program Input
 
Event handling
Event handlingEvent handling
Event handling
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
Chapter 09
Chapter 09Chapter 09
Chapter 09
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Intro to programing with java-lecture 1
Intro to programing with java-lecture 1Intro to programing with java-lecture 1
Intro to programing with java-lecture 1
 
JAVA - Throwable class
JAVA - Throwable classJAVA - Throwable class
JAVA - Throwable class
 
Exception Handling in C#
Exception Handling in C#Exception Handling in C#
Exception Handling in C#
 
Exception handling
Exception handlingException handling
Exception handling
 
Tutorial 6
Tutorial 6Tutorial 6
Tutorial 6
 
GENERIC CODE CLONING METHOD FOR DETECTION OF CLONE CODE IN SOFTWARE DEVELOPMENT
GENERIC CODE CLONING METHOD FOR DETECTION OF CLONE CODE IN SOFTWARE DEVELOPMENT GENERIC CODE CLONING METHOD FOR DETECTION OF CLONE CODE IN SOFTWARE DEVELOPMENT
GENERIC CODE CLONING METHOD FOR DETECTION OF CLONE CODE IN SOFTWARE DEVELOPMENT
 
Dot net softvamp techno solutions_technical interview questions 2 years exper...
Dot net softvamp techno solutions_technical interview questions 2 years exper...Dot net softvamp techno solutions_technical interview questions 2 years exper...
Dot net softvamp techno solutions_technical interview questions 2 years exper...
 

Similar to Lab13 (20)

Exception handler
Exception handler Exception handler
Exception handler
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)
 
Professional-core-java-training
Professional-core-java-trainingProfessional-core-java-training
Professional-core-java-training
 
OOP in Java Presentation.pptx
OOP in Java Presentation.pptxOOP in Java Presentation.pptx
OOP in Java Presentation.pptx
 
Understanding And Using Reflection
Understanding And Using ReflectionUnderstanding And Using Reflection
Understanding And Using Reflection
 
Professional-core-java-training
Professional-core-java-trainingProfessional-core-java-training
Professional-core-java-training
 
01slide
01slide01slide
01slide
 
01slide
01slide01slide
01slide
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
Java intro
Java introJava intro
Java intro
 
DAY_1.1.pptx
DAY_1.1.pptxDAY_1.1.pptx
DAY_1.1.pptx
 
Unit 5 Java
Unit 5 JavaUnit 5 Java
Unit 5 Java
 
01slide
01slide01slide
01slide
 
Core java-introduction
Core java-introductionCore java-introduction
Core java-introduction
 
Java programming-Event Handling
Java programming-Event HandlingJava programming-Event Handling
Java programming-Event Handling
 
Bca 4020 java programming
Bca 4020   java programmingBca 4020   java programming
Bca 4020 java programming
 
OOFeatures_revised-2.pptx
OOFeatures_revised-2.pptxOOFeatures_revised-2.pptx
OOFeatures_revised-2.pptx
 
Java
JavaJava
Java
 
3350703
33507033350703
3350703
 
Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answers
 

Recently uploaded

Call Girls In Okhla DELHI ~9654467111~ Short 1500 Night 6000
Call Girls In Okhla DELHI ~9654467111~ Short 1500 Night 6000Call Girls In Okhla DELHI ~9654467111~ Short 1500 Night 6000
Call Girls In Okhla DELHI ~9654467111~ Short 1500 Night 6000Sapana Sha
 
NO1 Verified kala jadu karne wale ka contact number kala jadu karne wale baba...
NO1 Verified kala jadu karne wale ka contact number kala jadu karne wale baba...NO1 Verified kala jadu karne wale ka contact number kala jadu karne wale baba...
NO1 Verified kala jadu karne wale ka contact number kala jadu karne wale baba...Amil baba
 
webinaire-green-mirror-episode-2-Smart contracts and virtual purchase agreeme...
webinaire-green-mirror-episode-2-Smart contracts and virtual purchase agreeme...webinaire-green-mirror-episode-2-Smart contracts and virtual purchase agreeme...
webinaire-green-mirror-episode-2-Smart contracts and virtual purchase agreeme...Cluster TWEED
 
VIP Call Girls Service Chaitanyapuri Hyderabad Call +91-8250192130
VIP Call Girls Service Chaitanyapuri Hyderabad Call +91-8250192130VIP Call Girls Service Chaitanyapuri Hyderabad Call +91-8250192130
VIP Call Girls Service Chaitanyapuri Hyderabad Call +91-8250192130Suhani Kapoor
 
Mumbai Call Girls, 💞 Prity 9892124323, Navi Mumbai Call girls
Mumbai Call Girls, 💞  Prity 9892124323, Navi Mumbai Call girlsMumbai Call Girls, 💞  Prity 9892124323, Navi Mumbai Call girls
Mumbai Call Girls, 💞 Prity 9892124323, Navi Mumbai Call girlsPooja Nehwal
 
Booking open Available Pune Call Girls Budhwar Peth 6297143586 Call Hot Indi...
Booking open Available Pune Call Girls Budhwar Peth  6297143586 Call Hot Indi...Booking open Available Pune Call Girls Budhwar Peth  6297143586 Call Hot Indi...
Booking open Available Pune Call Girls Budhwar Peth 6297143586 Call Hot Indi...Call Girls in Nagpur High Profile
 
(ZARA) Call Girls Talegaon Dabhade ( 7001035870 ) HI-Fi Pune Escorts Service
(ZARA) Call Girls Talegaon Dabhade ( 7001035870 ) HI-Fi Pune Escorts Service(ZARA) Call Girls Talegaon Dabhade ( 7001035870 ) HI-Fi Pune Escorts Service
(ZARA) Call Girls Talegaon Dabhade ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Call Girls In Faridabad(Ballabgarh) Book ☎ 8168257667, @4999
Call Girls In Faridabad(Ballabgarh) Book ☎ 8168257667, @4999Call Girls In Faridabad(Ballabgarh) Book ☎ 8168257667, @4999
Call Girls In Faridabad(Ballabgarh) Book ☎ 8168257667, @4999Tina Ji
 
Contact Number Call Girls Service In Goa 9316020077 Goa Call Girls Service
Contact Number Call Girls Service In Goa  9316020077 Goa  Call Girls ServiceContact Number Call Girls Service In Goa  9316020077 Goa  Call Girls Service
Contact Number Call Girls Service In Goa 9316020077 Goa Call Girls Servicesexy call girls service in goa
 
VVIP Pune Call Girls Moshi WhatSapp Number 8005736733 With Elite Staff And Re...
VVIP Pune Call Girls Moshi WhatSapp Number 8005736733 With Elite Staff And Re...VVIP Pune Call Girls Moshi WhatSapp Number 8005736733 With Elite Staff And Re...
VVIP Pune Call Girls Moshi WhatSapp Number 8005736733 With Elite Staff And Re...SUHANI PANDEY
 
Hot Call Girls |Delhi |Preet Vihar ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Preet Vihar ☎ 9711199171 Book Your One night StandHot Call Girls |Delhi |Preet Vihar ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Preet Vihar ☎ 9711199171 Book Your One night Standkumarajju5765
 
(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
DENR EPR Law Compliance Updates April 2024
DENR EPR Law Compliance Updates April 2024DENR EPR Law Compliance Updates April 2024
DENR EPR Law Compliance Updates April 2024itadmin50
 
Call Girls Ramtek Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Ramtek Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Ramtek Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Ramtek Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Call On 6297143586 Pimpri Chinchwad Call Girls In All Pune 24/7 Provide Call...
Call On 6297143586  Pimpri Chinchwad Call Girls In All Pune 24/7 Provide Call...Call On 6297143586  Pimpri Chinchwad Call Girls In All Pune 24/7 Provide Call...
Call On 6297143586 Pimpri Chinchwad Call Girls In All Pune 24/7 Provide Call...tanu pandey
 

Recently uploaded (20)

Call Girls In Okhla DELHI ~9654467111~ Short 1500 Night 6000
Call Girls In Okhla DELHI ~9654467111~ Short 1500 Night 6000Call Girls In Okhla DELHI ~9654467111~ Short 1500 Night 6000
Call Girls In Okhla DELHI ~9654467111~ Short 1500 Night 6000
 
NO1 Verified kala jadu karne wale ka contact number kala jadu karne wale baba...
NO1 Verified kala jadu karne wale ka contact number kala jadu karne wale baba...NO1 Verified kala jadu karne wale ka contact number kala jadu karne wale baba...
NO1 Verified kala jadu karne wale ka contact number kala jadu karne wale baba...
 
Call Girls In Dhaula Kuan꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCe
Call Girls In Dhaula Kuan꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCeCall Girls In Dhaula Kuan꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCe
Call Girls In Dhaula Kuan꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCe
 
webinaire-green-mirror-episode-2-Smart contracts and virtual purchase agreeme...
webinaire-green-mirror-episode-2-Smart contracts and virtual purchase agreeme...webinaire-green-mirror-episode-2-Smart contracts and virtual purchase agreeme...
webinaire-green-mirror-episode-2-Smart contracts and virtual purchase agreeme...
 
VIP Call Girls Service Chaitanyapuri Hyderabad Call +91-8250192130
VIP Call Girls Service Chaitanyapuri Hyderabad Call +91-8250192130VIP Call Girls Service Chaitanyapuri Hyderabad Call +91-8250192130
VIP Call Girls Service Chaitanyapuri Hyderabad Call +91-8250192130
 
Mumbai Call Girls, 💞 Prity 9892124323, Navi Mumbai Call girls
Mumbai Call Girls, 💞  Prity 9892124323, Navi Mumbai Call girlsMumbai Call Girls, 💞  Prity 9892124323, Navi Mumbai Call girls
Mumbai Call Girls, 💞 Prity 9892124323, Navi Mumbai Call girls
 
Call Girls In Pratap Nagar꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCe
Call Girls In Pratap Nagar꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCeCall Girls In Pratap Nagar꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCe
Call Girls In Pratap Nagar꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCe
 
Booking open Available Pune Call Girls Budhwar Peth 6297143586 Call Hot Indi...
Booking open Available Pune Call Girls Budhwar Peth  6297143586 Call Hot Indi...Booking open Available Pune Call Girls Budhwar Peth  6297143586 Call Hot Indi...
Booking open Available Pune Call Girls Budhwar Peth 6297143586 Call Hot Indi...
 
(ZARA) Call Girls Talegaon Dabhade ( 7001035870 ) HI-Fi Pune Escorts Service
(ZARA) Call Girls Talegaon Dabhade ( 7001035870 ) HI-Fi Pune Escorts Service(ZARA) Call Girls Talegaon Dabhade ( 7001035870 ) HI-Fi Pune Escorts Service
(ZARA) Call Girls Talegaon Dabhade ( 7001035870 ) HI-Fi Pune Escorts Service
 
Call Girls In Faridabad(Ballabgarh) Book ☎ 8168257667, @4999
Call Girls In Faridabad(Ballabgarh) Book ☎ 8168257667, @4999Call Girls In Faridabad(Ballabgarh) Book ☎ 8168257667, @4999
Call Girls In Faridabad(Ballabgarh) Book ☎ 8168257667, @4999
 
Green Banking
Green Banking Green Banking
Green Banking
 
Contact Number Call Girls Service In Goa 9316020077 Goa Call Girls Service
Contact Number Call Girls Service In Goa  9316020077 Goa  Call Girls ServiceContact Number Call Girls Service In Goa  9316020077 Goa  Call Girls Service
Contact Number Call Girls Service In Goa 9316020077 Goa Call Girls Service
 
VVIP Pune Call Girls Moshi WhatSapp Number 8005736733 With Elite Staff And Re...
VVIP Pune Call Girls Moshi WhatSapp Number 8005736733 With Elite Staff And Re...VVIP Pune Call Girls Moshi WhatSapp Number 8005736733 With Elite Staff And Re...
VVIP Pune Call Girls Moshi WhatSapp Number 8005736733 With Elite Staff And Re...
 
young Whatsapp Call Girls in Delhi Cantt🔝 9953056974 🔝 escort service
young Whatsapp Call Girls in Delhi Cantt🔝 9953056974 🔝 escort serviceyoung Whatsapp Call Girls in Delhi Cantt🔝 9953056974 🔝 escort service
young Whatsapp Call Girls in Delhi Cantt🔝 9953056974 🔝 escort service
 
Hot Call Girls |Delhi |Preet Vihar ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Preet Vihar ☎ 9711199171 Book Your One night StandHot Call Girls |Delhi |Preet Vihar ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Preet Vihar ☎ 9711199171 Book Your One night Stand
 
(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
DENR EPR Law Compliance Updates April 2024
DENR EPR Law Compliance Updates April 2024DENR EPR Law Compliance Updates April 2024
DENR EPR Law Compliance Updates April 2024
 
(NEHA) Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts 24x7
(NEHA) Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts 24x7(NEHA) Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts 24x7
(NEHA) Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts 24x7
 
Call Girls Ramtek Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Ramtek Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Ramtek Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Ramtek Call Me 7737669865 Budget Friendly No Advance Booking
 
Call On 6297143586 Pimpri Chinchwad Call Girls In All Pune 24/7 Provide Call...
Call On 6297143586  Pimpri Chinchwad Call Girls In All Pune 24/7 Provide Call...Call On 6297143586  Pimpri Chinchwad Call Girls In All Pune 24/7 Provide Call...
Call On 6297143586 Pimpri Chinchwad Call Girls In All Pune 24/7 Provide Call...
 

Lab13

  • 1. Object Oriented Programming COSC-1202 Laboratory Manual Fall 2017 LAB 13 Packages in Exception Handling Java Instructor: Sameen Fatima _______________________ TEACHING ASISTANT SIGNATURE & DATE MARKS AWARDED: /10 __________________________________________________________________ KHAWAJA FAREED UNIVERSITY OF ENGINEERING AND INFORMATION TECHNOLOGY Last Edited By Ms. Sameen Fatima Version 01 Prepared By Ms. Sameen Fatima Date 08 Aug, 2017
  • 2. LAB 13 Interfaces and Packages in Java Lab Objectives: 1. Understanding the concept of Interfaces in Java Software Required: Netbeans IDE Packages The package is both a naming and a visibility control mechanism. You can define classes inside a package that are not accessible by code outside that package. You can also define class members that are exposed only to other members of the same package. This allows your classes to have intimate knowledge of each other, but not expose that knowledge to the rest of the world. Because of the interplay between classes and packages, Java addresses four categories of visibility for class members:  Subclasses in the same package  Non-subclasses in the same package  Subclasses in different packages  Classes that are neither in the same package nor subclasses TASK 01: Create packages and try to access private, protected, public and default data members in another package. Also create subclasses a class outside its package and try to access private, protected, default and public data members. EXCEPTIONS Exception handling is a very important yet often neglected aspect of writing robust software. When an error occurs in a Java program it usually results in an exception being thrown. How you throw, catch and handle these exception matters. Runtime errors appear in Java as exceptions, exception is a special type of classes that could be thrown to indicate a runtime error and provide additional data about that error. If a method is declared to throw an exception, any other method calls it should deal with this exception by throwing it (if it appears) or handle it. Three categories of errors (syntax errors, runtime errors, and logic errors): 1. Syntax errors arise because the rules of the language have not been followed. They are detected by the compiler. 2. You can use the debugging techniques to find logic errors.
  • 3. 3. Exception handling to deal with runtime errors and using assertions to help ensure program correctness. TASK 02: Run following code TASK 03: Run the following code
  • 4. TASK 04: Run the following code // File Name InsufficientFundsException.java import java.io.*; public class InsufficientFundsException extends Exception { private double amount; public InsufficientFundsException(double amount) { this.amount = amount; } public double getAmount() { return amount; } } // File Name CheckingAccount.java import java.io.*; public class CheckingAccount { private double balance; private int number; public CheckingAccount(int number) { this.number = number; } public void deposit(double amount) { balance += amount; } public void withdraw(double amount) throws InsufficientFundsException { if(amount <= balance) { balance -= amount; }else { double needs = amount - balance; throw new InsufficientFundsException(needs); } } public double getBalance() { return balance; } public int getNumber() { return number; } }
  • 5. // File Name BankDemo.java public class BankDemo { public static void main(String [] args) { CheckingAccount c = new CheckingAccount(101); System.out.println("Depositing $500..."); c.deposit(500.00); try { System.out.println("nWithdrawing $100..."); c.withdraw(100.00); System.out.println("nWithdrawing $600..."); c.withdraw(600.00); } catch (InsufficientFundsException e) { System.out.println("Sorry, but you are short $" + e.getAmount()); e.printStackTrace(); } } } TASK 05: Write a program that counts even numbers between minimum and maximum values. Maximum and minimum values are provided by user. If minimum value is greater than or equal to maximum value, the program should throw an InvalidRange exception and handle it to display a message to the user on the following format: Invalid range: minimum is greater than or equal to maximum.