Sunday, 12 March 2023

Unit 3 Java Programs


1. Create a package P and within that package create class PackClass which have method called findmax( ) which find maximum value from three numbers. Now import the package within another class DemoClass and now display the maximum number. 


2. Write a program that creates three different classes in three different packages and access them from default package. All the three packages should be at the same level. 


3. Create package pack1 within this package create class A which contains one instance variable and one instance method. Create another package pack2 within this package create class B. where class B is calling the method and variable of class A 


4. Write a program that accepts a string from command line and perform following operations: 1. Display each character on separate line in reverse order. 2. Count total number of chracters and display each character's position too. 3. Identify that whether the string is palindrom or not. 4. Count total number of uppercase and lowercase characters in it. 


5. Write a Java program to input n integer numbers and display lowest and second lowest number. Also handle the different exceptions possible to be thrown during execution. 


6. Write a program that takes a string from the user and validate it. The string should be at least 5 characters and should contain at least one digit. Display an appropriate valid message. 


7. Write an application that accepts marks of three different subject from user. Marks should be between 0 to 100, if marks of any of the subject is not belong to this range, generate custom exception out of RangeException. If marks of each subjects are greater than or equal to 40 then display message “PASS” along with percentage, otherwise display message “FAIL”. Also write exception handling code to catch all the possible runtime exceptions likely to be generated in the program. 


8. Write a program which takes the age of 5 persons from command line and find the average age of all persons. The program should handle exception if the argument is not correctly formatted and custom exception if the age is not between 1 to 100. 


9. Write an application that converts between meters and feet. Its first commandline argument is a number and second command line argument is either "centimeter" or "meter". If the argument equals "centimeter" displays a string reporting the equivalent number of meters. If this argument equals "meters", display a string reporting the equivalent number of centimeter. If unit is not given properly then generate custom exception Unitformatexception. If first argument is not proper format then generate numberformatexception. Generate other exception as per requirements. (1 meter=100 centimeter) 


10. Write a program that accepts 5 even numbers from command line , if any of the numbers is odd then throw custom exception OddException and count such invalid numbers.



No comments:

Post a Comment

python programs

1. sum of two number