0% found this document useful (0 votes)
43 views110 pages

Computer ScienceCOMPLETE ICSE

This document outlines the Computer Applications examination for the CISCE academic year 2023-2024, scheduled for March 13, 2024. It includes instructions for answering the paper, details about the two sections, and various questions covering Java programming concepts, data types, and class definitions. The document also specifies the marks distribution and types of questions to be attempted.

Uploaded by

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

Computer ScienceCOMPLETE ICSE

This document outlines the Computer Applications examination for the CISCE academic year 2023-2024, scheduled for March 13, 2024. It includes instructions for answering the paper, details about the two sections, and various questions covering Java programming concepts, data types, and class definitions. The document also specifies the marks distribution and types of questions to be attempted.

Uploaded by

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

Computer Applications

CISCE
Academic Year: 2023-2024
(English Medium)
Date & Time: 13th March 2024, 11:00 am

Duration: 2h Marks: 100


1. Answers to this Paper must be written on the paper provided separately.
2. You will not be allowed to write during the first 15 minutes.
3. This time is to be spent reading the question paper.
4. The time given at the head of this Paper is the time allowed for writing the ans
wers.
5. This Paper is divided into two Sections.
6. Attempt all questions from Section A and any four questions from Section B.
7. The intended marks for questions or parts of questions are given in brackets [].

SECTION-A (40 Marks) (Attempt all questions from this Section.)

Q1. Choose the correct answers to the questions from the given options. (Do not copy
the questions, write the correct answer only.)

1.1. Consider the above picture and choose the correct statement from the following:

1. Polygon is the object and the pictures are classes

2. Both polygon and the pictures are classes

3. Polygon is the class and the pictures are objects

4. Both polygon and the pictures are objects

Solution

Polygon is the class, and the pictures are objects

Explanation:

The class is a polygon, and its types include triangle, parallelogram, and pentagon. As
a result, they fall under the Polygon class.
1.2. int x = 98; char ch = (char)x; what is the value in ch?

1. b

2. A

3. B

4. 97

Solution

Explanation:

'A' has an ASCII value of 97; hence, ' B' has an ASCII value of 98.

1.3. The output of the statement "CONCENTRATION" indexOf('T') is ______.

1. 9

2. 7

3. 6

4. (-1)

Solution

The output of the statement "CONCENTRATION" indexOf('T') is 6.

Explanation:

The index position of 'T' in "CONCENTRATION" is 6.

1.4. The access specifier that gives least accessibility is ______.

1. Package

2. Public

3. Protected

4. Private

Solution

The access specifier that gives least accessibility is private.

Explanation:
The private access specifier restricts access to the class solely, providing the least
amount of accessibility.

1.5. The output of the statement "talent". compareTo("genius") is ______.

1. 11

2. -11

3. 0

4. 13

Solution

The output of the statement "talent". compareTo("genius") is 13.

Explanation:

ASCII value of 't' - ASCII value of 'g' = 116 − 103 = 13.

1.6. Which of the following is an escape sequence character in Java?

1. /n

2. \t

3. /t

4. //n

Solution

\t

Explanation:

Every other option is incorrect.

1.7. If (a>b&&b>c) then largest number is ______.

1. b

2. c

3. a

4. Wrong expression

Solution
If (a>b&&b>c) then largest number is a.

Explanation:

a is greater than b, and b is greater than c, so a is the greatest.

1.8. What is the output of Math.ceil(5.4) + Math.ceil(4.5)?

1. 10.0

2. 11.0

3. 12.0

4. 9.0

Solution

11.0

Explanation:

Mathi.ceil() returns the next higher number. (6.0 + 5.0).

1.9. What is the method to check whether a character is a letter or digit?

1. isDigif(char)

2. isLetterOrDigit()

3. isLetterOrDigit(char)

4. isLETTERorDIGIT(char)

Solution

isLetterOrDigit(char)

Explanation:

isLetterOrDigit() determines whether a character is a letter, digit, or none of the


above.

1.10. The extension of a Java source code file is ______.

1. exe

2. obj

3. jvm
4. java

Solution

The extension of a Java source code file is java.

Explanation:

The source code extension is .java, bytecode extension is .obj.

1.11. The number of bytes occupied by a character array of four rows and three
columns is ______.

1. 12

2. 24

3. 96

4. 48

Solution

The number of bytes occupied by a character array of four rows and three columns
is 24.

Explanation:

• The size of the char data type is 2 bytes.

• Thus, 2 * 4 * 3 = 24.

1.12. Which of the following data type cannot be used with switch case construct?

1. int

2. char

3. String

4. Double

Solution

Double

Explanation:

• The data type double is incompatible with all versions of Java.


• There's a doubt. The string data type is also not usable in Java versions prior to
7.0, but it works in switches from 7.0 and above.

1.13. Which of the following are entry-controlled loops?

1. for 2. while

3. do..while 4. switch

1. Only 1

2. 1 and 2

3. 1 and 3

4. 3 and 4

Solution

1 and 2

Explanation:

The for loop and while loop are entry-controlled loops that check the condition before
entering the loop body.

1.14. Method which reverses a given number is ______:

1. Impure method

2. Pure method

3. Constructor

4. Destructor

Solution

Method which reverses a given number is pure method:

Explanation:

The procedure of reversing a number generates a new number that is the reverse of
the original number but does not modify the original number.

1.15. If the name of the class is "Yellow", what can be the possible name for its
constructors?

1. yellow
2. YELLOW

3. Yell

4. Yellow

Solution

Yellow

Explanation:

The constructor will have the same name as the class itself.

1.16. Invoking a method by passing the objects of a class is termed as ______.

1. Call by reference

2. Call by value

3. Call by method

4. Call by constructor

Solution

Invoking a method by passing the objects of a class is termed as Call by reference.

Explanation:

Passing an argument as an object acts as a call by reference since only one copy of
the object is shared by both the caller and the called method.

1.17. The correct statement to create an object named mango of class fruit:

1. Fruit Mango = new fruit();

2. fruit mango = new fruit();

3. Mango fruit = new Mango();

4. fruit mango = new mango();

Solution

fruit mango = new fruit();

Explanation:

The class and object names should be the same, as specified in the query.
1.18. Assertion (A): Static method can access static and instance variables.

Reason (R): Static variables can be accessed only by static method.

1. Assertion and Reason both are correct.

2. Assertion is true and Reason is false.

3. Assertion is false and Reason is true.

4. Assertion and Reason both are false.

Solution

Assertion and Reason both are false.

Explanation:

The static method can only access itself, whereas an instance variable can be
accessed through a class object. Thus, we can conclude that static methods cannot
access instance variables without the assistance of an object.

In contrast, static variables can be immediately accessed by both static and instance
methods.

1.19. What is the output of the Java code given below?

String color [ J = {"Blue", "Red", "Violet"}; System.out.println(color[2].length();

1. 6

2. 5

3. 3

4. 2

Solution

Explanation:

The array element at index position 2 i.e. color[2] is "Violet" and the number of
characters in "Violet" is 6.

1.20. Which of the following mathematical methods returns only an integer?

1. Math.ceil(n)
2. Math.sqrt(n)

3. Math.floor(n)

4. Math.round(n)

Solution

Math.round(n)

Explanation:

This method rounds up/down a supplied decimal value to a whole number. For
example, Math.round(5.5) = 6, but Math.round(5.4) = 5.

Q2.

2.1. Write Java expression for:

Solution

2.2. Evaluate the expression when x is 4:

Solution

2.3. Rewrite the following do while program segment using for:


Solution

2.4. Give the output of the following program segment. How many times is the loop
executed?

Solution

The for loop will run 0 times as the condition is false, and the loop is entry-controlled.

2.5. What is value of x?

Solution

2.6. Consider the following two-dimensional array and answer the questions given
below:

a. What is the order of the array?

b. What is the value of x [0] [0] + x [2] [2]?

Solution

a. Order of the array 4 × 3, i.e. 4 rows and 3 columns


b.

2.7. Differentiate between boxing and unboxing.

Solution

• Boxing is the process of changing a primitive datatype into an object of a


corresponding wrapper class, whereas

• Unpacking is the process of returning a wrapper class object to its primitive


state.

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

Solution

-4

Reason:

compareTo() gives the ASCII difference between the first two dissimilar characters
present in the string, but if any one of the strings ends early, then it returns the
difference of the length.

2.9. Consider the given program and answer the questions given below:
a. What concept of OOPs is depicted in the above program with two
constructors?

b. What is the output of the method main()?

Solution

a. Polymorphism. Having two constructors in a class represents constructor


overloading, which is a part of polymorphism.

b. 10
30

2.10. Primitive data types are built in data types which are a part of the wrapper
classes. These wrapper classes are encapsulated in the java.lang package. Non
primitive datatypes like Scanner class are a part of the utility package for which an
object needs to be created.
a. To which package the Character and Boolean classes belong?

b. Write the statement to access the Scanner class in the program.

Solution

a. java.lang

b.

SECTION-B (60 Marks) (Answer 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 description/mmemonic codes so that


the logic of the program is clearly depicted. Flowcharts and algorithms are not
required.

Q3. DTDC, a courier company, charges for the courier based on the weight of the
parcel. Define a class with the following specifications:

class name: courier

Member variables: name - name of the customer

weight - weight of the parcel in kilograms

address - address of the recipient

bill - amount to be paid

type - 'D'- domestic, 'I'- international

Member methods:

void accept ( )- to accept the details using the methods of the Scanner class
only.

void calculate ( )- to calculate the bill as per the following criteria:

Weight in Kgs Rate per Kg

First 5 Kgs Rs.800


Next 5 Kgs Rs.700

Above 10 Kgs Rs.500

An additional amount of Rs.1500 is charged if the type of the


courier is I (International)

void print )- To print the details

void main ()- to create an object of the class and invoke the methods

Solution
Output:

Enter the name of the customer: Alok Kumar Singh.

Enter the weight of the parcel in kilograms: 55.

Enter the address of the recipient: New Delhi.

Enter the type: D for domestic and I for international: D

Name of the customer: Alok Kumar Singh

Weight of the parcel: 55.0 kilograms

Address of the recipient: New Delhi

Type of the parcel: D

Amount to be paid: 30000.0


Q4. Define a class to overload the method perform as follows:

double perform (double r, to calculate and return the value of Curved surface
double h) area of cone CSA π rl

void perform (int r, int c) Use NESTED FOR LOOP to generate the following
format r = 4, c = 5 output -
12345
12345
12345
12345

void perform (int m, int n, to print the quotient of the division of m and n if ch is Q
char ch) else print the remainder of the division of m and n if ch
is R

Solution
Output:

12345

12345

12345

12345

12345

Q5. Define a class to accept a number from user and check if it is an EvenPal number
or not. (The number is said to be EvenPal number when number is palindrome
number (a number is palindrome if it is equal to its reverse) and sum of its digits is an
even number.)

Example: 121 - is a palindrome number

Sum of the digits - 1 + 2 + 1 = 4 which is an even number

Solution
Output:

Enter a positive number: 121

It is an EvenPal number 121

Enter a positive number: 123

It is not an EvenPal number

Q6. Define a class to accept values into an integer array of order 4 x 4 and check
whether it is a DIAGONAL array or not An array is DIAGONAL if the sum of the left
diagonal elements equals the sum of the right diagonal elements. Print the
appropriate message.

Example:

3 4 2 5 Sum of the left diagonal elements =

2 5 2 3 3 + 5 + 2 + 1 = 11

5 3 2 7 Sum of the right diagonal elements =

1 3 7 1 5 + 2 + 3 + 1 = 11

Solution
Output:

Enter the array elements

3425

2523

5327

1371

It is a DIAGONAL array
Q7. Define a class pin code and store the given pin codes in a single-dimensional
array. Sort these pin codes in ascending order using the Selection Sort technique
only. Display the sorted array.

110061, 110001, 110029, 110023, 110055, 110006, 110019, 110033

Solution

Output:

Array elements after the sorting

110001 110006 110019 110023 110029 110033 110055 110061

Q8. Define a class to accept the gmail id and check for its validity.
A gmail id is valid only if it has:

→@

→ . (dot)

→ gmail

→ com

Example: [email protected] is a valid gmail id.

Solution
Output:

Enter a valid gmail id

[email protected]

[email protected] is a valid gmail id

Enter a valid gmail id

[email protected]

[email protected] is an invalid gmail id


COMPUTER APPLICATIONS
Semester-2 (2022)
Maximum Marks: 50

Time allowed: One and a half hours

Answers to this Paper must he written on the paper provided separately.

You will not be allowed to write during the first 10 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.

Attempt all questions from Section- A and any three questions from Section- B.

The marks intended for questions are given in brackets [ ]

Section A

(Attempt all questions)

Question 1.

Choose the correct answers to the questions from the given options. (Do not copy the question. Write the correct answer only.) [10]

(i) Return data type of isLetter(char) is...

(a) Boolean (b) boolean

(c) bool (d) char

(ii) Method that converts a character to uppercase is.......

(a) toUpper()

(b) ToUpperCase()

(c) toUppercase()

(d) toUpperCase(char)

(iii) Give output of the following String methods:

“SUCESS".indexOf(‘S’)+“SUCCESS”. last IndexOft‘S’)

(a) 0 (b) 5

(c) 6 (d) -5

(iv) Corresponding wrapper class of float data type is.......

(a) FLOAT (b) float

(c) Float (d) Floating

(v) …....class is used to convert a primitive data type to its corresponding object.

(a) String (b) Wrapper

(c) System (d) Math

(vi) Give the output of the following code: System.out.println("Good”.Concat(“Day"));

(a) GoodDay (b) Good Day

(c) Goodday (d) goodDay

(vii) A single dimensional array contains N elements. What will be the last subscript?
(a) N (b) N-1

(c) N -2 (d) N+1

(viii) The access modifier that gives least accessibility is:

(a) private (b) public

(c) protected (d) package

(ix) Give the output of the following code :

String A =“56.0”, B = “94.0”;

double C = Double.parseDouble(A);

double D = Double.parseDouble(B);

System.out.println((C+D));

(a) 100 (b) 150.0

(c) 100.0 (d) 150

(x) What will be the output of the following code?

System, out. println(“Lucknow". substring (0,4));

(a) Lucknow (b) Luckn

(c) Luck (d) luck

Section-B

(Attempt any four questions from this Section.)

Question 2.

Define a class 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 is position, otherwise display the message “Search element not found”. [10]

2, 5, 7,10,15, 20, 29, 30, 46, 50

Question 3.

Define a class to declare a character array of size ten. accept the characters into the array and display the characters with highest and
lowest ASCII (American Standard Code for Information Interchange) value. [10]

EXAMPLE :

INPUT:

‘R’, ‘z’, ‘q’, ‘A’, ‘N’, ‘p’, ‘m’, ‘U’, ‘Q’, ‘F’

OUTPUT :

Character with highest ASCII value = z

Character with lowest ASCII value = A

Question 4.

Define a class to declare an array of size twenty of double datatype, accept the elements into the array and perform the following : [10]

• Calculate and print the product of all the elements.

• Print the square of each element of the array.

Question 5.

Define a class to accept a string, and print the characters with the uppercase and lowercase reversed, but all the other characters should
remain the same as before. [10]
EXAMPLE: INPUT : WelCoMe_2022

OUTPUT : wELcOmE_2022

Question 6.

Define a class to declare an array to accept and store ten words. Display only those words which begin with the letter ‘A’ or ‘a’ and also
end with the letter ‘A’ or ‘a’.

EXAMPLE :

Input : Hari, Anita, Akash, Amrita, Alina, Devi Rishab, John, Farha, AMITHA

Output: Anita

Amrita

Alina

AMITHA

Question 7.

Define a class to accept two strings of same length and form a new word in such a way that, the first character of the first word is followed
by the first character of the second word and so on. [10]

Example : Input string 1 – BALL

Input string 2 – WORD

OUTPUT : BWAOLRLD
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

Question 1.
(a) Define Java byte code. [2]

(b) Write a difference between class and an object. [2]

(c) Name the following: [2]

(i) The keyword which converts variable into constant.

(ii) The method which terminates the entire program from any stage.

(d) Which of the following are primitive data types? [2]

(i) double

(ii) String

(iii) char

(iv) Integer

(e) What is an operator? Name any two types of operators used in Java. [2]
Question 2.
(a) What is autoboxing in Java? Give an example. [2]

(b) State the difference between length and length() in Java. [2]

(c) What is constructor overloading? [2]

(d) What is the use of import statement in Java? [2]

(e) What is an infinite loop? Give an example. [2]

Question 3.
(a) Write a Java expression for the following: [2]

√𝑏 2 − 4𝑎𝑐

(b) Evaluate the following if the value of x=7, y=5 [2]

x+=x++ + x + ++y

(c) Write the output for the following: [2]

String s1 = ''Life is Beautiful'';

System.out.println (''Earth'' + s1.substring(4));

System.out.println( s1.endsWith(''L'') );

(d) Write the output of the following statement: [2]

System.out.println(''A picture is worth \t \''A thousand words.\'' '');

(e) Give the output of the following program segment and mention how many times [2]
the loop will execute:

int k;

for ( k = 5 ; k < = 20 ; k + = 7 )

if ( k% 6==0 )

continue;

System.out.println ( k );

(f) What is the data type returned by the following library methods? [2]

(i) isWhitespace()

(ii) compareToIgnoreCase()
(g) Rewrite the following program segment using logical operators: [2]

if ( x > 5 )

if ( x > y )

System.out.println (x+y);

(h) Convert the following if else if construct into switch case: [2]

if (ch== 'c' || ch=='C')

System.out . print(''COMPUTER'');

else if (ch== 'h' || ch=='H')

System.out . print(''HINDI'');

else

System.out . print(''PHYSICAL EDUCATION'');

(i) Give the output of the following: [2]

(i) Math.pow (36,0.5) + Math.cbrt (125)

(ii) Math.ceil (4.2 ) + Math.floor (7.9)

(j) Rewrite the following using ternary operator: [2]

if(n1>n2)

r = true;

else

r = false;
SECTION B (60 Marks)
Attempt any four questions from this Section.
The answers in this Section should consist of the Programs in either Blue J 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.
Flow-Charts and Algorithms are not required.

Question 4.
A private Cab service company provides service within the city at the following rates: [15]

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

String data members to '' '' 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 the bill as per the following format

CAR TYPE:

KILOMETER TRAVELLED:

TOTAL BILL:

Create an object of the class in the main method and invoke the member methods.
Question 5.

Write a program to search for an integer value input by the user in the sorted list given [15]
below using binary search technique. If found display ''Search Successful'' and print
the element, otherwise display ''Search Unsuccessful''

{31, 36, 45, 50, 60, 75, 86, 90}

Question 6.
Write a program to input a sentence and convert it into uppercase and display each [15]
word in a separate line.

Example: Input : India is my country

Output : INDIA

IS

MY

COUNTRY

Question 7.
Design a class to overload a method Number( ) as follows: [15]

(i) void Number (int num , int d) - To count and display the frequency of a
digit in a number.

Example:

num = 2565685

d=5

Frequency of digit 5 = 3

(ii) void Number (int n1) - To find and display the sum of even digits of
a number.

Example:

n1 = 29865

Sum of even digits = 16

Write a main method to create an object and invoke the above methods.
Question 8.

Write a menu driven program to perform the following operations as per user’s choice: [15]

(i) To print the value of c=a2+2ab, where a varies from 1.0 to 20.0 with increment
of 2.0 and b=3.0 is a constant.

(ii) To display the following pattern using for loop:

A
AB
ABC
ABCD
ABCDE

Display proper message for an invalid choice.

Question 9.

Write a program to input and store integer elements in a double dimensional array of [15]
size 3 x 3 and find the sum of elements in the left diagonal.

Example:

1 3 5

4 6 8

9 2 4

Output: Sum of the left diagonal elements = (1 + 6 +4) = 11


ICSE Paper 2019
Computer Applications

General Instructions :

• Answers to this Paper must he 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)

Question 1.
(a) Name any two basic principles of Object-oriented Programming.
(b) Write a difference between unary and binary operator.
(c) Name the keyword which :
(i) indicates that a method has no return type.
(ii) makes the variable as a class variable.
(d) Write the memory capacity (storage size) of short and float data type in bytes.
(e) Identify and name the following tokens :

(i) public
(ii) ‘a’
(iii) ==
(iv) {}

Solution.

(a) Abstraction and encapsulation are the basic principles of Object-oriented


Programming.

(b)
Unary Operators Binary Operators

(i) The operators which act upon a (i) The operators which require two
single operand are called unary operands for their action are called
operators. binary operators.
(ii) They are pre-increment and post (ii) They are mathematical operators
increment (+ +) and relational operators.

(c)
(i) void
(ii) static

(d) (i) short: 2 bytes


(ii) float: 4 bytes

(e) (i) keyword


(ii) literal
(iii) operator
(iv) separator

Question 2.
(a) Differentiate between if else if and switch-case statements. [2]
(b) Give the output of the following code : [2]
String P = “20”, Q = “19”,
int a = Integer .parselnt(P);
int b = Integer. valueOf(Q);
System.out.println(a+””+b);
(c) What are the various types of errors in Java ? [2]
(d) State the data type and value of res after the following is executed : [2]
char ch = ‘9’;
res = Character. isDigit(ch) ;

(e) What is the difference between the linear search and the binary search technique?
[2]

Solution.

(a)
if else if switch-case

(i) It evaluates integer, character, pointer or (i) It evaluates only character or integer
floating-point type or boolean type. value.

(ii) Which statement will be executed (ii) Which statement will be executed is
depend upon the output of the expression decided by user.
inside if statement.

(b) 2019
(c) Syntax error, Runtime error, Logical error
(d) boolean
True
(e)

Linear Search Binary Search


(i) Linear search works both for sorted (i) Binary search works on sorted data
and unsorted data. (either in ascending order or in
descending order).
(ii) Linear search begins at the start of an (ii) This technique divides the array in two
array i.e. at 0th position. halves, and the desired data item is
searched in the halves.

Question 3.
(a) Write a Java expression for the following : [2]
|x2+2xy|
(b) Write the return data type of the following functions : [2]
(i) startsWith( )
(ii) random( )
(r) If the value of basic=1500, what will be the value of tax after the following statement
is executed? [2]
tax = basic > 1200 ? 200 : 100;
id) Give the output of following code and mention how many times the loop will execute
? [2]
int i;
for(i=5; i> =l;i~)
{
if(i%2 ==1)
continue;
System.out.print(i+ ”
}
(e) State a difference between call by value and call by reference. [2]
(f) Give the output of the following: [2]
Math.sqrt(Math.max(9, 16))
(g) Write the output for the following: [2]
String s1 = “phoenix”; String s2 =”island”;
System.out.prindn (s1.substring(0).concat (s2.substring(2)));
System.out.println(s2.toUpperCase( ));
(h) Evaluate the following expression if the value ofx=2,y=3 and z=1. [2]
v=x+–z+y+ + +y
(i) String x[ ] = {“Artificial intelligence”, “IOT”, “Machine learning”, “Big data”}; [2]
Give the output of the following statements:
(i) System.out.prindn(x[3]);
(ii) System.out.prindn(x.length);
(j) What is meant by a package? Give an example. [2]

Solution.

(a) Math.abs((x * x) + (2 * x * y);


(b) (i) boolean
(ii) double
(c) 200
(d) 4 2
Loop will execute 5 times.

(e)

Call by Value Call by Reference


(i) In call by value the method creates its new (i) In call by reference, reference of the
set of variables (formal parameters) to copy actual parameters is passed on to the
the value of actual parameters and works method. No new set of variables is created.
with them.
(ii) Any change made in the formal (ii) Any change made in the formal
parameter is not reflected in the actual parameter is always reflected in the actual
parameter. parameters.
(iii) Primitive data types are passed by call by (iii) Reference types like (objects, array etc.)
value. are passed by call by reference.

(f) 4.0
(g) phoenix land
ISLAND

(h) = 2 + 0 + 3 + 4
(i) (i) Big data
(ii) 4
(j) A package is an organized collection of classes which is included in the program as
per the requirement of the program. For example java.io package is included for input
and output operations in a program.

Section -B [60 Marks]

Attempt any four questions from this Section


The answers in this Section should consist of the Programs in either Blue J 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.
Flow-Charts and Algorithms are not required.

Question 4.
Design a class name ShowRoom with the following description :
Instance variables/ Data members :
String name – To store the name of the customer
long mobno – To store the mobile number of the customer
double cost – To store the cost of the items purchased
double dis – To store the discount amount
double amount – To store the amount to be paid after discount
Member methods: –
ShowRoom() – default constructor to initialize data members
void input() – To input customer name, mobile number, cost
void calculate() – To calculate discount on the cost of purchased items, based on
following criteria

Cost Discount (in percentage)

Less than or equal to ₹ 10000 5%

More than ₹ 10000 and less than or equal to ₹ 20000 10%

More than ₹ 20000 and less than or equal to ₹ 35000 15%

More than ₹ 35000 20%

void display() – To display customer name, mobile number, amount to be paid after
discount
Write a main method to create an object of the class and call the above member
methods.

Solution.

import java.io.*;
import java.util.*;
class ShowRoom {
String name;
long mobno;
double cost;
double dis;
double amount;
ShowRoom( ) {
name = ” “;
mobno =0;
cost = 0;
dis = 0;
amount = 0;
}
void input( ) {
Scanner sc = new Scanner(System.in);
System.out.println(“EnterName:”);
name = sc.nextLine( );
System.out.println(“Enter Mobile number:”);
mobno = sc.nextLong( );
System.out.println(“Enter cost:”);
cost = sc.nextDouble( );
}
void calculate( ) {
if (cost <= 10000){
dis cost*5/100;
amount = cost – dis;
}
else
if (cost > 10000 && cost < = 20000){
dis = cost* 10/100;
amount cost – dis;
}
else
if (cost > 20000 && cost < = 35000){
dis = cost* 15/100;
amount = cost – dis;
}
else
if (cost > 35000){
dis = cost*20/100;
amount = cost – dis;
}
}
void display( ) {
System.out.println(“Name::” +name);
System.out.println(“Mobile No.::” +mobno);
System.out.println(“Amount::” +amount);
}
public static void main(String args( )) {
ShowRoom ob = new ShowRoom( );
ob.input( );
ob.calculate( );
ob.display( );
}
}

Question 5.
Using the switch-case statement, write a menu driven program to do the following : [15]
(a) To generate and print Letters from A to Z and their Unicode Letters Unicode

(b) Display the following pattern using iteration (looping) statement: 1

Solution.
import java.io.*;
import java.util.*;
class SwitchCase {
public static void main(String args[ ]) {
Scanner sc = new Scanner (System.in);
System.out.println(” 1. Enter 1 for Unicode:”);
System.out.prindn(” 2. Enter 2 for Pattern:”);
System.out.println(“Enter your choice:”);
int choice sc.nextlntO;
switch(choice){
case 1:
char ch;
System.out.println( “Letters \t Unicode”);
for (ch = ‘A’; ch < = ‘Z’; ch+ +) {
System.out.println(ch +”\t” + (int)ch);
}
break;
case 2:
int i, j;
for (i = 1; i < = 5; i+ +) {
for (j = 1; j < = i; j + +)
{
System.out.print(j + “”);.
}
System.out.printlnO;
}
break;
default:
System.out.println(“Wrong choice entered:”);
}
}
}

Question 6.
Write a program to input 15 integer elements in an array and sort them in ascending
order using the bubble sort technique. [15]

Solution.

import java.io.*;
import java.util’*;
class AscendingOrder {
public static void main(String args[]) {
int i, j, temp;
Scanner sc = new Scanner(System.in);
int arr[] = new int[15];
System.out.println(“Enter 15 integers:”);
for (i = 0; i < = 15; i+ +) {
arr[i] = sc.nextlntO;
for(i = 0; i < 14; i++){
for(j = 0; j < 14 -i; j + +){
if(arr[j] > arr[j + 1]){
temp = arr[j];
arr[j] = arr [j + 1];
arr[j + 1] = temp;
}
}
}
System.out.println(“Elements in ascending order are::”);
for (i = 0; i < 15; i+ +) {
System.out.println(arr[i]);
}
}
}
}

Question 7.
Design a class to overload a function series() as follows: [15]

(a) void series (int x, int n) – To display the sum of the series given below:
x1 + x2 + x3 + ……………. xn terms
(b) void series (int p) – To display the following series:
0, 7, 26, 63 p terms.
(c) void series () – To display the sum of the series given below:

Solution.

import java.io.*;
import java.util.*;
class OverloadSeries {
void series( int x, int n) {
int i; .
double a;
double sum = 0;
for (i = 1; i < = n; i++) {
a = Math.pow(x, i);
sum = sum + a;
}
System.out.prindn(“Sum::” +sum)r
}
void series(int p) {
int i;
for (i = 1; i < = p; i++) {
System.out.prindn((i * i * i) – 1 + ” “);
}
}
void series() {
double i;
double s = 0;
for (i =-2; i < = 10; i+ +) {
s = s + 1/i;
}
System.out.println(“Sum:” +s);
}
}

Question 8.
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’. [15]

Example:
Sample Input: ADVANCEMENT AND APPLICATION OF INFORMATION TECHNOLOGY
ARE EVER CHANGING.
Sample Output : Total number of words starting with letter A’ = 4.

Solution.

import java.io.*;
import java.util.*;
class UpperCount {
public static void main(String args[ ]) {
int i, a;
Scanner sc = new Scanner(System.in);
String str, str1, str2;
System.out.prindn(“Enter sentence::”);
str = sc.nextLine();
strl = str.toUpperCaseO; ‘
str2 = “” + strl;
a = 0; ,
for (i = 0; i < = str2.1ength(); i+ +) {
if(str2.charAt(i) == ‘ ‘)
if(str2.charAt(i + 1) == ‘A’);
a+ +;
}
System.out.println(“Total number of words starting with letter ‘A’::” +a);
}
}

Question 9.
A tech number has even number of digits. If the number is split in two equal halves, then
the square of sum of these halves is equal to the number itself. Write a program to
generate and print all four digit tech numbers. [15]

Example :
Consider the number 3025
Square of sum of the halves of 3025 = (30+25)2
= (55)2
= 3025 is a tech number.

Solution.

import java.io.*;
import java.util.*;
class TechNumber {
public static void main(String args[ ]) {
int i, a, b, sum;
String n;
System.out.println(“Four Digits Tech Numbers are::”);
for(i = 1000; i < 1000; i+ +) {
n = i +””;
a = lnteger,parselnt(n.substring(0, 2));
b = Integer.parselnt(n.substring(2));
sum = (int)Math.pow((a + b), 2);
if (sum == i)
System.out.println(i);
}
}
}
ICSE Paper 2018
Computer Applications

General Instructions:

• 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)

Question 1.
(a) Define abstraction.
(b) Differentiate between searching and sorting.
(c) Write a difference between the functions isUpperCase( ) and toUpperCase( ).
(d) How are private members of a class different from public members ?
(e) Classify the following as primitive or non-primitive data types :
(i) char
(ii) arrays
(iii) int
(iv) classes

Solution:
(a) Abstraction is a process of hiding the implementation details and showing only
functionality to the user.

(b) Searching is a technique which is used to search a particular element in an array or


string. Sorting is a technique which is used to rearrange the elements of an array or
string in a particular order either ascending or descending.

(c) The isUpperCase( ) method is used to check whether the given character is in upper
case or not. It returns Boolean data type.
The toUpperCase( ) method is used to convert a character or string into upper case. It
returns char or String type. •
(d) Scope of the private members is within the class whereas scope of the public
members is global.

(e) (i) char is primitive data type.


(ii) arrays are non-primitive data type.
(iii) int is primitive data type.
(iv) classes are non-primitive data type.

Question 2.
(a) (i) int res = ‘A’; [2]
What is the value of res ?
(ii) Name the package that contains wrapper classes.
(b) State the difference between while and do while loop. [2]
(r) System.out.print(“BEST”); |2]
System.out.println(“OF LUCK”);

Choose the correct option for the output of the above statements
(i) BEST OF LUCK
(ii) BEST
OF LUCK

(d) Write the prototype of a function check which takes an integer as an argument and
returns a character. [2]

(e) Write the return data type of the following function. [2]
(i) endsWith( )
(ii) log( )

Solution:
(a) (i) Value of res is 65.
(ii) Java.lang
(b)

(c) (i) BEST OF LUCK is the correct option.


(c) char check(int x)
(e) (i) Boolean
(ii) double

Question 3.
(a) Write a Java expression for the following :

(b) What is the value of y after evaluating the expression given below ?
y + = + +y+y–l –y; when int y=8
(c) Give the output of the following : [2]
(i) Math.floor (- 4.7)
(ii) Math.ceil(3.4) + Math.pow(2,3)
(d) Write two characteristics of a constructor. [2]
(e) Write the output for the following : [2]
System.out.prindn(“Incredible” + “\n” + “world”);
(f) Convert the following if else if construct into switch case [2]
if (var= = 1)
System.out .println(“good”);
else if(var= =2)
System.out.prindn(“better”);
else if(var= =3)
System.out.prindn( “best”);
else
System.out.prindn(“invalid”);

(g) Give the output of the following string functions : [2]


(i) “ACHIEVEMENT” .replaceCE’, ‘A’)
(ii) “DEDICATE”. compareTo(“DEVOTE”)
(h) Consider the following String array and give the output [2]
String arr[]= {“DELHI”, “CHENNAI”, “MUMBAI”, “LUCKNOW”, “JAIPUR”};
System.out.println(arr[0] .length( )> arr[3] .length( );
System.out.print(arr[4] ,substring(0,3));

(i) Rewrite the following using ternary operator : [2]


if(bill > 10000)
discount = bill * 10.0/100;
else
discount = bill * 5.0/100;
(i) Give the output of the following program segment and also mention how many times
the loop is executed : [2]
int i;
for (i = 5; i > 10; i + +)
System.out.printin(i);
System.out.println(i*4);

Solution:
(a) Math.sqrt * (3 * x + Math.pow(x, 2)) / (a + b);
(b) 8 + (9 + 9 + 7) = 8 + 25 =33
(c) (0 – 5.0 (it) 12.0
(d) (i) Constructor has the same name as of class.
(ii) Constructor gets invoked when an object is created.
(e) Incredible
world
(f) switch ( ) {
case 1:
System.out .println( “good”);
break; .
case 2:
System.out .println( “better”);
break;
case 3:
System.out.println( “invalid”);
break;
}
(g) (i) ACHIAVAMANT
(ii) – 18
(h) false (at index 0, DELHI consists of 5 characters, at index 3, LUCKNOW consists of 7
characters. Therefore 5 > 7 is false)
JAI (at index 4, JAIPUR exists and extract its three characters)
(i) discount = bill > 100 ? bill * 10.0 /100 : bill * 5.0 /100;
(j) 20. Loop will be executed for 0 times.

Section-B [60 Marks]

Attempt any four questions from this Section


The answers in this Section should consist of the Programs in either Blue J 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.
Flow-Charts and Algorithms are not required.
Question 4.
Design a class Railway Ticket with following description : [15]
Instance variables/s data members :
String name : To store the name of the customer
String coach : To store the type of coach customer wants to travel
long mobno : To store customer’s mobile number
int amt : To store basic amount of ticket
int totalamt : To store the amount to be paid after updating the original amount

Member methods
void accept ( ) — To take input for name, coach, mobile number and amount
void update ( ) — To update the amount as per the coach selected

Type of Coaches Amount

First_ AC 700
Second_AC 500
Third _AC 250
sleeper None

void display( ) — To display all details of a customer such as name, coach, total amount
and mobile number.
Write a main method to create an object of the class and call the above member
methods.

Solution:

import java.io.*;
import java.util.Scanner; class RailwayTicket {
String name, coach;
long mobno;
int amt, totalamt;
void accept( ) throws IOException {
Scanner sc = new Scanner(System.in);
System.out.print(“Enter Passenger’s Name: “);
name = sc.next( );
System.out.print(“Enter Mobile Number:”);
mobno = sc.nextlnt( );
Systein.out.print(“Enter Coach (FirstAC/SecondAC/ThirdAC/sleeper):”);
coach = sc.next( );
System.out.print(“Enter basic amount of ticket:”);
amt = sc.nexdnt( );
}
void update!) {
if (coach.equals(“First_AC”))
totalamt = amt + 700;
else
if (coach.equals(“Second_AC”))
totalamt = amt + 500; .
else
if (coach.equals!”Third_AC”))
totalamt = amt + 250;
else
totalamt = amt;
}
void display() {
System.out.println(“\n\n Name :” +name);
System.out.println(“Coach :” +coach);
System.out.prindn(”Total Amount:” +totalaint);
System.out.prindn(“Mobile No.:” +name);
}
public static void main (String args[ ]) throws IOException {
RailwayTicket t = new RailwayTicket!);
t.accept();
t.update();
t.display();
}
}

Question 5.
Write a program to input a number and check and print whether it is a Pronic number
[15] or not. (Pronic number is the number which is the product of two consecutive
integers)

Examples : 12 = 3 × 4 .
20 = 4 × 5
42 = 6 × 7

Solution:

import java.io.*;
import java.util. Scanner;
class Pronic]
public static void main(String argsQ) throws IOException {
Scanner sc = new Scanner(System.in);
System.out.print(“Enter the number: “);
int n = sc.nextlnt();
int i = 0;
while(i * (i + 1) < n) {
i++;
}
if(i *(i + 1) = = n){
System.out.println(n + ” is a Pronic Number.”);
}
else {
System.out.prindn(n + ” is not a Pronic Number.”);
}
}
}

Question 6.
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. [15]
Sample input: we are in cyber world
Sample output : We Are In Cyber World

Solution:

import java.io.*;
import java.util.Scanner;
class ChangeLetter {
public static void main(String args[ ]) throws IOException {
Scanner sc = new Scanner(System.in);
System.out.print(“Enter String in lowercase:”);
String str 1 = sc.next( );
strl = “” +strl;
String str2 = ” “:
for (int i = 0; i<strl.length( ); i+ +) {
if(strl ,charAt(i) = = “) {
str2 = str2 + ” +Character. toUpperCase(strl.charAt(i+l));
i+ + ;
}.
else
str2= str2 + strl.charAt(i);
}
System.out.println(str2.trim( ));
}
}

Question 7.
Design a class to overload a function volume() as follows : [15]

(i) double volume (double R) — with radius (R) as an argument, returns the volume of
sphere using the formula.
V = 4/3 × 22/7 × R3
(ii) 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 × R2 × H
(iii) 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.

Solution:

class ShapesVolume {
public static double volume (double R) {
double V = 4.0 / 3, * 22.0 / 7 * Math.pow(R, 3);
return V;
}
public static double volume(double H, double R) {
double V = 22.0 / 7 * R * R * H ;
return V;
}
public static double volume (double L, double B, double H) {
double V = L * B * H;
return V;
}
}

Question 8.
Write a menu driven program to display the pattern as per user’s choice. [15]

For an incorrect option, an appropriate error message should be displayed.


Solution:

import java.io.*;
import java.util.Scanner;
class Pattern {
public static void main(String args[]) throws IOException {
Scanner sc = new Scanner(System.in);
System.out.println(“::::MENU::::”)
System.out.println(” 1. To display ABCD Pattern”);
System.out.print(” 2. To display Word Pattern”);
System.out.print(“Enter your choice:”);
int ch= sc.nextlnt();
switch(ch) {
case 1:
for (char i = ‘E’; i > = ‘A’; i- -){
for(char j = ‘A’;j <=i;j + +){
System.out.print(j);
}
System.out.prindn( );
}
break;
case 2:
String S = “BLUE”;
for (int i = 0; i < S.length(); i+ +) {
for(int j = 0; j < =i; j + +) {
System.out.print(S.charAt(i));
}
System.out.println();
}
break;
default:
System.out.println(“Invalid Input”);
break;
}
}
}

Question 9.
Write a program to accept name and total marks of N number of students in two single
subscript array name[] and total marks[ ]. [15]
Calculate and print:

(i) The average of the total marks obtained by N Number of students.


[average = (sum of total marks of all the students)/N]
(ii) Deviation of each student’s total marks with the average.
[deviation = total marks of a student – average] ‘

Solution:

import java.io.*;
import java. util. Scanner;
class NameMarks {
public static void main(String argsO) throws IOException {
Scanner sc = new Scanner(System.in);
System.out.print(“Enter number of students:”);
int N = sc.nextlnt( );
String named = new String[N];
int totalmarksG = new int[N];
double deviation[ ] = new double[N];
double sum = 0;
for (int i = 0; i < N; i+ +) {
System.out.print(“Enter Name of the Student:”);
name[i] = sc.next( );
System.out.print(“Enter Marks:”);
totalmarks[i] = sc.nextlntO;
sum = sum + totalmarks [i];
}
double average = sum / N;
System.out.println(“The average of the total marks of ” +N+” number of students:”
+average);
for (int i = 0; i < N; i+ +) {
deviadon[i] = total marks (i] – average;
System.out.println(“Deviation of” + name[i] + “s marks with the average:” +deviation[i]);
}
}
}
ICSE Paper 2017
Computer Applications

General Instructions:

• 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)

Question 1.
(a) What is inheritance ? [2]
(b) Name the operators listed below r [2]
(0 <
(it) + +
(iii) &&
(iv) ? :
(c) State the number of bytes occupied by char and int data types. [2]
(d) Write one difference between / and % operator. [2]
(e) String x[ ] = {“SAMSUNG”, “NOKIA”, “SONY”, “MICROMAX”, “BLACKBERRY”}; [2]
Give the output of the following statements :
(i) System.out.prindn(x[1]);
(ii) System.out.println(x[3].length{ )); ,

Answers:
(a) Inheritance in java is a mechanism in which one object acquires all the properties
and behaviors of parent object.

The idea behind inheritance in java is that you can create new classes that are built
upon existing classes. When you inherit from an existing class, you can reuse methods
‘and fields of parent class, and you can add new methods and fields also.
(b) (i) Comparison operator
(ii) Unary operator
(iii) Logical operator
(iv) Ternary operator

(c) The char data occupies two bytes whereas int data type occupies four bytes.
(d) The / operator is used for division whereas % operator is used to find the remainder.
(e) (i) NOKIA
(ii) 8

Question 2.
(a) Name the following : [2]
(i) A keyword used to call a package in the program.
(ii) Any one reference data type.
(b) What are the two ways of invoking functions? [2]
(c) State the data type and value of res after the following is executed: [2]
char ch = ‘t’;
res=Character. toUpperCase(ch);
(d) Give the output of the following program segment and also mention the number of
times
the loop is executed: [2]
int a,b;
for (a=6, b=4; a< =24; a=a + 6)
{
if (a%b= =0)
break;
}
System, out .println(a);

(e) Write the output: [2]


charch= ‘F’;
int m= ch;
m=m+5;
System.out.println(m+ ” ” +ch);

Answers:
(a) (i) import
(ii) Array
(b) By Value and By Reference
(c) int type and value is 84.
(d) Output is 12. Twice.
In the loop : for (a = 6, b=4; a< =24; a = a+6), the value of a will be
incrementing as 6, 24 and upon incrementing the value to 42, the loop will terminate.
Accordingly the loop has to execute two times.
But within the loop there is a condition : if(a%b = =0) break;
This means when remainder on dividing a by b comes out to be 0 (at 24/4 = 0), the
condition breaks and from the above it is clear that value of a is incremented from 6 to
24 when the loop executes second time.

(e) 75 F

Question 3.
(a) Write a Java expression for the following : [2]
ax5 + bx3 + c
(b) What is the value of xl if x=5 ? [2]
x1 = + +x – X+ + + –x
(c) Why is an object called an instance of a class ? [2]
(d) Convert following do-while loop into for loop. [2]
int i = 1;
int d = 5;
do {
d=d*2;
System.out.println(d);
i+ + ; } while (i< =5);
(e) Differentiate between constructor and function. [2]

(f) Write the output for the following : [2]


String s= “Today is Test”;
System.out.println(s.indexOf(‘T’));
System.out.println(s.substring(0, 7) + ” ” + “Holiday”);

(g) What are the values stored in variables r! and r2: [2]
(i) double r1=Math.abs(Math.min(-2.83,-5.83));
(ii) double r2=Math.sqrt(Math.floor(16.3));

(h) Give the output of the following code: [2]


String A = “26”, B=”100″;
String D =A+B+”200″;
int x = Integer.parselnt(A);
int y = Integer.parselnt(B);
int d = x+y;
System.out.println(“Result 1 = ”+D);
System.out.prinln(“Result 2 = “+d); ,

(i) Analyze the given program segment and answer the following questions : [2]
for(int i=3;i< =4;i+ +) {
for(int j=2;j<i;j+ +) {
System.out.print(” “); }
System.out.println(“WIN”); }
(i) How many times does the inner loop execute ?
(ii) Write the output of the program segment.

(f) What is the difference between the Scanner class functions nextQ and nextLine()? [2]

Answers:
(a) a.Math.pow(x,5) + b.Math.pow(x,3) +c;
(b) 6
(c) An object is a software bundle of related state and behavior. A class is a blueprint or
prototype from which objects are created. An instance is a single and unique unit of a
class.

(d) int i =1;


int d = 5;
for(i = 1; i < = 5; i+ +) {
d = d*2;
System.out.println(d);
}

(e) Constructors must be named with the same name as the class name. They cannot
return anything, even void (the object itself is the implicit return).
Functions must be declared to return something, although it can be void.

(f) 0
Today i Holiday
(g) r1 = 5.83 .
r2 = 4.0
(h) Result 1 = 26100200
Result 2 = 126
(i) (i) Once
(ii) WIN
WIN

(j)next ( ) can read the input only till the space. It cannot read two words separated by
space.
Also, next( ) places the cursor in the same line after reading the input.
nextLine( ) reads input including space between the words (that is, it reads till the end of
line \n). Once the input is read, nextLine( ) positions the cursor in the next line.
Section – B (60 Marks)

Attempt any four questions from this Section.


The answers in this Section should consist of the Programs in either Blue J 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.
Flow-Charts and Algorithms are not required.

Question 4.
Define a class ElectricBill with the following specifications : [15]
class : ElectricBill

Instance variables /data member :


String n – to store the name of the customer
int units – to store the number of units consumed
double bill – to store the amount to be paid

Member methods :
void accept ( ) – to accept the name of the customer and number of units consumed
void calculate ( ) – to calculate the bill as per the following tariff :

A surcharge of 2.5% charged if the number of units consumed is above 300 units.

Write a main method to create an object of the class and call the above member
methods.
Answer:
import java.io.*;
class ElectricBill {
String n;
int units;
double bill ;
void accept() throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.print(“Name of the customer = “);
n = reader.readLine( );
System.out.print( “Number of units consumed = “);
String un = reader. readLine( );
units=Integer .parselnt(un);
}
void calculate!) {
if(units < = 100)
bill = 2.00*units;
if(units< =300) bill = 3.00*units; if (units > 300)
bill = 5.00*units;
}
void print( ) {
System.out.println(“Naine of the customer:” +n);
System.out.println(“Number of units consumed:” +units);
System.out.println(“Bill amount:” + bill);
}
public static void main(String argsQ) throws IO
Exception { ElectricBill eb = new ElectricBill( );
eb. accept!);
eb.calculate();
}
}

Question 5.
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.) [15]

Example : consider the number 1124,


Sum of the digits = l + l+ 2 + 4 = 8
Product of the digits = 1×1 x2x4 = 8

Answer:
class Spy {
public static void main(int n) {
int sum = 0;
int multiple = 1;
int a;
int p = n;
// a stores each digit extracted and p creates a backup of input.
while(n ! = 0) {
a = n % 10; ,
sum = sum + a;
multiple = multiple * a;
n = n/10;
}
System.out.println(“The sum of ” +p +” is ”+sum);
System.out.println(“The product of “+p +” is ” + multiple);
if(sum = = multiple) {
System.out.println(“Aha, ” + “It is a Spy Number Where Sum = Product”);
}
else {
System.out.println(” It is NOT a Spy Number Where Sum ft Product”);
}
}
}

Question 6.
Using switch statement, write a menu driven program for the following : [15]

(i) To find and display the sum of the series given below :
S = x1 -x2 + x2 – x4 + x5 – x20
(where x = 2)

(ii) To display the following series :


1 11 111 1111 11111
For an incorrect option, an appropriate error message should be displayed.

Answer:

import java.io.*;
class SwitchStatement {
public static void main(String argsQ) throws IOException {
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader input = new BufferedReader(reader);
System.out.println(“l-Sum of Series:”);
System.out.println(“2-Display Special Series:”);
System.out.println(“Enter your choice:”);
String n1 = input.readLine( );
int ch = Integer.parselnt(nl);
System.out.println(“Enter Number of Terms
String t = input.readLine();
int n = Integer.parselnt(t);
switch (ch) {
case 1:
int sign = -1;
double term = 0;
double sum = 0;
int x = 2;
System.out.println(“Value of x: ” +x);
System.out.println(“Number of terms: ” +n);
sum + = x; // First term added here,
for (int i = 2; i < = n; i+ +){
term = sign * Math.pow(x,i);
sum + = term;
sign *= -1;
}
System.out.println(“Sum of Series +sum);
break;
case 2 :
int num;
System.out.println(“Enter the number of terms: ”);
String tm = input.readLine(); .
num = Integer.parselnt(tm);
int s = 0, c;
for (c = 1; c < = num; c+ +){
s = s * 10 + 1;
System.out.print(s + ” “);
}
break;
}
}
}

Question 7.
Write a program to input integer elements into an array of size 20 and perform the
following operations: [15]
(i) Display largest number from the array.
(ii) Display smallest number’from the array.
(iii) Display sum of all the elements of the array.

Answer:
import java.util.Scanner;
class LargeSmallSum {
public static void main(String args[ ]) {
int n;
int max, min, sum = 0;
int i, j;
Scanner s = new Scanner(System.in);
System.out.print(“Enter no. of elements you want in array:”);
n = s.nextlnt();
int a[ ] = new int[n];
System.out.println(“Enter all the elements:”);
for (i = 0; i < n; i+ +) {
a[i] = s.nextlntO;
}
max = a[0];
min = a[0];
for(i = 0; i < n ; i + +) { if(a[i] > max) {
max = a[i];
}
if (a[i] < min) {
min = a[i];
}
}
System.out.println(“Maximum Number is:”+max);
System.out.println(“Smallest Number is:” +min);
for(i = 0; i < n; i+ +) {
sum = sum + a[i];
}
System.out.println(“Sum of the Numbers is:” +sum);
}
}

Question 8.
Design a class to overload a function check ( ) as follows : [15]
(i) void check (String str, char ch) – to find and print the frequency of a character in a
string.

Example : *
Input:
str = “success”
ch = ‘s’ .
Output:
number of s present is = 3

(ii) void check(String si) – to display only vowels from string si, after converting it to
lower case.

Example:
Input:
s1 = “computer”
Output:
oue

Answer:
class CharacterVowel {
public void checkering str, char ch) {
int c = 0, code,i,s;
str = str.toLowerCase( );
int len = str.length( );
for (code = 97; code < 122; code+ +) {
c = 0;
for (i = 0; i < len; i+ +) {
ch = str.charAt(i);
s = (int) ch;
if(s = = code)
c = c + 1;
}
ch = (char)code;
if(c ! = 0)
System.out.println(“Frequency of “+ch+ “is” +c);
}
}
public void check(String si) {
int i;
char ch=0, chr=0;
for(i=0;i<s1.length();i+ +) {
ch = s1.charAt(i);
if(Character.isUpperCase(ch))
chr = Character. toLo werCase(ch);
if((s1 .charAt(i)==’a’) 11 (s1 .charAt(i) = ‘u’) | j(s1 .charAt(i) = = ‘o’)| | (s1 .charAt(i)==’i’)
11 (s1 .charAt(i) = = ‘e’))
System.out.println(s1 .charAt(i));
}
}
}

Question 9.
Write a program to input forty words in an array. Arrange these words in descending
order of alphabets, using selection sort technique. Print the sorted array. [15]

Answer:
import java.util.Scanner;
class Descending {
public static void main(String args[ ]) {
int n;
String temp;
Scanner s = new Scanner(System.in);
System.out.print(“Enter number of words you want to enter:”);
n = s.nextlnt( );
String names[ ] = new String[n];
Scanner s1 = new Scanner(System.in);
System.out.println(“Enter all words:”);
for(int i = 0; i < n; i+ +) {
names[i] = s1.nextLine[( );
}
for (int i = 0; i < n; i+ +){
for (int j = i + 1; j < n;j++){
if (names[i].compareTo(namesG]) < 0) {
temp = names [i];
names[i] = namesG];
names[j] = temp;
}
}
}
System.out.print(“Words in Descending Order:”);
for (int i = 0;i<n-l;i++){
System.out.print(names[i] + “,”);
}
System.out.print(names[n – 1]);
}
}
ICSE Paper 2016
Computer Applications

(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)

Question 1:
(a) Define Encapsulation. [2]
(b) What are keywords ? Give an example. [2]
(c) Name any two library packages. [2]

(d) Name the type of error ( syntax, runtime or logical error) in each case given
below: [2]
(i) Math.sqrt (36 – 45)
(ii) int a;b;c;

(e) If int x [ ] = { 4, 3,7, 8, 9,10}; what are the values of p and q ? [2]
(i) p = x.length
(ii) q = x[2] + x[5] * x[1]

Answer:
(a) Encapsulation: It is process of wrapping code and data together into a single unit
(called class).

(b) Keywords: Keywords are reserved words in Java, which have a special meaning in
the language.
Example: if, void, int etc.
(c) (i) java.io
(ii) java.util

(d) (i) logical error


(ii) syntax error

(e) (i) Value of P will be 6.


(ii) q = x[2] + x[5] * x[1]
= 7 + 10 * 3
= 7 + 30 = 37
value of q is 37.

Question 2:
(a) State the difference between == operator and equals ( ) method. [2]
(b) What are the types of casting shown by the following examples: [2]
(i) char c = (char) 120;
(ii) int x = ‘t’;
(c) Differentiate between formal parameter and actual parameter. [2]
(d) Write a function prototype of the following: [2]
A function PosChar which takes a string argument and a character argument and
returns an integer value.
(e) Name any two types of access specifiers. [2]

Answer:
(a)

= = operator equals ( ) method

It is a relational operator. It is a method of string class.

It checks for equality of primitive type of It checks for equality of two string type of
values. values.

(b) (i) Explicit type conversion,


(ii) Implicit type conversion.

(c)

Formal parameter Actual parameter


They are variables define in function They are values given to the function at
signature. the time of function call.
They receive value from actual They give values to formal parameter.
parameter.

(d) int PosChar (String str, char ch)

(e) Two types of access specifiers:


1. public
2. . private

Question 3:
(a) Give the output of the following string functions: [2]
(i) “MISSISSIPPI”.indexOf(‘S’) + “MISSISSIPPF”.lastIndexOf(‘I’)
(ii) “CABLE”.compareTo(“CADET”)

(b) Give the output of the following Math functions: [2]


(i) Math.ceil(4.2)
(ii) Math.abs(-4)

(c) What is a parameterized constructor ? [2]

(d) Write down java expression for: [2]

(e) Rewrite the following using ternary operator: [2]


if (x%2 == o)
System.out.print(“EVEN”);
else
System.out.print(“ODD”);

(f) Convert the following while loop to the corresponding for loop: [2]
int m = 5, n = 10;
while (n>=1)
{
System.out.println(m*n);
n-;
}

(g) Write one difference between primitive data types and composite data types. [2]
(h) Analyze the given program segment and answer the following questions: [2]
(i) Write the output of the program segment.
(ii) How many times does the body of the loop gets executed ?

(i) Give the output of the following expression: [2]


a+= a++ + ++a + – – a + a – – ; when a = 7

(j) Write the return type of the following library functions: [2]
(i) is Letter Or Digit(char)
(ii) replace(char, char)

Answer:
(a) (i) 2 + 10 = 12
(ii) -3

(b) (i) 5.0


(ii) 4

(c) Parameterized Constructor: It is a constructor which accepts parameters. When an


object is declared using parameterized constructor, the initial values have to be passed
as arguments to the constructor.

(d) T = Math.sqrt (A*A + B*B + C*C);

(e) String k;
k = x%2 == 0 ? “EVEN” : “ODD”;
System.out.print(k);

(f) for (int m=5, n=10; n>=1; n – – )


{
System.out.println (m*n);
}

(g)

Primitive data types Composite data types


They are predefined/inbuilt data These data types are defined by user
types. and made-up of primitive data type
values.
Examples : int, byte, long, short, char, Examples : Array, class, interface.
float, double, boolean.

(h) (i) Output:


5
10
(ii) 3 times

(i) a = a+ a++ + ++a + – – a + a – – ;


= 7 + 7 + 9 + 8 + 8 = 39

(j) (i) boolean (ii) String

Section B (60 Marks)

Attempt any four questions from this Section.


The answers in this Section should consist of the Programs in either Blue J,
environment or any program environment with Java as the base.
Each program should be written using Variable descriptions I Mnemonic Codes so that
the logic of the program is clearly depicted.
Flow-Charts and Algorithms are not required.

Question 4:
Define a class named Book Fair with the following description: [15]
Instance variables/Data members :

String B name — stores the name of the book


double price — stores the price of the book Member methods :

(i) Book Fair() — Default constructor to initialize data members


(ii) void Input() — To input and store the name and the price of the book.
(iii) void calculate() — To calculate the price after discount. Discount is calculated based
on the following criteria.

Price Discount
Less than or equal to Rs. 1000 2% of price

More than Rs. 1000 and less than 10% of price


or equal to Rs. 3000
More than % 3000 15% of price

(iv) Void display () — To display the name and price of the book after discount. Write a
main method to create an object of the class and call the above member methods.

Answer:
Question 5:
Using the switch statement, write a menu driven program for the following: [15]
(i) To print the Floyd’s triangle [Given below]

2 3

4 5 6

7 8 9 10

11 12 13 14 15
(ii) To display the following pattern:

I C

I C S

I C S E

For an incorrect option, an appropriate error message should be displayed.

Answer:
Question 6:
Special words are those words which starts and ends with the same letter. [15]

Examples:
EXISTENCE
COMIC
WINDOW
Palindrome words are those words which read the same from left to right and vice
versa

Examples:
MALAYALAM
MADAM
LEVEL
ROTATOR
CIVIC

All palindromes are special words, but all special words are not palindromes. Write a
program to accept a word check and print whether the word is a palindrome or only
special word.

Answer:

Question 7:
Design n class to overload a function SumSeriesO as follows: [15]

(i) void SumSeries(int n, double x) – with one integer argument and one double
argument to find and display the sum of the series given below:
(ii) void SumSeries() – To find and display the sum of the following series:
s = 1 + (1 x 2) + (1 x 2 x 3) + ….. + (1 x 2 x 3 x 4 x 20)

Answer:
Question 8:
Write a program to accept a number and check and display whether it is a Niven number
or not. [15]

(Niven number is that number which is divisible by its sum of digits).

Example:
Consider the number 126.
Sum of its digits is 1+2+6 = 9 and 126 is divisible by 9.

Answer:

Question 9:
Write a program to initialize the seven Wonders of the World along with their locations
in two different arrays. Search for a name of the country input by the user. If found,
display the name of the country along with its Wonder, otherwise display “Sorry Not
Found!”. [15]

Seven wonders — CHICHEN ITZA, CHRIST THE REDEEMER, TAJMAHAL, GREAT WALL
OF CHINA, MACHU PICCHU, PETRA, COLOSSEUM
Locations — MEXICO, BRAZIL, INDIA, CHINA, PERU, JORDAN, ITALY
Example — Country Name: INDIA Output: INDIA-TAJMAHAL
Country Name: USA Output: Sorry Not Found!
Answer:
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.

Question 1.

(a) Which of the following are valid comments?


(i) /* comment */
(ii) /* comment
(iii) // comment
(iv) */ comment */ [2]

(b) What is meant by a package? Name any two Java Application Programming
Interface packages. [2]

(c) Name the primitive data type in Java that is:


(i) a 64-bit integer and is used when you need a range of values wider than
those provided by int.
(ii) a single 16-bit Unicode character whose default value is '\u0000' [2]

(d) State one difference between floating point literals float and double. [2]
(e) Find the errors in the given program segment and re-write the statements correctly
to assign values to an integer array.
int a = new int( 5 );
for( int i=0; i<=5; i++ ) a[i]=i; [2]

Question 2.

(a) Operators with higher precedence are evaluated before operators with relatively
lower precedence. Arrange the operators given below in order of higher precedence
to lower precedence.
(i) && (ii) % (iii) >= (iv) ++ [2]
(b) Identify the statements listed below as assignment, increment, method invocation or
object creation statements.
(i) System.out.println("Java");
(ii) costPrice = 457.50;
(iii) Car hybrid = new Car();
(iv) petrolPrice++; [2]
(c) Give two differences between switch statement and if-else statement. [2]
(d) What is an infinite loop? Write an infinite loop statement. [2]
(e) What is a constructor? When is it invoked? [2]

Question 3.

(a) List the variables from those given below that are composite data types.
(i) static int x; (iv) boolean b;
(ii) arr[i]=10; (v) private char chr;
(iii) obj.display(); (vi) String str; [2]

(b) State the output of the following program segment:


String str1 = “great”; String str2 = “minds”;
System.out.println(strl.substring(0,2).concat(str2.substring(l)));
System.out.println(("WH" + (strl.substring(2).toUpperCase()))); [2]

2
T14 861
(c) What are the final values stored in variables x and y below?
double a = − 6.35;
double b = 14.74;
double x = Math.abs(Math.ceil(a));
double y = Math.rint(Math.max(a,b)); [2]
(d) Rewrite the following program segment using the if-else statements instead of the
ternary operator.
String grade = (mark>=90) ? "A" : (mark>=80) ? "B" : "C"; [2]
(e) Give output of the following method:
public static void main(String[] args) {
int a = 5;
a++;
System.out.println(a);
a − = (a− −) − (− −a);
System.out.println(a); } [2]
(f) What is the data type returned by the library functions:
(i) compareTo()
(ii) equals() [2]
(g) State the value of characteristic and mantissa when the following code is
executed.
String s = "4.3756";
int n = s.indexOf('.');
int characteristic = Integer.parseInt(s.substring(0,n));
int mantissa = Integer.valueOf(s.substring(n+1)); [2]
(h) Study the method and answer the given questions.
public void sampleMethod()
{ for( int i=0; i<3; i++ )
{ for( int j=0; j<2; j++)
{ int number = (int)(Math.random() * 10);
System.out.println(number); }}}
(i) How many times does the loop execute?

3
(ii) What is the range of possible values stored in the variable number? [2]

(i) Consider the following class:


public class myClass {
public static int x = 3, y = 4;
public int a = 2, b = 3; }
(i) Name the variables for which each object of the class will have its own
distinct copy.
(ii) Name the variables that are common to all objects of the class. [2]
(j) What will be the output when the following code segments are executed?
(i) String s = "1001";
int x = Integer.valueOf(s);
double y = Double.valueOf(s);
System.out.println("x=" +x);
System.out.println("y=" +y);
(ii) System.out.println("The King said \"Begin at the beginning!\" to me."); [2]

SECTION B (60 Marks)

Attempt any four questions from this Section.

The answers in this Section should consist of the Programs in either Blue J environment
or any program environment with Java as the base.
Each program should be written using Variable descriptions/Mnemonic Codes
such that the logic of the program is clearly depicted.
Flow-Charts and Algorithms are not required.

Question 4.

Define a class named movieMagic with the following description:


Instance variables/data members:
int year - to store the year of release of a movie
String title - to store the title of the movie.
float rating - to store the popularity rating of the movie.
(minimum rating = 0.0 and maximum rating = 5.0)

4
Member Methods:
(i) movieMagic() Default constructor to initialize numeric data members to 0 and
String data member to "".
(ii) void accept() To input and store year, title and rating.
(iii) void display() To display the title of a movie and a message based on the rating as
per the table 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 a main method to create an object of the class and call the above member methods. [15]

Question 5.

A special two-digit number is such that when the sum of its digits is added to the product
of its digits, the result is equal to the original two-digit number.
Example: Consider the number 59.
Sum of digits = 5 + 9 = 14
Product of its digits = 5 x 9 = 45
Sum of the sum of digits and product of digits= 14 + 45 = 59
Write a program to accept a two-digit number. Add the sum of its digits to the product of
its digits. If the value is equal to the number input, output the message “Special 2-digit
number” otherwise, output the message “Not a Special 2-digit number”. [15]

Question 6.

Write a program to assign a full path and file name as given below. Using library functions,
extract and output the file path, file name and file extension separately as shown.
Input C:\Users\admin\Pictures\flower.jpg
Output Path: C:\Users\admin\Pictures\
File name: flower
Extension: jpg [15]

5
Question 7.

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 = ( − )( − )( − )

where s =

(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 diagonal1, double diagonal2) with two double arguments, returns
the area of a rhombus using the formula:

area = (diagonal1 × diagonal2) [15]

Question 8.

Using the switch statement, write a menu driven program to calculate the maturity amount
of a Bank Deposit.
The user is given the following options:
(i) Term Deposit
(ii) Recurring Deposit
For option (i) accept principal(P), rate of interest(r) and time period in years(n). Calculate

and output the maturity amount (A) receivable using the formula A= P 1+
For option (ii) accept Monthly Installment (P), rate of interest(r) and time period in months
(n). Calculate and output the maturity amount(A) receivable using the formula
( )
A=P×n+P× × ×

For an incorrect option, an appropriate error message should be displayed. [15]

6
Question 9.

Write a program to accept the year of graduation from school as an integer value from the
user. Using the Binary search technique on the sorted array of Integers given below,
output the message “Record exists” if the value input is located in the array. If not, output
the message “Record does not exist”.
{1982, 1987, 1993, 1996, 1999, 2003, 2006, 2007, 2009, 2010} [15]

You might also like