
ASSIGNMENT No: 02
Due Date: 16th March 2012
1. Create a class of Employee and prompt the user for time. If time is later than 9 am then
throw a user defined”TooLate Exception” displaying a message that you are too late.
2. Handle above exception in a try catch block by calling a function handleException. At
the end display “Program Ended “whether exception is thrown or not.
3. Define an object and initialize it to null. Try to call a method through this reference. Now
wrap the code in a try-catch clause to catch the exception
4. Write a program which throws an ArrayOutOfBoundsException and catch specified
exception in catch block.
5. Write a program which calls func1 of class A and the func1 calls func2 of class B. func2
throws a user defined exception. Your task is to handle this exception in the main
method.
6. Create an interface RemoteControlwhich has functions :
public interface RemoteControl {
booleanpowerOnOff(); // Returns new state, on = true
intvolumeUp(int increment); // Returns new volume level
intvolumeDown(int decrement); // Returns new volume level
void mute(); // Mutes sound output
intsetChannel(int channel); // Set the channel number and return it
intchannelUp(); // Returns new channel number
intchannelDown(); // Returns new channel number
}
Write a class TV that inherits Interface RemoteControl. Provide proper implementation of
interface. You may add following datamembers of TV to provide implementation for methods:
private String make = null;
private intscreensize = 0;
private boolean power = false;
private int MIN_VOLUME = 0;
private int MAX_VOLUME = 100;
private int volume = MIN_VOLUME;
private int MIN_CHANNEL = 0;
private int MAX_CHANNEL = 999;
private int channel = 0;