[go: up one dir, main page]

0% found this document useful (0 votes)
6 views12 pages

23-24 Sem1 OOP Lab Problem Stmt CSAB

The document outlines various tasks for creating Java applications, including designing a library management system with class inheritance, implementing string and array operations, creating a banking system with exception handling, and developing a vehicle rental system. It also includes requirements for managing student data, calculating percentages, and handling exceptions, as well as various programming challenges involving data structures like ArrayLists and HashMaps. Each task emphasizes object-oriented programming principles and practical implementations of Java features.

Uploaded by

nikhilyt93
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views12 pages

23-24 Sem1 OOP Lab Problem Stmt CSAB

The document outlines various tasks for creating Java applications, including designing a library management system with class inheritance, implementing string and array operations, creating a banking system with exception handling, and developing a vehicle rental system. It also includes requirements for managing student data, calculating percentages, and handling exceptions, as well as various programming challenges involving data structures like ArrayLists and HashMaps. Each task emphasizes object-oriented programming principles and practical implementations of Java features.

Uploaded by

nikhilyt93
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

1 . 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

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,

iterator, and advance for-loop.

b. check if element(value) exists in ArrayList?

c. add element at particular index of ArrayList?

d. remove element at particular index of ArrayList?

e. sort a given array list.(collections.sort())

f. reverse elements in an array list.

g. compare two array lists.

h. find first and last occurrence of repeated element.

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

13.a) Implement the method findNumbers 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
number is a multiple of 5 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.

14) A Company manufactures Vehicles, which could be a Helicopter, a Car,


or a Train depending on the customer’s demand. Each Vehicle instance
has a method called move, which prints on the console the nature of
movement of the vehicle. For example, the Helicopter Flies in Air, the Car
Drives on Road and the Train Runs on Track. Write a program that
accepts input from the user on the kind of vehicle the user wants to order,
and the system should print out nature of movement. Implement all Java
coding best practices to implement this program.
15) You are required to compute the power of a number by implementing
a calculator. Create a class My Calculator which consists of a single
method long power (int, int). This method takes two integers n and p, as
parameters and finds (n)p. If either or is negative, then the method must
throw an exception which says " n or p should not be negative”. Also, if
both and are zero, then the method must throw an exception which says
"n or p should not be negative”.

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.

Class Name: Person


Member variables:
Name, age

Class Name: Employee


Member variables:
Designation, salary

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)

a) Write a Java program to display the pattern like a diamond.


Input number of rows (half of the diamond) :7 Expected Output :

*
***
*****
*******
*********
***********
*************
***********
*********
*******
*****
***
*

B ) Display the letter L in star pattern.

*
* * * *

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.

22) 1) Java Program to Count Number of Duplicate Words in String

.2) How to Check if the String Contains 'e' in umbrella

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.

b) Write a java program to check that given number is prime or not.

26) Write a java program for calculator


27) Write a java program for display the result .

You might also like