NewWorksheet (Long answer questions)
Subject: Computer Applications. Class:X
Chapter name: Library classes
1. Write a program to accept a character and check the case, upper or lower, otherwise check whether it
is a digit or special character.
2. Write a program to enter a letter. Change the case of the input letter and display the new letter and its
ASCII code.
3. Write a program in Java to access a set of any 10 characters. Calculate and print the sum of ASCII codes
of the characters.
4. Write a program in Java to input ‘n’ number of uppercase or lowercase letters. Find and display the
number of uppercase and lowercase letters. Assume that none of the characters is a digit or special
character.
5. Write a program in Java to print letters from A to Z along with their numeric values from 1 to 26
respectively.
6. Write a program in Java to display the uppercase letters along with their equivalent lowercase letters
side-by-side in two different columns.
7. Write a program in java to generate following pattern:
A
AB
ABC
ABCD
ABCDE
8. Write a program in java to generate following pattern:
A
BB
CCC
DDDD
EEEEEE
9. Write a program in java to generate following pattern:
1
12
123
1234
12345
Chapter name: User-Defined methods
1. Write a class with the method name volume using function overloading that computes and invokes the
volume of a cube, a sphere and a cuboid.
Formula: volume of a cube (vc) = s*s*s
volume of a sphere (vs) = 4/3 * ∏*r*r*r
volume of a cuboid (vcd) = l*b*h
2. Define a class to overload the method display( ) as follows:
void display( ): To print the following format using nested loop.
12345
12345
12345
void display(int n, int m) : To print the addition of m and n if m is greater
than n otherwise print the sum of twice n and thrice m.
double display(double a, double b, double c) : to print the value of z where
z=pxq
p = a*b and q = a+b+c
3. Write a program to accept a number and check whether number is prime or not. Use the function name as
check (int n), the function returns 1, if the number is prime otherwise, it returns 0.
4. Write a program to accept a number and check whether the number is palindrome or not by using the
method name reverse (int n). The method returns the reversed number to the main program that checks the
palindrome number.
5. Design a class to overload a function num_cal( ) as follows:
(i) void num_cal (int num, char ch) with one integer argument and one character [Link] computes
the square of an integer if choice ch is ‘s’ otherwise , computes its cube.
(ii) void num_cal (int a, int b, char ch) with two integer arguments and one character argument. It
computes the product of integer if choice ch is ‘p’ else adds the integers.
(iii) void num_cal (String str1, String str2) with two string arguments prints whether two strings are
equal or not.
6. Design a class to overload a function area ( ) as follows:
(i) 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
(ii) double area( int a , int b, int height) with three integer arguments , returns the area of a trapezium
using the formula :
Area = ½ * height *(a+b)
(iii) double area( double d1 , double d2) with two double arguments , returns the area of a rhombus
using the formula :
Area = ½ * (d1*d2)
7. Design a class to overload a method Number ( ) as follows:
(i) Void Number (int num, int d): To count and display the frequency of a digit in a number.
(ii) Void Number (int n): To find and display the sum of even digits in a number.
8. Write a class with name perimeter using function overloading that computes perimeter of square, rectangle
and circle.
Perimeter of square = 4*s
Perimeter of square = 2*(l+b)
Perimeter of square = 2*22/7*r
10. Design a class to overload a method volume( ) as follows:
(i) double volume(double r): returns volume of sphere
V = 4/3*22/7*r*r*r
(ii) double volume(double h, double r): returns volume of cylinder
V = 22/7*r*r*h
(iii) double volume(double l, double b, double h): returns volume of cuboid
V = l*b*h
11. Define a class to overload the function print( ) as follows:
(a) void print( ) : to print following format :
11111
22222
33333
44444
(b) print(int n ) to check whether the number is a lead number or not. A lead number is the one whose
sum of even digits is equal to sum of odd digits.
Chapter name: Arrays (single and double dimensional)
1. Write a program to accept 5 different numbers in a single dimensional array (SDA). Arrange the
numbers in ascending order by using ‘Selection Sort’ technique and display them.
2. 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. [2, 8, 11, 16, 20, 52]
3. Write a program to accept 10 different numbers in a single dimensional array. Now, enter a number
and search whether the number is present or not in the list of array elements by using linear search
technique.
4. Write a program to accept 5 different numbers in a single dimensional array (SDA). Arrange the
numbers in ascending order by using ‘bubble Sort’ technique and display them.
5. Write a program to accept 5 different numbers in a single dimensional array. Display the greatest and
smallest numbers of the array elements.
6. Write a program to accept 20 different numbers in a single dimensional array .Display the sum of all
the numbers which are divisible by either 3 or 5.
7. Write a program to accept values in integer array of size 10. Find the sum of one digit and sum of two
digit numbers entered. Display the sum separately.
8. Write a program in java to store the numbers in 3*4 matrix in a double dimensional array. Find the
sum of all the numbers of the matrix and display the sum.
9. Write a program in java to store the numbers in 3*4 matrix in a double dimensional array. Find the
highest and lowest numbers of the matrix and display them.
[Link] a program in java to store the numbers in 4*4 matrix in a double dimensional array. Find the
sum of numbers of each row and sum of numbers of each column of matrix by using input statement.
[Link] a program in java to store the numbers in 4*4 matrix in a double dimensional array. Find the
transpose of the matrix by using input statement. The transpose of a matrix is obtained when we
change the row elements into column and columns into rows.
[Link] a program in java to store the numbers in 4*4 matrix in a double dimensional array. Find the
sum of numbers of the left diagonal and sum of numbers right diagonal of the matrix by using input
statement.
Chapter name: String handling
1. Write a program to accept 10 different city names in a single dimensional array. Arrange the names
in a ascending order by using the Bubble sort technique and compareTo string handling function, display
them. Sample input: Delhi, Bengaluru, Agra, Mumbai, Kolkata
Sample input: Agra, Bengaluru, Delhi, Kolkata, Mumbai
2. Define a class to accept a String and print the number of digits, alphabets and special
characters in the string. Example:S = “KAPILDEV@83”
Output: Number of digits – 2, Number of Alphabets – 8, Number of Special characters – 1
3. Write a program in java to accept a word and check whether the word is palindrome or not
Sample Input: Enter a word: madam; Sample output: Palindrome
(A word is said to be Palindrome, if it reads same after reversing the letters)
4. Write a program to accept a string. Count and display the number of vowels present in the string.
5. Write a program to accept a string and change the case of each letter of [Link] the new string.
6. Write a program in java to accept a sentence in lower case. Convert first letter of each word
Of the sentence in uppercase. Display the sentence so formed.
7. Define a class to accept 10 characters (lower case/upper case) from the user in array. Using bubble sort
technique, arrange them in ascending order. Display the sorted array and original array.
Sample input: {‘c’, ‘p’, ‘d’,’a’, ‘k’, ‘g’} Sample output: {a,c,d,g,k,p}
8. Define a class to declare an array to accept and store ten names/words. Display only those names which
begin with letter ‘A’ or ‘a’ and end with letter ‘A’ or ‘a’.
9. Write a program to input a sentence and convert it into uppercase and count and display the total number
of words starting with a letter 'A'. Example:
Sample Input: ADVANCEMENT AND APPLICATION OF INFORMATION TECHNOLOGY ARE EVER CHANGING.
Sample Output: Total number of words starting with letter 'A' = 4.
10. Sam designs a program to check the strength of a password. A strong password should satisfy the following
conditions: →length of the password should be atleast 12 characters
→should atleast have 4 upper case letters, 4 lower case letters, 2 digits, 2 special characters
Define a class accept the password and check whether the password is strong or not.
Chapter name: Class as basis of all computation
1. Define a class named CloudStorage with the following specifications:
Member Variables: - int acno - stores the user's account number. - int space - stores the amount of
storage space in GB purchased by the user. - double bill - stores the total price to be paid by the user.
Member Methods: - void accept() - prompts the user to input their account number and storage space
using Scanner class methods only.
void calculate() - calculates the bill total price based on the storage space purchased using the pricing
table provided: Storage range Price per GB (Rs) First 15 GB Next 15 GB Above 30 GB 15 13 11 –
void display() - displays the account number, storage space and bill to be paid.
Write a main method to create an object of the class and invoke the methods of the class with respect to
the object.
2. 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.
3. Define a class named MovieMagic with following description:
Class name : MovieMagic
instance variables:
int year : to store year of release of movie
String title : to store title of movie
float rating = to store popularity rating of movie
member methods:
(i) MovieMagic( ) : Default constructor to initialize numeric data to 0 and string data to “ ”
(ii) Void accept( ): to input and store year , title and rating.
(iii) Void display( ): to display the title of movie and a message based on rating as below
Rating Message to be displayed
0.0 to 2.0 Flop
2.1 to 3.4 Semi-hit
3.5 to 4.5 hit
4.6 to 5.0 Super hit
Write main method to create an object of class and call above member methods.
4. A private Cab service company provides service within the city at the following rates:
AC CAR NON AC CAR
UPTO 5 KM ₹ 150 /- ₹ 120 /-
BEYOND 5 KM ₹ 10/-PER KM ₹ 08/- PER KM
Design a class CabService with the following description:
Member variables /data members:
String car_type - To store the type of car (AC or NON AC)
double km - To store the kilometer travelled
double bill - To calculate and store the bill amount
Member methods :
CabService( ) - Default constructor to initialize data [Link] data members to NULL; and
double data members to 0.0.
void accept ( ) - To accept car_type and km (using Scanner class only).
void calculate ( ) - To calculate the bill as per the rules given above.
void display( ) - To display CAR TYPE,KILOMETER TRAVELLED,TOTAL BILL:
Create an object of the class in the main method and invoke the member methods.
Short answer model questions
(Library classes, Arrays - single and double dimensional, User-Defined methods,String handling)
1. Given int m[ ] = {5,55,9,3,9,24};
find q = m[2] + m[4] +m[0];
2. State the datatype and value of y after following is executed:
char x = ‘6’;
y = [Link](x);
3. Find the output of following program snippet:
char c = ‘B’;
int n = (int) c +32;
[Link] ((char)n);
4. Give output of following.
for(int i = 1;i<=3;i++){
for(int y=0;y<=3;y++){
[Link] (“Ramadevi school”);
}}
5. State the values of n and ch.
char c = ‘B’;
int n = c+1;
char ch = (char)n;
6. Give output of following.
for(int i = 1;i<=2;i++){
for(int y=0;y<=4;y++){
[Link] (“Artificial Intelligence”);
}}
7. Find output:
String s = “7”;
int t = [Link](s);
t = t+1000;
[Link](t);
8. Predict output:
for(int x= 1;x<=12;x++){
if(n%x == 0)
[Link] (“Artificial Intelligence”) ;}
9. Given int m[ ] = {1,2,3,4,5,6,7,8,9,10};
Find p = [Link];
find q = m[2+1] + m[7] *m[0] + m[8];
10. Predict output
String s = “1001”;
int x = [Link](s);
Double y = [Link](s);
[Link] (x);
[Link] (y);
11. The following code to compare two strings is compiled, the following syntax error was displayed –
incompatible types – int cannot be converted to boolean. Identify the statement which has the error and write
the correct statement. Give the output of the program segment.
void calculate( ) {
String a = "KING", b = "KINGDOM";
boolean x = [Link](b);
[Link](x); }
12. Evaluate the expression when the value of x = 4: x * = - - x + x++ + x.
13. Convert the following do…while loop to for loop:
int x=10;
do { x– –;
[Link](x);
}
while (x>=1);
14. Give the output of the following String class methods:
(a) "COMMENCEMENT" . lastIndexOf('M')
(b) "devote" . compareTo("DEVOTE")
15. Give the output of the following program segment and specify how many times the loop is executed.
String s = “JAVA”;
for(i=0;i< [Link]();i+=2)
[Link]([Link](i));
16. Write the output of the following String method:
String x= “ talent” ; String y=”matrix” ;
[Link]([Link](3).concat([Link](3))) ;
17. Write a Java expression for the following: | x2+2xy |.
18. Write the output for the following:
String s1 = ''phoenix''; String s2 =''island'' ;
[Link] ([Link](0).concat ([Link](2) ) );
[Link]([Link]());
19. Evaluate the following expression if the value of x=2, y=3 and z=1. v=x+ --z+ y++ +y.
20. String x[ ] = {"Artificial intelligence", "IOT", "Machine learning", "Big data"};
Give the output of the following statements:
(i) [Link](x[3]); (ii) [Link]([Link]);
21. Give the output of the following: [Link]([Link](9,16)).
22. Write the output for the following:
String s="Today is Test" ;
[Link]([Link]('T'));
[Link]([Link](0,7) + " " +"Holiday");
23. Analyze the given program segment and answer the following questions:
for(int i=3;i<=4;i++ ){
for(int j=2;j<i;j++){
[Link]("" );}
[Link]("WIN" );}
[Link] the output of the following string functions:
(i) "ACHIEVEMENT".replace('E', 'A')
(ii) "DEDICATE".compareTo("DEVOTE")
25. Give the output of the following program segment and also mention how many times the loop is executed:
int i;
for ( i = 5 ; i > 10; i ++ )
[Link]( i );
[Link]( i * 4 );