COMPUTER APPLICATIONS
Students must complete a minimum of 20 laboratory assignments.
EACH ASSIGNMENT SHOULD HAVE THE FOLLOWING:
1. CODE IN JAVA
2. THE OUTPUT OF THE PROGRAM
3. VARIABLE DESCRIPTION OF THE VARIABLES USED IN THE PROGRAM.
Format for variable description(sample)
Name of the Variable Data Type Purpose/description
a int To input first number
b double To input second number
Suggested List of Assignments:
1. Define a class to search for a value input by the user from the list of values given below.
If it is found display the message "Search successful", otherwise display the message
"Search element not found" using Binary search technique.
5.6, 11.5, 20.8, 35.4, 43.1, 52.4, 66.6, 78.9, 80.0, 95.5
2. Define a class to overload the function print as follows:
void print() - to print the following format
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
5 5 5 5
void print(int n) - To check whether the number is a lead number. A lead number is
the one whose sum of even digits are equal to sum of odd digits.
e.g. 3669
odd digits sum = 3 + 9 = 12
even digits sum = 6 + 6 = 12
3669 is a lead number.
3. Define a class to accept a String and print the number of digits, alphabets and special
characters in the string.
4. Example:
S = "KAPILDEV@83"
Output:
Number of digits – 2
Number of Alphabets – 8
Number of Special characters – 1
5. Write a program to input 15 integer elements in an array and sort them in ascending
order using the bubble sort technique.
6. Write a program to input a number and check and print whether it is a Pronic number or
not. (Pronic number is the number which is the product of two consecutive integers)
Examples:
12 = 3 x 4
20 = 4 x 5
42 = 6 x 7
7. Write a program in Java to accept a string in lower case and change the first letter of
every word to upper case. Display the new string.
Sample input: we are in cyber world
Sample output: We Are In Cyber World
8. Design a class to overload a function volume() as follows:
double volume (double R) – with radius (R) as an argument, returns the volume of
sphere using the formula.
V = 4/3 x 22/7 x R3
double volume (double H, double R) – with height(H) and radius(R) as the arguments,
returns the volume of a cylinder using the formula.
V = 22/7 x R2 x H
double volume (double L, double B, double H) – with length(L), breadth(B) and Height(H)
as the arguments, returns the volume of a cuboid using the formula.
V=LxBxH
9. Write a program to accept a number and check and display whether it is a spy number
or not. (A number is spy if the sum of its digits equals the product of its digits.)
Example: consider the number 1124.
Sum of the digits = 1 + 1 + 2 + 4 = 8
Product of the digits = 1 x 1 x 2 x 4 = 8
10. Write a program to input integer elements into an array of size 20 and perform the
following operations:
Display largest number from the array.
Display smallest number from the array.
Display sum of all the elements of the array
11. Design a class to overload a function area( ) as follows:
double area (double a, double b, double c) with three double arguments, returns the
area of a scalene triangle using the formula:
area = √(s(s-a)(s-b)(s-c))
where s = (a+b+c) / 2
double area (int a, int b, int height) with three integer arguments, returns the area of a
trapezium using the formula:
area = (1/2)height(a + b)
double area (double diagonal1, double diagonal2) with two double arguments, returns
the area of a rhombus using the formula:
area = 1/2(diagonal1 x diagonal2)
12. Write a program to perform binary search on a list of integers given below, to search for
an element input by the user. If it is found display the element along with its position,
otherwise display the message "Search element not found".
5, 7, 9, 11, 15, 20, 30, 45, 89, 97
13. Define a class to accept a string and convert the same to uppercase, create and display
the new string by replacing each vowel by immediate next character and every
consonant by the previous character. The other characters remain the same.
Example:
Input : #IMAGINATION@2024
Output : #JLBFJMBSJPM@2024
14. Define a class named FruitJuice with the following description:
instance variables/Data Members
int product_code: stores the product code number
String flavour: stores the flavour of the juice (e.g., orange, apple, etc.)
String pack_type: stores the type of packaging (e.g., tera-pack, PET bottle, etc.)
int pack_size: stores package size (e.g., 200 mL, 400 mL, etc.)
int product_price: stores the price of the product
Member Methods, Purpose
FruitJuice(): constructor to initialise integer data members to 0 and string data
members to " "
void input (): to input and store the product code, flavour, pack type, pack size and
product price
void discount (): to reduce the product price by 10
void display (): to display the product code, flavour, pack type, pack size and product
price
15. Define a class Student as given below:
Data members/instance variables:
name, age, m1, m2, m3 (marks in 3 subjects), maximum, average
Member methods:
A parameterized constructor to initialize the data members.
To accept the details of a student.
To compute the average and the maximum out of three marks.
To display the name, age, marks in three subjects, maximum and average.
Write a main method to create an object of a class and call the above member methods.
16. Write a program to input a string. Calculate the total number of characters and vowels
present in the string and also reverse the string.
17. Write a program to input a sentence from the user and count the number of letters and
spaces present in it.
18. Write a program to search for an element in an array using binary search.
19. Write a program to search for an element in an array using linear search.
20. Define a class to accept values in integer array of size 10. Sort them in an ascending
order using selection sort technique. Display the sorted array.
21. Define a class to accept a string and convert it into uppercase. Count and display the
number of vowels in it.
Input: robotics
Output: ROBOTICS
Number of vowels: 3
22. Define a class to accept values into 4x4 array and find and display the sum of each row.
Example:
A[][]={{1,2,3,4},{5,6,7,8},{1,3,5,7},{2,5,3,1}}
Output:
sum of row 1 = 10
sum of row 2 = 26
sum of row 3 = 16
sum of row 4 = 11
23. Write a menu driven program to display the pattern as per the user’s choice.
Pattern 1
ABCDE
ABCD
ABC
AB
A
Pattern 2
B
LL
UUU
EEEE
For an incorrect option, an appropriate error message should be displayed.
24. Write a program to accept a number and check and display whether it is a Niven
number or not.
(Niven number is that number which is divisible by its sum of digits.).
Example:
Consider the number 126. The sum of its digits is 1 + 2 + 6 = 9 and 126 is divisible by 9.
25. Define a class to accept a number and check whether it is a SUPERSPY number or not. A
number is called SUPERSPY if the sum of the digits equals the number of the digits.
Example:
Input: 1021
output: SUPERSPY number [SUM OF THE DIGITS = 1+0+2+1 = 4,
NUMBER OF DIGITS = 4
26. Design a class with the following specifications:
Class name: Student
Member variables:
name — name of student
age — age of student
mks — marks obtained
stream — stream allocated
(Declare the variables using appropriate data types)
Member methods:
void accept() — Accept name, age and marks using methods of Scanner class.
void allocation() — Allocate the stream as per following criteria:
mks, stream
>= 300, Science and Computer
>= 200 and < 300, Commerce and Computer
>= 75 and < 200, Arts and Animation
< 75, Try Again
void print() – Display student name, age, mks and stream allocated.
Call all the above methods in main method using an object.