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

SampleOOP_QuestionBank

Uploaded by

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

SampleOOP_QuestionBank

Uploaded by

babelarnav92
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1.

Write an interface called “exam” with a method


boolean pass(int marks)

Write another interface called “classify” with a method


String division(int average)

Write a class called “result” which implements both interfaces .The pass method
should return true if marks is greater than 40 else false. The division method must
return divisions i.e. first, second; third, pass depending upon the average
marks(average marks calculated from 3 subjects accepted from the user).

2. WAP to create a basic registration form for a library website with all the possible
components , include minimum two buttons within the form also add action
listeners on click of the buttons.

3. Write a Java program to

i) test if an array contains a specific value.


ii) remove a specific element from an array.
iii) insert an element at specific position into an array.
iv) find the maximum and minimum value of an array.

4. Write a JAVA program to remove extra spaces between words in the string
E.g.:
I/p—Hello world welcome all
O/p—Hello world welcome all

Also calculate the number of vowels present in the sentence

5. A chemist/pharmacy needs a program to display the total amount to be paid after


the user has bought some medicines and their rates. On the user (chemist) selecting
the name of the medicines and the quantity, the amount should be calculated and
displayed. Finally output should look like:
Ex:
No. Name Rate Quantity Rupees

1. Crocin 15 10 150.00
2. Diclogem 10 5 50.00

Total : 200.00
6. Write a program to multiply the two matrices.

Check for the condition of multiplication. If the condition fails, a program should
throw an exception” Matrices cannot be multiplied” otherwise the program should
display the multiplication result.

7. WAP to accept numbers from user using command-line arguments and throw an
exception “Odd Number”,if the number entered is odd.

Keep accepting the numbers till the input encounters a ‘0’

Also find sum of all the numbers except the odd ones.

8. Write a Java program that accepts two integers via BufferedReader class
from the user and then prints the sum, the difference, the product, the
average,the maximum (the larger of the two integers), the minimum
(smaller of the two integers).

Also break both the integers into a sequence of individual digits.


Ex:
Input : 1234
Output : 1 2 3 4

9. WAP to implement two threads, (First by Thread class, second by Runnable


interface).

First thread calculates addition of 1 to n numbers, n taken from the user.

Second thread displays first 10 even numbers.

Both the threads sleep in between for 10 seconds.

Set priority of both the threads to 5 and 7 respectively.

10. WAP to create a basic registration form for a college website with all the possible
components.
11. WAP to accept a sentence from the user. Display the accepted sentence in a camel
case form.

E,g Input: java world welcomes you


Output: Java World Welcomes You

12. Write a menu driven Java program to


a) Choice 1: read a floating-point number. If the number is zero it prints "zero",
otherwise, print "positive" or "negative".
b) Choice 2: read an integer and count the number of digits the number has.
c) Choice 3: accept three numbers and print "All numbers are equal" if all three
numbers are equal, "All numbers are different" if all three numbers are
different and "Neither all are equal or different" otherwise.

13. Write a Java program to

a. find the common elements between two arrays of integers.


b. remove duplicate elements from an array.
c. find the second largest element in an array.
d. find the second smallest element in an array

14. WAP to create a basic registration form for a bank website with all the possible
components.

15. Simulate an ATM system.

a) To ask the user for the operation to be performed like,


1) Withdrawal of amount
2) Deposit of amount
3) Statement of balance.

b) In case of withdrawal, throw an exception if the amount to be removed is


greater than the balance.
16. Write a java program to check whether a string is a valid password

The rules for a valid password are :

 A password must have at least 10 characters


 It should consist of only letters and digits
 It should contain at least 2 digits
 First letter must be a capital letter

17. WAJP to do the following:


a. To print the Question “Who is the Prime Minister of India ?”
b. To accept an answer.
c. To print “Excellent” and then stop if the answer is correct.
d. To output the message “try again” if the answer is wrong through user
defined exception [this is second attempt]
e. To display the correct answer when the answer is wrong even at the third
attempt and stop.

18. Simulate an ATM system.


a) To a user , ask for the operation to be performed like,
1) Withdrawal of amount
2) Deposit of amount
3) Statement of balance.

b) In case of deposit, throw an exception if the amount to be deposited is


greater than 1, 00,000 RS.

19. Write a program to

o Define a class Telephone having instance variable name, phoneno and


pincode.
o Sort the values based on pincode.
o Write another class to display name, phoneno and pincode for 5
Telephone objects.
20. Write a program to accept a sentence. Sort the letters within the words of a
sentence in alphabetical order and display sorted order.

Also count no. of vowels and consonants in a string.

Ex:
Enter a string : welcome to java
Sorted version of string: ceelmow ot aajv (without using inbuilt method)

21. WAJP using multiple classes that checks whether two arrays have the same
elements, ignoring multiplicities.

Ex:-If one array contains 1 ,4,9,16,9,7,4,9,11 and another 11,11,7,9,16,4,1, they


have same elements otherwise not.

22. A bookshop maintains the inventory of books that are being sold at the shop. The
list includes details such as author, title, price publisher and stock position.

Whenever customer wants a book he inputs the title and author program searches
the list and displays whether it if available or not.

If it is not, an appropriate message is displayed through user defined exception.


If it is then program should display the book details and request for the number of
copies required.

If the requested copies are available, the total cost of requested copies is displayed
otherwise the message “Required copies not in stock” is displayed.

Write a class book with suitable member functions and constructors.

23. Write a program to check whether an entered string is Palindrome or not(Use


String class not StringBuffer).

If the string is not a Palindrome, then a user defined exception should be thrown
“String is not a Palindrome”
24. Write a program to create a class student with Name, Id, Branch, College-Name
as data members where College-Name is a static data member.

Now count the number of students belonging to IT and Computers branch using
static members and functions.

A program should throw an exception for branches other than Computers and IT.

25. Write a program that accepts a list of five integers from the command line and
stores them in a vector. Modify the program to accomplish the following.

To add a member at a specified location in the list.


To delete a member at the end of the list.
To print the contents of the vector.WAP to accept a two
dimensional matrix from user and throw an exception if the
entered matrix is not symmetric.

(Hint : A matrix is symmetric if (a[i][j] = a[j][i] ) for all values of i and j.)

Also, find the sum of all the non diagonal elements if it is Symmetric.

You might also like