# ICSE Class 10 Computer Application Solved Question Paper Year 2015

COMPUTER APPLICATIONS ICSE – 2015
(Theory)
(Two Hours)

Answer 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 on the head of this paper is the time allowed for writing the answer.
This Paper is divided into Sections.
Attempt all questions from Section A and any four 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

1. Marks 

What are the default values of the primitive data type int and float?
Ans. Default Values:
int 0
float 0.0f

2. Marks 

Name any two OOP’s principles.
Ans.Two OOP’s principles are;
1 Polymorphism
2 Encapsulation

3. Marks 

What are identifiers?
Ans.Identifiers are fundamental building blocks of java program.
They are a general terminology used for arrays, strings, primitive data members etc. They have specific naming rules.
Eg, int n = 1; n is an identifier.

4. Marks 

Identify the literals listed below:
(i) 0.5 (ii) ‘A’ (iii) false (iv) “a”.
Ans. The literals are;
(i) 0.5 – Real Literal
(ii) ‘A’ – Character Literals
(iii) false – Boolean Literal
(iv) “a” – String Literal

5. Marks 

Name the wrapper classes of char type and boolean type.
Ans.Wrapper a classes of:-
char – Character
booloan – Boolean

## Question 2

1. Marks 

Evaluate the value of n if value of p= 5, q=19
int n = (q-p)>(p-q) ? (q-p) : (p-q);
Ans. p=5, q=19
int n= (q-p)> (p-q)? (q-p): (p-q)
hence, n = (q-p) is applicable
= 19-5 = 14

2. Marks 

Arrange the following primitive data types in an ascending order of their size:
(i) char (ii) byte (iii) double (iv) int.
Ans.Arranging according to size
byte < char < int < double.

3. Marks 

What is the value stored in variable res given below:
double res = Math.pow (“345”.indexOf(‘5’), 3);
Ans.
double res = Math.pow (“345”.IndexOf (‘5’),3);
=Math.pow (2,3), As because (“345”.IndexOf (‘5’) is 2
= 8.0

4. Marks 

Name the two types of constructors.
Ans.
Two types of constructor are:
Default constructor and Parameterised constructor.

Example
Default
class Student
{
Student( )
{
}
}

Parameterised
class Student
{
int roll;
String name;
Student (int r, String n)
{
roll = r;
name = n;
}

}

5. Marks 

What are the values of a and b after the following function is executed, if the values passed are 30 and 50:
void paws( int a, int b)
{
a= a+b;
b=a-b;
a=a-b;
System.out.println( a+ “, “+b);
}
Ans.
Output:
50,30

## Question 3

1. Marks 

State the data type and value of y after the following is executed:
char x=’7′;
y=Character.isLetter(x);
Ans.
char x = ‘7’
y = Character.is Letter (x);
y = false
Data type in y is of Boolean type

2. Marks 

What is the function of catch block in exception handling? Where does it appear in a program?
Ans.
Catch block contains all the statements that are to be executed when an error has been detected in the corresponding try block.
So catch helps us to complete our operations even if an error occurs.
It occurs after the try block in a java program.

Example of a try-catch block
try
{
}
catch(NumberFormatException nfEx)
{
System.out.println(“Input format is incorrect”);
}

3. Marks 

State the output when the following program segment is executed:
String a =”Smartphone”, b=”Graphic Art”;
String h=a.substring(2,5);
String k= b.substring(8).toUpperCase( );
System.out.println(h);
System.out.println(k.equalsIgnoreCase(h));
Ans.
Output:-
art
true

4. Marks 

The access specifier that gives the most accessibility is_ _ and the least accessibility is _ _.
Ans.
The access specifier that gives maximum visibility is public and the least accessibility is private.

5. Marks 
1. Name the mathematical function which is used to find sine of an angle given in radians.
2. Name a string function which removes the blank spaces provided in the prefix and suffix of a string.

Ans.

1. Math.sin() is used to find the sine of an angel in radians.
2. trim()is used to remove blank spaces from both ends of the string.
6. Marks 
1. What will this code print?
int arr[] =new int ;
System.out.println(arr);
(i) 0 (ii) value stored in arr (iii) 0000 (iv)garbage value
2. Name the keyword which is used to resolve the conflict between method parameter and instance variables/fields.

Ans.

1. (iv)garbage value.
2. The ‘this’ keyboard remove conflict between method parameter and instance variables having same name.
Example
class Student
{
int rollno;
String name;Student(int rollno, String name)
{
this.rollno = rollno;
this.name = name;
}———————
———————
}Output:
101 Arpan
102 Arnab
7. Marks 

State the package that contains the class:
(ii)Scanner
Ans.
The package that contains:
(ii)Scanner – java.util

8. Marks 

Write the output of the following program code:
char ch;
int x=97;
do
{
ch=(char)x;
System.out.print(ch+””);
if(x%10=0)
break;
++x;
}while(x<= 100);
Ans.
Output:-
a,b,c,d

9. Marks 

Write the Java expressions for:
a2+b2;
2ab
Ans. (Math,pow(a,2) + (Math.pow(b,2))
2.*a*b.

10. Marks 

If int y= 10 then find int z = (++y *(y++ +5));
Ans.
z = 176

# 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 description/Mnemonic Codes
so that the logic of the program is clearly depicted.
Flow-Charts and Algorithms are not required.

## Question 4

Marks 

Define a class called ParkingLot with the following description:
Instance variables /data members:
int vno – To store the vehicle number
int hours – To store the number of hours the vehicle is parked in the parking lot
double bill: To store the bill amount
Member methods:
void input( ) – To input and store the vno and hours.
void calculate( ) – To compute the parking charge at the rate of ` 3 for the first hour or part thereof, and ` 1.50 for each additional hour or part thereof.
void display( ) – To display the detail
Write a main method to create an object of the class and call the above methods.
Ans.

```import java.io.*;

class parkingLot
{
int vno;
int hours;
double bill;

void input( ) throws IOException
{
System.out.print(&amp;quot;Enter the vehicle number is: &amp;quot;);
System.out.print(&amp;quot;Enter number of hours the vehicle is parked in: &amp;quot;);
}

void calculate( )
{
if(hours &amp;lt;= 1)
{
bill = hours *3;
}
else
{
bill = 1 *3.0 +(hours -1) * 1.5;
}
}

void display( )
{
System.out.println(&amp;quot;The Vehicle number is: &amp;quot; +vno);
System.out.println(&amp;quot;The number of hours are: &amp;quot; +hours);
System.out.println(&amp;quot;The bill is Rs.: &amp;quot; +bill);
}

public static void main(String args[ ])throws IOException
{
parkingLot car1 = new parkingLot( );
car1.input( );
car1.calculate( );
car1.display( );
}
}
```

## Question 5

Marks 

Write two separate programs to generate the following patterns using iteration (loop) statements:

 (a) * (b) 54321 *# 5432 *#* 543 *#*# 54 *#*#* 5

Ans.

1. ```		import java.io.*;

class loop1
{
public static void main(String args[ ])throws IOException
{
int i,j;
for(i=1;i&amp;lt;=5;i++)
{
for(j=1;j&amp;lt;=i;j++)
{
if(j%2==1)
System.out.print(&amp;quot;*&amp;quot;);
else
System.out.print(&amp;quot;#&amp;quot;);
}
System.out.println(&amp;quot;&amp;quot;);
}
}
}
&amp;lt;/li&amp;gt;
&amp;lt;li&amp;gt;
import java.io.IOException;

class loop2
{
public static void main(String args[]) throws IOException
{
int i, j;
for (i = 1; i &amp;lt;= 5; i++)
{
for (j = 5; j &amp;gt;= i; j--)
{
System.out.print(j);
}
System.out.println();
}
}
}

&amp;lt;/li&amp;gt;
```

## Question 6

Marks 

Write a program to input and store roll numbers, names and marks in 3 subjects of n number students in five single dimensional array and display the remark based on average marks as given below: (The maximum marks in the subject are 100) Average marks Remark
85-100 EXCELLENT
75-84 DISTINCTION
60-74 FIRST CLASS
40-59 PASS
Less than 40 POOR

Ans.

```import java.io.*;
public class ClassManagement
{

public static void main(String[] args)throws IOException
{
System.out.print(&amp;quot;Enter number of students: &amp;quot;);

int[] roll = new int[n];
String[] name = new String[n];
int[] phy = new int[n];
int[] che = new int[n];
int[] comp = new int[n];
int[] avg = new int[n];

for(int i = 0; i&amp;lt;n; i++)
{
System.out.println(&amp;quot;Enter Data of student: &amp;quot; +(i+1) +&amp;quot;:-&amp;quot;);
System.out.print(&amp;quot;Enter Roll Number: &amp;quot;);
System.out.print(&amp;quot;Enter Name: &amp;quot;);
System.out.print(&amp;quot;Enter Physics Marks: &amp;quot;);
System.out.print(&amp;quot;Enter Chemistry Marks: &amp;quot;);
System.out.print(&amp;quot;Enter Computer Marks: &amp;quot;);
avg[i] = (phy[i] + che[i] +comp[i])/3;
if(avg[i] &amp;gt;= 85)
else if(avg[i] &amp;gt;= 75 &amp;amp;&amp;amp; avg[i] &amp;lt;= 84)
else if(avg[i] &amp;gt;= 60 &amp;amp;&amp;amp; avg[i] &amp;lt;= 74)
else if(avg[i] &amp;gt;= 40 &amp;amp;&amp;amp; avg[i] &amp;lt;= 59)
else
}

for(int j = 0; j&amp;lt;n; j++)
System.out.println(roll[j] +&amp;quot;\t&amp;quot; +name[j] +&amp;quot;\t&amp;quot; +avg[j] +&amp;quot;\t&amp;quot; +grade[j]);
}

}

```

## Question 7

Marks 

Design a class to overload a function Joystring( ) as follows:

1. void Joystring(String s, char ch1, char ch2) with one string argument and two character arguments that replaces the character argument ch1 with the character argument ch2 in the given string s and prints the new string.
Example:
Input value of s -“TECHNALAGY” chl=’A’, ch2=’O’Output: “TECHNOLOGY”
2. void Joystring(String s) with one string argument that prints the position of the first space and the last space of the given string s.
Example:
Input value of =”Cloud computing means Internet based computing”Output: First index: 5 ,
Last index: 36
3. void Joystring( String si, String s2 ) with two string arguments that combines the two strings with a space between them and prints the resultant string.
Example:
Input value of s1 = “COMMON WEALTH ”
Input value of s2 = “GAMES ” Output: COMMON WEALTH GAMESOutput:
Output: COMMON WEALTH GAMES
(use library functions)

Ans.

```import java.io.*;

public class JoyOfString
{

static void Joystring(String s, char ch1, char ch2)
{
s = s.replace(ch1, ch2);
System.out.print(&amp;quot;New String: &amp;quot; +s);

}

static void Joystring(String s)
{
System.out.println(&amp;quot;first space and the last space of the given string&amp;quot;);
System.out.println(&amp;quot;First index : &amp;quot; +s.indexOf(&amp;quot; &amp;quot;));
System.out.println(&amp;quot;Last index: &amp;quot; +s.lastIndexOf(&amp;quot; &amp;quot;));
}

static void Joystring(String s1, String s2)
{
s1 = s1 + &amp;quot; &amp;quot;;
System.out.print(s1.concat(s2));
}

public static void main(String[] args)throws IOException
{
String str;
try
{
System.out.println(&amp;quot;Inputs for 1st Method of String: &amp;quot;);
System.out.print(&amp;quot;Enter a Word: &amp;quot;);
System.out.print(&amp;quot;Enter a Character that would replaced: &amp;quot;);
System.out.print(&amp;quot;Enter a Character that would replaced with: &amp;quot;);
Joystring(str, crep, crepw);

System.out.println(&amp;quot;\nInput for 2nd Method of String: &amp;quot;);
System.out.print(&amp;quot;Enter a String: &amp;quot;);
Joystring(str);

System.out.println(&amp;quot;\nInputs for 3rd Method of String: &amp;quot;);
System.out.print(&amp;quot;Enter 1st String: &amp;quot;);
System.out.print(&amp;quot;Enter 2nd String: &amp;quot;);
Joystring(str1, str2);

}
catch(IOException e)
{
e.printStackTrace();
}
}

}
```

## Question 8

Marks 

Write a program to input twenty names in an array. Arrange these names in descending order of alphabets, using the bubble sort technique.

Ans.

```import java.io.*;

public class BubbleSortNamesArray
{

public static void bubbleSort(String[] array)
{
String temp;
int n = array.length;
for(int i = 1; i&amp;lt;n; i++)
{
for(int j = 0; j&amp;lt;n-i; j++)
{
if(array[j].compareToIgnoreCase(array[j+1]) &amp;gt; 0)
{
temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
}
}
}
}

public static void main(String [] args)throws IOException
{
int len = 20;
String[] stringArray = new String[len];
char Ini;
String IniS;
int i;

for(i=0; i&amp;lt;len; i++)
{
System.out.print(&amp;quot;Enter Name: &amp;quot;);

//Below Lines are for Transforming data to Initials Caps and all in Small
stringArray[i]=stringArray[i].toLowerCase();
Ini = stringArray[i].charAt(0);
IniS = Ini +&amp;quot;&amp;quot;;
IniS=IniS.toUpperCase();
stringArray[i] = stringArray[i].substring(1, stringArray[i].length());
stringArray[i] = 	IniS +	stringArray[i];
}

bubbleSort(stringArray);
System.out.println(&amp;quot;---Final---&amp;quot;);
for(i = 0; i &amp;lt; len; i++)
{
System.out.print(stringArray[i] + &amp;quot;  &amp;quot;);
}
System.out.println();
}
}

```

## Question 9

Marks 

Using the switch statement, write a menu driven program to:

1. To find and display all the factors of a number input by the user (including 1 and excluding number itself).
Example:
Sample Input : n = 15
Sample Output : 1, 3, 5
2. To find and display the factorial of a number input by the user (the factorial of a non-negative integer n, denoted by n!, is the product of all integers less than or equal to n.
Example:
Sample Input : n = 5
Sample Output : 5! = 1x2x3x4x5 =120.
For an incorrect choice, an appropriate error message should be displayed.

Ans.

```import java.io.*;

public class FactCase
{
public static void main(String [] args)throws IOException
{

switch(choice)
{
case 1:
System.out.print(&amp;quot;Enter a Number to find its Factors: &amp;quot;);
int factorNumber = 1;
while(factorNumber &amp;lt; facts)
{
if(facts % factorNumber == 0)
{
System.out.println(factorNumber + &amp;quot; is a factor of &amp;quot; + facts);
}
factorNumber ++;
}
break;
case 2:
System.out.print(&amp;quot;Enter a Number to find its Factorial: &amp;quot;);
long factorial = 1;

System.out.print(factrl +&amp;quot;! = &amp;quot;);
for(int i = 1; i&amp;lt;= factrl; i++)
{
factorial = i * factorial;
if(i&amp;lt;factrl)
System.out.print(i +&amp;quot; X &amp;quot;);
else
System.out.print(i +&amp;quot; = &amp;quot;);
}
System.out.print(factorial);
break;
default: