23-24 Sem1 OOP Lab Problem Stmt CSAB
23-24 Sem1 OOP Lab Problem Stmt CSAB
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
2.
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.
3. 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.
4. BankAccount class is defined with methods for deposit, withdrawal, and getting the balance.
The withdraw method throws a custom InsufficientFundsException 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.
5.
Create a arraylist for software companies [Google, Apple, Microsoft, Amazon, Facebook] and
Perform following operations on Arraylist :
1. Add a new software company name in the above arraylist- CapGemini, and display the
output.
2. Replace the 3rd company from an array list with a new company name and display the
output.
3. Delete the 4th company from the array list and display the arraylist
4. Add sub arraylist in the above arraylist-[Walmart,Cognizant,HSBC] and display the
output.
5. Search that given company name is exist in arrayList or not.
6. You are tasked with creating a Java program that counts the number of unique words in a
given text using a HashSet.
Requirements:
WordCounter Class:
● Create a WordCounter class that includes the following:
● A method countUniqueWords(String text) that takes a text as input and returns the count
of unique words.
● Use a HashSet to store unique words.
● Consider a word as any sequence of characters separated by whitespace.
Main Application:
● Implement a main application that demonstrates the functionality of the WordCounter
class.
● Allow the user to input a text string.
● Use the WordCounter class to count and display the number of unique words in the input
text.
Sample Output :
Enter a text string: This is a simple Java program. Java is powerful and simple.
Number of unique words: 8
7. 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]
8. Write a Java program to create a banking system with three classes - Bank, Account,
SavingsAccount, and CurrentAccount. The bank should have a list of accounts and methods for
adding them. Accounts should be an interface with methods to deposit, withdraw, calculate
interest, and view balances. SavingsAccount and CurrentAccount should implement the Account
interface and have their own unique methods.
Case1:Savings Account:
Initial Deposit: 1000.00
Interest rate: 1.25%
Case 2:Current Account:
Initial Deposit: 5000.00
OverdraftLimit: 1000.00
Case3:Deposit to Account:
Now 100 to Savings Account.
Now deposit 500 to Current Account
Case4:Withdraw from Account:
Withdraw 150 from Savings Account.
Case5: Account Balance:
Savings A/c and Current A/c.:
Account balance: 950.0
Account balance: 5500.0
Case6: Apply Intrest:
After applying interest on Savings A/c for 1 year:
Savings A/c and Current A/c.:
Account balance: 961.875
Account balance: 5500.0
9. You are tasked with developing a simple Vehicle Rental System in Java. The system
should allow users to rent different types of vehicles, such as cars and bicycles. Implement an
class called Vehicle to represent the common attributes and behaviors of all vehicles. Then,
create two subclasses, Car and Bicycle, that inherit from the Vehicle class.
Requirement:
Vehicle Class: Include the following attributes:
● id (unique identifier for each vehicle)
● brand (the brand or make of the vehicle)
● rentalRate (the cost per hour for renting the vehicle)
Include the following methods:
● displayDetails() (display the details of the vehicle)
● calculateRentalCost(int hours) (calculate the total rental cost based on the rental rate and
the number of hours)
Car Class:
● Extend the Vehicle class. Include an additional attribute: numSeats (the number of
seats in the car) Override the displayDetails() method to include car-specific details.
● Bicycle Class:
● Extend the Vehicle class. Include an additional attribute: type (the type of bicycle,
e.g., mountain bike, road bike)
● Override the displayDetails() method to include bicycle-specific details.
● Main Application:
● Implement a main application that demonstrates the functionality of the system.
● Allow users to:
o Add new cars and bicycles to the system with their details.
o Display the details of all available vehicles.
o Rent a vehicle by specifying the vehicle ID and the number of hours.
o Display the rental details, including the total cost.
10.
a. Check that given number is Armstrong or not.Eg-153=1 +5 +3 =1+225+27=153
3 3 3
b.Write a Java program to check whether two strings are anagram or not?
RACE and CARE are anagram strings.
c. Take two DOB in string format from user .Compare it and display the
messages as “Younger”, ”Elder” or “Same age”.
11. a. Write a program to create and traverse (or iterate) ArrayList using for-loop,
12. a. Create arrayList, add the integer elements in arrayList using asList().Remove
the duplicate values and return a arrayList containing unique values. Implement the
logic inside removeDuplicates() method. Test the functionalities using the main ()
method of the Tester class. Sample Input and Output---------10, 20, 10, 15,40,15,40 ---
10,20,15,40
b. Given two lists, concatenate the second list in reverse order to the end of the first
list and return the concatenated list. Implement the logic inside concatenateLists()
method. listOne = Hello 102 200.8 25 listTwo = 150 40.8 welcome A output: Hello
102 200.8 25 A welcome 40.8 150
16) . Write a Java Program to iterate ArrayList using for-loop, iterator, and advance for-loop. Insert 3
Array List.Input 20 30 40Output:
iterator Loop:
20
30
40
Advanced For Loop:
20
30
40
For Loop:
20
30
40
17) Write a program to implement following inheritance. Accept data for 5 persons and display
the name of employee having salary greater than 5000.
18) 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.
19) Write a Java Program to count the number of words in a string using HashMap.
Output:
Input :Enter String: "This this is is done by Saket Saket";
{Saket=2, by=1, this=1, This=1, is=2, done=1}
20)
*
***
*****
*******
*********
***********
*************
***********
*********
*******
*****
***
*
*
* * * *
21) We have to calculate the percentage of marks obtained in three subjects (each out
of 100) by student A and in four subjects (each out of 100) by student B. Create an
abstract class 'Marks' with an abstract method 'getPercentage'. It is inherited by two
other classes 'A' and 'B' each having a method with the same name which returns the
percentage of the students. The constructor of student A takes the marks in three
subjects as its parameters and the marks in four subjects as its parameters for student
B. Create an object for eac of the two classes and print the percentage of marks for
both the students.
3) Write a Java program to find the common elements between two arrays of integers.
23) a) Write a Java program to segregate all 0s on left side and all 1s on right side
of a given array of 0s and 1s.
b) Write a Java program to segregate all 0s on left side and all 1s on right side of a
given array of 0s and 1s.
24) a) Write a Java Program to find the highest number and lowest number in an array.
b) Calculate and return the sum of all the even numbers present in the
numbers array passed to the method calculateSumOfEvenNumbers.
Implement the logic inside calculateSumOfE venNumbers() method.Test
the functionalities using the main() method of the Tester class.
25) a) Write a Java program to create a class known as Person with methods called
getFirstName() and getLastName(). Create a subclass called Employee that adds a new method
named getEmployeeId() and overrides the getLastName() method to include the employee's job
title.