Java Reference
In-Depth Information
Figure 11.11
Output of the BankDemo program.
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();
}
}
}
Lab 11.1: Writing try/catch Blocks
The purpose of this lab is to become familiar with writing a try/catch block.
1. Write a class named Multiply and add main() within the class. The
Multiply class is going to multiply two numbers together that are
input by using the command-line arguments.
2. Within main(), declare a try block that parses the first two
command-line arguments into ints by using the Integer.parseInt()
method.
Search WWH ::




Custom Search