0% found this document useful (0 votes)
5 views

OOP Problem Statements1 (1)

Uploaded by

Harsh Bhogal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

OOP Problem Statements1 (1)

Uploaded by

Harsh Bhogal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

OOP Problem Statements

1.
Write the method findSimpleGene that has one String parameter dna, representing a string of DNA.
This method does the following:
● Finds the index position of the start codon “ATG”. If there is no “ATG”, return the empty
string.
● Finds the index position of the first stop codon “TAA” appearing after the “ATG” that was
found. If there is no such “TAA”, return the empty string.
● If the length of the substring between the “ATG” and “TAA” is a multiple of 3, then return
the substring that starts with that “ATG” and ends with that “TAA”.

DNA-“ AGGAATGTTCCCAATAGTAGACATAAAAGTC”

2. The Citizen class should have following attributes name, id, country, sex, marital Status, annual
Income, and economy Status. Validate the fields if the age is below 18 and country is not ‘India’
throw Non Eligible Exception and give proper message. Use to String method to display the
citizen object in proper format. Use separate packages for Exception and application classes

3. A. Write a Program to Print the Pascal’s Triangle in Java

B. Write a Java program to print the number triangle


4.
A. Write a Java program to remove prime numbers between 1 to 25 from ArrayList using an iterator.

B. Write a Java program to

a. create and traverse (or iterate) ArrayList using for-loop, iterator, and advance for-
loop.
b. check if element(value) exists in ArrayList?
c. add element at particular index of ArrayList?
5.
a) Implement the method find Numbers accepting two numbers num1 and num2 based on the
conditions given below:

Validate that num1 should be less than num2 . If the validations are successful populate all
the 2 digit positive numbers between num1 and num2 into the provided numbers array. If
sum of the digits of the number is a multiple of 3 return an empty array else return the
numbers array.
Test the functionalities using the main method of the Tester class.

b) Program to add any two given matrices and print the result.

6. Create a class Student with attributes roll no, name, age and course. Initialize values through
parameterized constructor. If age of student is not in between 15 and 21 then generate user-
defined exception "AgeNotWithinRangeException". If name contains numbers or special symbols
raise exception "NameNotValidException". Define the two exception classes.

7.
Write a Java method to find all twin prime numbers less than 100.

Twin primes are primes whose difference is 2 and only one composite no between them.

8.
Write a program for managing a store's inventory. The store has different types of products such as
Electronics and Clothing. Your task is to create a class hierarchy using inheritance to represent these
products in the inventory.

1. Create a base class named Inventory Item with the following attributes:
○ name (String): the name of the product.
○ Item ID (int): a unique identifier for each product.
2. Derive two classes from Inventory Item:
○ Electronics: represents an electronic product in the store. Include an additional
attribute warranty Period (int) for the warranty period in months.
○ Clothing: represents a clothing item in the store. Include an additional attribute size
(String) for the size of the clothing item.
3. Implement appropriate constructors for each class.
4. Create a method in the Inventory Item class called display Info() that displays the information
about the product (name, item ID). Override the display Info() method in the Electronics and
Clothing classes to include information specific to each type of product.
5. Create a test program to demonstrate the functionality of your classes. In the test program,
create instances of the Electronics and Clothing classes, and call the displayInfo() method to
display their information.

NOTE:- item ID is assigned automatically in a sequential manner for each new inventory item created
using a static keyword.

9. Write a Java program to manage and analyze an array of integers. The application should allow the
user to specify the number of elements, input integer values, and display the array in a user-friendly
format. It should compute the sum and average of the array, determine the largest and smallest
numbers, and provide search functionality to find a specific integer and its index.
10.
Write a Java application to generate Floyd’s Triangle based on the number of rows provided by the
user. For example, if the user enters 5, the pattern should look like:

1
23
456
7 8 9 10

11 12 13 14 15

11.
Write a Java program that prints a hollow square pattern of asterisks. The size of the square should be
specified by the user. For example, for a size of 5:

12.
Design a class StudentGradeCalculator that calculates and manages the grades of students based
on multiple assessments. The assessments include assignments, quizzes, and exams, and each type
of assessment has a different weightage. The class should provide methods to compute the final
grade of each student based on the given weights and scores for each assessment type. The
following features should be implemented:

Requirements:
1. Pass by Value: Implement methods where individual scores (assignment, quiz, exam) are
passed by value. Ensure that changing these values within the methods does not affect the
original values.
2. Passing Objects: Implement methods where student details (name, ID, and scores) are
passed as objects. Changes made to these objects should reflect outside the method.
3. Returning Multiple Values: Design methods that return multiple values, such as the average
grade, final grade, and a letter grade (A, B, C, D, F).
4. Custom Exception Handling: Include custom exception handling to manage cases where
invalid scores are entered (e.g., scores outside the range of 0–100).
5. Final Grade Calculation: Use weighted averages for assignments (40%), quizzes (30%), and
exams (30%) to compute the final grade.
6. Multiple Student Analysis: Extend functionality to analyze multiple students, returning a list
of final grades and names of students.

13. Design a Java application that simulates a bank transaction system using multithreading. The
application should demonstrate thread synchronization and the handling of concurrent
transactions. Requirements:
1. Account Class:
○ Represents a bank account with attributes:
■ Account Number: String
■ balance: double
○ Methods:
■ deposit(double amount): Adds the specified amount to the account balance.
■ withdraw(double amount): Deducts the specified amount from the account
balance, ensuring that sufficient funds are available.
2. Transaction Class:
○ Implements Runnable to represent a bank transaction.
○ Attributes:
■ account: Account (the account involved in the transaction)

14.
Design a Java application that demonstrates the concepts of polymorphism (compile-time and
runtime) and method overloading through a class hierarchy representing different types of bank
accounts. The application should allow calculating interest for different account types.
Requirements:
1. Base Class: Create a class named BankAccount with the following:
Attributes: accountNumber: String, accountHolderName: String, balance: double
o Methods: calculateInterest(): Returns the interest for a generic bank account.
Overloaded calculateInterest(double rate): Calculates interest based on the given rate.
2. Derived Classes:
o Create a class named SavingsAccount that extends BankAccount:
Override the calculateInterest() method to return interest based on a fixed savings
interest rate (e.g., 4%).
o Create a class named CurrentAccount that extends BankAccount:
Override the calculateInterest() method to return interest based on a different fixed
current account interest rate (e.g., 3%).
3. Main Class: In the main method, perform the following:
o Create instances of SavingsAccount and CurrentAccount.
o Call the overloaded calculateInterest() methods to demonstrate compile-time
polymorphism.
O Call the overridden calculateInterest() methods to demonstrate runtime polymorphism.
4. Expected Output:
o Show the calculated interest for different account types using both method overloading
and overriding.

15.
Create a Java program that uses StringBuffer to manipulate strings. The program should:
● Append a new string to an existing one.
● Reverse the entire string.
● Insert a substring at a specified index.
Replace a part of the string with another substring.
16. ● Develop a Java program to convert currency values between USD and INR. The
program must enforce strict input constraints, allowing only values between $1 and
$10,000. Implement a `CurrencyConverter` class with methods to convert USD to
INR and vice versa. Use a custom exception, `InvalidCurrencyValueException`, to
handle invalid inputs. The program should gracefully handle errors using try-catch
blocks and provide meaningful messages to the user. Predefined conversion rates are 1
USD = 83 INR and 1 INR = 0.012 USD. The user interface should allow multiple
conversions until they choose to exit.
17. You are tasked with designing a simple application for managing a library. The library has different
types of items such as books and DVDs. Your task is to create a class hierarchy using inheritance to
represent these items in the library. Requirements: Create a base class named LibraryItem with the
following attributes:
title (String): the title of the library item , itemID (int): a unique identifier for each library item
Derive two classes from LibraryItem: 1)Book: represents a book in the library. Include an additional
attribute author (String) for the book's author.
2) DVD: represents a DVD in the library. Include an additional attribute director (String) for the
DVD's director.
Implement appropriate constructors for each class.
Create a method in the LibraryItem class called displayInfo() that displays the information about the
library item (title, itemID). Override the displayInfo() method in the Book and DVD classes to
include information specific to each type of item.
Create a test program to demonstrate the functionality of your classes. In the test program, create
instances of the Book and DVD classes, and call the displayInfo() method to display their
information. Note: Ensure that the itemID is assigned automatically in a sequential manner for each
new library item created.
Sample output:
Book Information:
Title: Java language
Item ID:1
Author: ABC
Type: BOOK

DVD Information:
Title: C language
Item ID:2
Author: Jack sparrow
Type :DVD

DVD Information:
Title: OOP
Item ID:3
Author: Black smith
Type :DVD

18. Write a java program that includes functionalities such as


1) input string,
2)displaying the length,
3)finding and displaying the uppercase and lowercase versions,
4) checking if the string is a palindrome,
5) counting the occurrences of a specific character. and 6) string concatenation.

19. A Java program that performs various operations on arrays. Your program should include the
following functionalities:
Input: Prompt the user to enter the size of an array. Allow the user to input the elements of the array.
Display: Display the entered array.
1) Find and Display: Find and display the sum of all elements in the array.
2) Find and display the average of the elements.
3) Find and display the maximum and minimum values in the array.
4) Search: Prompt the user to enter a value to search for in the array. Display whether the value is
present in the array and, if yes,display its index.

20. BankAccount class is defined with methods for deposit, withdrawal, and getting the balance. The
withdraw method throws a custom Insufficient Funds Exception if the withdrawal amount exceeds
the account balance.
The BankApplication class shows the use of this bank account by taking user inputs for account
details, deposit, and withdrawal amounts. It includes a try-catch block to handle the custom exception
and a finally block to display the current balance regardless of whether an exception occurred or not.

21. Write a Java program to create a class called Student with private instance variables
student_id, student_name, and grades. Provide public getter and setter methods to access and
modify the student_id and student_name variables. However, provide a method called
addGrade() that allows adding a grade to the grades variable while performing additional
validation. Sample I/P Please Enter Your Id:1001, Please Enter Your Name:Rahul Jadhav,
Please Enter Your Marks: 90 78 87 91 (Use ArrayList to store the marks) Sample output:
Student ID: 1001
Student Name: Rahul Jadhav
Grades: [90, 78, 87, 91]

22. a) Write a Java program to create a class called Employee with methods called work() and
getSalary(). Create a subclass called HRManager that overrides the work() method and adds a new
method called addEmployee().
b) Implement a program to handle Arithmetic exception, Array Index Out of Bounds. The user enters
two numbers Num1 and Num2. The division of Num1 and Num2 is displayed. If Num1 and Num2
are not integers, the program would throw a Number Format Exception. If Num2 were zero, the
program would throw an Arithmetic Exception. Display the exception.
23.
Write a Java program for following

A) Write a method that returns a new array that contains the elements of the input array in the
reverse order ( Example : Input: [1,4,7,3,6] Output: [6,3,7,4,1] )

b) Write a Java program to create a base class Vehicle with methods startEngine() and
stopEngine(). Create two subclasses Car and Motorcycle. Override the startEngine() and
stopEngine() methods in each subclass to start and stop the engines differently.

24.
Implement a Java program for calculating the area of geometric shapes. The program should
support calculating the area of a rectangle, a square, and a circle. Each shape has a different
method to calculate its area. Your task is to implement a Java program that demonstrates method
overloading by providing multiple versions of the calculateArea() method to calculate the area of
each shape. (Use method overloading)

You might also like