COMPUTER APPLICATIONS
(Theory)
(Two hours)
Answers to this paper must be written on the paper provided separately.
You will not be allowed to write during the first 15 minutes.
This time is to be spent in reading the question paper.
The time given at the head of this paper is the time allowed for writing the answers.
This paper is divided into two sections.
Attempt all questions from Section A and any four questions from Section B.
The intended marks for questions or parts of questions are given in brackets [ ].
SECTION A (40 Marks)
Attempt all questions from this section.
Question 1
(a) Define Unicode.
Unicode is the character encoding system used in the Java language.
(b) Identify the following conversions as Autoboxing or Unboxing:
(i) Conversion of an Integer to an int.
Unboxing
(ii) Conversion of an int to an Integer.
Autoboxing
(c) Name the following literals:
(i) “ICSE”
String literal
(ii) ‘+’
Character literal
(iii) 254
Integer literal
(iv) false
Boolean literal
(d) Mention the two types of comments used in Java.
Single line comments
Multiline comments
(e) Rewrite the following using for loop:
int x = 10, y = 5;
do{
x++;
y--;
}while(x <= 15);
System.out.println(x + y);
int x = 10, y = 5;
for(; x <= 15; x++)
y--;
System.out.println(x + y);
Question 2
(a) Name the following:
(i) Parameters present in the method call statement.
Actual parameters
(ii) Smallest individual unit of a program.
Tokens
(b) State the purpose of the following methods:
(i) compareToIgnoreCase()
To compare two strings lexicographically while ignoring case differences.
(ii) trim()
To return a copy of the given string, with leading and trailing whitespaces omitted.
(c) What is a constructor?
A constructor is a special type of method that is used to create an object of a class. It doesn’t have any return type, not even void.
(d) Write a prototype of the method show() which receives a string and an integer as arguments and returns a character.
public char show(String s, int i)
(e) State the output of the following program segment:
int n = 47389, d;
while(n > 10){
d = n % 10;
System.out.println(d);
n = n / 100;
}
System.out.println(n);
9
3
4
Question 3
(a) Differentiate between the methods indexOf() and lastIndexOf().
The indexOf() method returns the index of the first occurrence of a character in the given string. The lastIndexOf() method returns the index of the last occurrence of a character in the given string.
(b) What is the value of y after evaluating the expression given below?
y += ++y + –y + y–; when int y = 5;
y = y + (++y + –y + y–)
y = 5 + (6 + 5 + 5)
y = 5 + 16
y = 21
(c) Give the output of the following statements:
System.out.println("Good".concat("Day"));
System.out.println("MERRYWORLD".substring(0, 5));
System.out.println("My_dream".length());
System.out.println("Memory".startsWith("Me"));
GoodDay
MERRY
8
true
(d) Write the output of the following statements:
System.out.println("result 1 = " + 6 + 2);
System.out.println("result 2 = " + (6 + 2));
result 1 = 62
result 2 = 8
(e) Write the return data type of the following methods of Character class:
(i) isLetter()
boolean
(ii) toUpperCase()
char
(f) Predict the output of the following:
(i) Math.sqrt(196) + Math.pow(49, 0.5);
21.0
(ii) Math.floor(17.9) + Math.ceil(-17.5);
0.0
(g) What will be the output when the following code segment is executed?
int x = 5;
char ch = ‘C’;
int y = ch + 5;
System.out.println(y + ” ” + (char)y);
72 H
(h) What is the value of x and y in the following statements?
int a = 63, b = 36;
(i) boolean x = (a < b)? true : false;
x = false
(ii) int y = (a < b)? a : b;
y = 36
(i) What are library classes? Give an example.
The library classes are the in-built classes that contain useful methods to perform a certain task. Example: Integer class.
(j) Write a Java expression for the following:

(a * x * x + b * y) / (2 * a * b)
SECTION B (60 Marks)
Attempt any four questions from this section.
The answers in this section should consist of the programs in either BlueJ environment or any program environment with Java as the base.
Each program should be written using variable descriptions/mnemonic codes so that the logic of the program is clearly depicted.
Flowcharts and algorithms are not required.
Question 4
Design a class Hotel with the following description:
Member variables:
String name – to store the name of the customer
long mno – to store the mobile number of the customer
double bill – to store the bill amount
double gst – to store the GST amount
double st – to store the service tax
double tamt – to store the total amount to be paid by the customer
Member methods:
void accept() – to accept customer’s name, mobile number and bill amount.
void calculate() – to calculate GST, service tax and total amount to be paid by the customer.
gst = 18% on bill
st = 12.5% on bill
tamt = bill + gst + st
void display() – to display the customer’s name, mobile number, GST, service tax and total amount.
Write a main() method to create an object and invoke the above member methods.
import java.util.Scanner;
class Hotel{
String name;
long mno;
double bill;
double gst;
double st;
double tamt;
public void accept(){
Scanner in = new Scanner(System.in);
System.out.print("Customer name: ");
name = in.nextLine();
System.out.print("Mobile number: ");
mno = Long.parseLong(in.nextLine());
System.out.print("Bill: ");
bill = Double.parseDouble(in.nextLine());
}
public void calculate(){
gst = 18.0 / 100 * bill;
st = 12.5 / 100 * bill;
tamt = bill + gst + st;
}
public void display(){
System.out.println("Customer's name: " + name);
System.out.println("Mobile number: " + mno);
System.out.println("GST: " + gst);
System.out.println("Service tax: " + st);
System.out.println("Total amount: " + tamt);
}
public static void main(String[] args){
Hotel obj = new Hotel();
obj.accept();
obj.calculate();
obj.display();
}
}
Question 5
Write a program to input n number of integer elements in an array and sort them in descending order using bubble sort technique and print the sorted list.
import java.util.Scanner;
class Bubble{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.print("N = ");
int n = Integer.parseInt(in.nextLine());
int a[] = new int[n];
System.out.println("Enter integers:");
for(int i = 0; i < a.length; i++)
a[i] = Integer.parseInt(in.nextLine());
for(int i = 0; i < a.length; i++){
for(int j = 0; j < a.length - 1 - i; j++){
if(a[j] < a[j + 1]){
int temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
System.out.println("List in descending order:");
for(int i = 0; i < a.length; i++)
System.out.print(a[i] + " ");
System.out.println();
}
}
Question 6
Write a menu-driven program using switch case to accept a choice from the user and according to the choice entered perform the following operations:
(a) To calculate and display the area of a circle using the formula:
Area = (π × radius2) where π = 22 / 7
(b) To calculate and display the area of a rectangle using the formula:
Area = (length × breadth)
(c) To calculate and display the area of a triangle using the formula:
Area = 1 / 2 × base × height
(d) To calculate and display the area of a square using the formula:
Area = side2
For an incorrect option, an appropriate error message should be displayed.
import java.util.Scanner;
class Menu{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.println("1. Area of circle");
System.out.println("2. Area of rectangle");
System.out.println("3. Area of triangle");
System.out.println("4. Area of square");
System.out.print("Enter your choice: ");
int choice = Integer.parseInt(in.nextLine());
switch(choice){
case 1:
System.out.print("Radius = ");
double r = Double.parseDouble(in.nextLine());
double a = 22.0 / 7 * r * r;
System.out.println("Area = " + a);
break;
case 2:
System.out.print("Length = ");
double l = Double.parseDouble(in.nextLine());
System.out.print("Breadth = ");
double b = Double.parseDouble(in.nextLine());
a = l * b;
System.out.println("Area = " + a);
break;
case 3:
System.out.print("Base = ");
b = Double.parseDouble(in.nextLine());
System.out.print("Height = ");
double h = Double.parseDouble(in.nextLine());
a = 1.0 / 2 * b * h;
System.out.println("Area = " + a);
break;
case 4:
System.out.print("Side = ");
double s = Double.parseDouble(in.nextLine());
a = s * s;
System.out.println("Area = " + a);
break;
default:
System.out.println("Invalid choice!");
}
}
}
Question 7
Design a class to overload a method called pattSeries() as follows:
(a) void pattSeries() – To generate and display the pattern given below:
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1
(b) void pattSeries(int n) – To find and display the sum of the series given below:
![]()
Write a main() method to create an object of the class and call the above member methods.
class Overload{
public void pattSeries(){
for(int i = 5; i >= 1; i--){
for(int j = i; j >= 1; j--)
System.out.print(j + " ");
System.out.println();
}
}
public void pattSeries(int n){
double sum = 0.0;
for(int i = 1; i <= n; i++)
sum += i / (i + 2.0);
System.out.println("Sum = " + sum);
}
public static void main(String[] args){
Overload obj = new Overload();
obj.pattSeries();
obj.pattSeries(5);
}
}
Question 8
Write a program to input a number and check and print whether it is an EvenPal number or not.
The number is said to be an EvenPal number when the number is a palindrome number and the sum of its digits is an even number.
Example:
Number 121 is a palindrome number and the sum of its digits is 1 + 2 + 1 = 4, which is an even number.
Therefore, 121 is an EvenPal number.
import java.util.Scanner;
class EvenPal{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.print("Enter the number: ");
int num = Integer.parseInt(in.nextLine());
int rev = 0;
int sum = 0;
for(int i = num; i != 0; i /= 10){
rev = rev * 10 + i % 10;
sum += i % 10;
}
if(num == rev && sum % 2 == 0)
System.out.println(num + " is EvenPal");
else
System.out.println(num + " is not EvenPal");
}
}
Question 9
A list contains marks in the subject Computer Applications for ‘N’ number of students. Write a program to create an array of size ‘N’ and store the marks. Check and print the number of students falling into the different ranges given below:
100 – 80
79 – 60
59 – 40
39 – 20
19 – 0
import java.util.Scanner;
class Ranges{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.print("N = ");
int n = Integer.parseInt(in.nextLine());
int a[] = new int[n];
int r[] = new int[5];
System.out.println("Enter marks:");
for(int i = 0; i < a.length; i++){
a[i] = Integer.parseInt(in.nextLine());
if(a[i] >= 80 && a[i] <= 100)
r[0]++;
else if(a[i] >= 60 && a[i] <= 79)
r[1]++;
else if(a[i] >= 40 && a[i] <= 59)
r[2]++;
else if(a[i] >= 20 && a[i] <= 39)
r[3]++;
else if(a[i] >= 0 && a[i] <= 19)
r[4]++;
}
System.out.println("100 - 80: " + r[0]);
System.out.println("79 - 60: " + r[1]);
System.out.println("59 - 40: " + r[2]);
System.out.println("39 - 20: " + r[3]);
System.out.println("19 - 0: " + r[4]);
}
}