Java_Program_Solutions (1)
Java_Program_Solutions (1)
Question 1
Write a program to give a simple example for an abstract class.
Solution:
Question 2
Create an outer class with a function display, again create another class inside the outer
class named inner with a function called display and call the two functions in the main class.
Solution:
Question 3
Write a program to create a class named shape. In this class, we have three subclasses:
circle, triangle, and square. Each class has two member functions named draw() and erase().
Create these using polymorphism concepts.
Solution:
Question 4
Write a program to create interface A. In this interface, we have two methods: meth1 and
meth2. Implement this interface in another class named MyClass.
Solution:
Question 5
Write a program to create an interface named test. In this interface, the member function is
square. Implement this interface in the arithmetic class. Create one new class called
ToTestInt. In this class, use the object of the arithmetic class.
Solution:
Question 6
Write a program to give an example of multiple inheritance in Java.
Solution:
Question 7
Write a program to create a package named mypack and import it in the circle class.
Solution:
Question 8
Create a class Number with one private instance variable of type double. Include methods
isZero(), isPositive(), isNegative(), isOdd(), isEven(), isPrime(), isArmstrong(),
getFactorial(), getSqrt(), getSqr(), sumDigits(), getReverse(), void listFactor(), void
dispBinary().
Solution:
Question 9
Solve problem by using sequential search algorithms (Selection, insertion).
Solution:
Question 10
Solve problem by using binary search sorting algorithms (Selection, insertion).
Solution:
Question 11
Solve problem by using quadratic sorting algorithms (Selection, insertion).
Solution:
Question 12
Develop stack and queue data structures using classes and objects.
Solution:
Question 13
Develop a Java application with an Employee class with members for generating a pay slip
using inheritance.
Solution:
Question 14
Write a Java program to create an abstract class for calculating the area of different shapes.
Solution:
Question 15
Write a Java program to create an interface for calculating the area of different shapes.
Solution:
Question 16
Write a Java program for implementing user-defined exception handling.
Solution:
Question 17
Write a Java program for implementing a multi-threaded application.
Solution:
Question 18
Write a Java program that reads a file name from the user, displays information about
whether the file exists, whether the file is readable, writable, the type of file, and the length
of the file in bytes.
Solution:
Question 19
Write a program for an example of a try and catch block. In this, check whether the given
array size is negative or not.
Solution:
Question 20
Write a program for an example of multiple catch statements occurring in a program.
Solution:
Question 21
Write a program to create a class MyThread. In this class, use a constructor to call the base
class constructor using super and start the thread. The run method of the class starts after
this. Both the main thread and the child thread are executed concurrently.
Solution:
Question 22
Develop a Java application with an Employee class with Emp_name, Emp_id, Address,
Mail_id, Mobile_no as members. Inherit the classes Programmer, Assistant Professor,
Associate Professor, and Professor from the Employee class. Add Basic Pay (BP) as the
member of all the inherited classes with 97% of BP as DA, 10% of BP as HRA, 12% of BP as
PF, 0.1% of BP for staff club funds. Generate pay slips for the employees with their gross
and net salary.
Solution:
Question 23
Write a Java Program to create an abstract class named Shape that contains two integers
and an empty method named printArea(). Provide three classes named Rectangle, Triangle,
and Circle such that each one of the classes extends the class Shape. Each one of the classes
contains only the method printArea() that prints the area of the given shape.
Solution:
Question 24
Create a multithreaded program by creating a subclass of Thread and then creating,
initializing, and starting two Thread objects from your class. The threads will execute
concurrently and display 'Java is hot, aromatic, and invigorating' to the console window.
Solution:
Question 25
Write a Java program that implements a multi-threaded application that has three threads.
The first thread generates a random integer every 1 second. If the value is even, the second
thread computes the square of the number and prints it. If the value is odd, the third thread
will print the cube of the number.
Solution:
Question 26
Write a Java program to find the maximum value from the given type of elements using a
generic function.
Solution:
Question 27
Develop the Internal mark calculation system based on the attendance percentage using
Java. Get the student name, register number, total number of working days in the semester,
and number of days present. Calculate attendance percentage and award attendance marks
based on specific conditions.
Solution:
Question 28
Write a Java program for implementing a generic class.
Solution:
Question 29
Design a calculator as a mini-project using the event-driven programming paradigm of Java
with options for decimal and scientific manipulations.
Solution:
Question 30
Develop queue data structures using classes and objects.
Solution:
Question 31
Write a Java Program to create an abstract class named sum of Two and sum of Three.
Perform addition of two numbers and addition of three numbers.
Solution:
Question 32
Write a program to Check Prime Number using Interface.
Solution:
Question 33
Write a Java program to find the sum value of two given types of elements using a generic
class.
Solution:
Question 34
Write a Java program that implements a multi-threaded application that has three threads.
The first thread generates a random integer every one second. If the value is odd, the
second thread computes the square of the number. If the value is even, the third computes
the cube of the number.
Solution:
Question 35
Create a Java Application to calculate GPA for 5 subjects using the marks and credits of the
subjects and implement user-defined exceptions for subject mark, credits, subject name,
and subject code.
Solution:
Question 36
Write Java programs to implement Arithmetic exceptions and Array IndexOutOfBound
exceptions.
Solution:
Question 37
Write a Java program that keeps a number from the user and generates an integer between
1 and 12 and displays the name of the month.
Solution:
Question 38
Write a program to Check Prime Number using Interface.
Solution:
Question 39
Write a Java program to implement user-defined exception handling for the result of input
a=1, b=0 performing c=a/b.
Solution:
Question 40
Write a Java program that implements sequential and binary search.
Solution:
Question 41
Write a Java program that implements insertion and selection sort.
Solution:
Question 42
Write a Java program that reads a file and displays its contents on the screen, with a line
number before each line.
Solution:
Question 43
Write a generic method to count the number of elements in a collection with a specific
property (e.g., odd integers, prime numbers, palindromes).
Solution:
Question 44
Write a Java program illustrating the creation of a simple package, accessing a package, and
implementing interfaces.
Solution: