PROGRAM 1: String Extraction
Aim:
To write a Java program that extracts a substring from a given string using user-defined
starting and ending positions.
Algorithm:
1. Start.
2. Prompt the user to enter a string.
3. Prompt the user to enter the starting index.
4. Prompt the user to enter the ending index.
5. Convert the index inputs to integers.
6. Check if the starting index is less than the ending index.
- If true, extract and display the substring.
- Else, display an invalid input message.
7. End.
PROGRAM 2: Interface Concept
Aim:
To implement the concept of interfaces and interface inheritance in Java and compute the
area of a circle.
Algorithm:
1. Start.
2. Define interface intface1 with radius and pi values.
3. Define interface intface2 with method computearea().
4. Define interface intface3 that extends both intface1 and intface2, with method
displaycircle().
5. Create a class sample that implements intface3.
6. Implement the methods:
- displaycircle() to print circle details.
- computearea() to calculate and display area.
7. In the main method:
- Create an object of class sample.
- Call displaycircle() and computearea().
8. End.
PROGRAM 3: Custom Exception Handling
Aim:
To implement custom exception handling in Java to restrict withdrawal if the entered
amount exceeds a threshold.
Algorithm:
1. Start.
2. Create a custom exception class PayOutOfBounds extending Exception.
3. In the main class:
- Prompt the user to enter name, account number, and amount.
- Convert amount to integer.
4. If amount > 10000, throw PayOutOfBounds exception.
5. Catch and handle:
- PayOutOfBounds with custom message.
- NumberFormatException if amount input is invalid.
- Generic Exception for other errors.
6. Close the scanner.
7. End.
PROGRAM 4: Multithreading with Ordered Output
Aim:
To create multiple threads in Java to print multiplication tables using the join() method for
ordered output.
Algorithm:
1. Start.
2. Create a class TableThread extending Thread with:
- Constructor to accept number and multiplier.
- run() method to print multiplication result.
3. In the main class:
- Use a loop from 1 to 5.
- For each loop value:
- Create three threads to multiply the number with 5, 3, and 7.
- Start each thread and immediately call join() to wait for its completion.
4. End.