0% found this document useful (0 votes)
25 views14 pages

ICSE 10 Sample Paper 1 Ans

Answer

Uploaded by

josephmaryjudy78
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)
25 views14 pages

ICSE 10 Sample Paper 1 Ans

Answer

Uploaded by

josephmaryjudy78
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/ 14

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. What do mean by Inheritance and Polymorphism in Java? [2]


Ans. Inheritance
 When one object acquires the properties and behaviors of a parent object, it is known as
inheritance. The data and methods available to the parent class or super class is also available
to the child class with the same names.
 It also provides code reusability.
 For e.g. we can have a class shape from which I can drive sub class Circle, Triangle, Square
etc...
Polymorphism
 Polymorphism means having many forms. In Java, we use method overloading and method
overriding to achieve polymorphism.
 In method overloading, we can have multiple methods with same name, like to find area,
based upon number of parameters the function can work for different shapes.
 In case of inheritance, the derived class can either use the method of base class or it can have
its own implementation of the method which will then override the base class function. This
is called method overriding.
 Polymorphism simplifies usage of object methods by external code and Java takes care of
calling the right method with the help of the signature and declaration of these entities

b. Give the output of this code


int a = 9; a++;
System.out.println (a);
a -= a-- - --a;
System .out.println (a); [2]

1
Ans: 10
8
Explanation
a = 9;
a++; // a = 10
SOP (a) // Prints 10
a -= a-- - --a;
a = 10 – (10 – 8)
a = 10 -2 = 8
SOP (a) // Prints 8

c. What is the value stored in x and y after execution of these statements?


double x = Math.ceil(8.3) + Math.floor(-3.2)+Math.rint(4.5);
double y = Math.abs(Math.round(Math.max( -4.4, -9.6))); [2]

Ans.
X = 9.0 Working: 9.0 + (-4.0) + 4.0 = 9.0
Y = 4.0 Working Math.abs(Math.round(-4.4)) = 4.0

d. Give the total number of bytes occupied by these arrays?


i. int ar[25]
ii. char M[3][4]
iii. double A[12] [2]
Ans.
The number of bytes:
i. ar[25] = 4*25 =100 bytes.
ii. M[3][4] = 2*3*4 =24 bytes
iii. A[12] = 8*12 =96 bytes

e. What is the output of this code? Show the working


long num=729, sum 0;
for( long y= num; y> 0; y= y/10){
sum= sum + y % 10;
}
System.out.println("Sum of digits = "+ sum); [2]

Ans. Sum of digits = 18

Initialization num = 729, sum = 0, y = 729


Iteration 1: sum = 0 + 729 % 10 = 9
Iteration 2: y = 729/10 = 72
sum = 9 + 72%10 = 11
Iteration 3 y = 72/10 = 7
sum = 11 + 7%10 = 18
y = 7/10 = 0 so the loop exits.

Print: Sum of digits = 18


2
Question 2.

a. In the program given below, state the name and the value of the :
i. method argument or argument variable
ii. local variable
iii. class variable
iv. instance variable

class myClass{
static int x = 7; int y = 2;
public static void main(String args[] ){
myClass obj= new myClass();
System.out.println( x );
obj.sampleMethod(5);
int a = 6;
System.out.println( a );
}
void sampleMethod(int n){
System.out.println(n);
System.out.println(y);
}
} [2]

Ans.
i. Method argument or argument variable is: n
ii. The class variable is : x
iii. The local variable is: a
iv. The instance variable is: y

b. State the result of the following statement.


System.out.print("My Friends are \n");
System.out.print("Ronit \tNihir \t");
System.out.print("and Ananya too"); [2]

Ans.
My Friends are
Ronit Nihir and Ananya too.

c. What do you mean by function overloading? Explain with the help of


one example. [2]
Ans.
Java allows creating or defining various functions/methods by the same name which are
differentiated by their data types or number of arguments. This is known as function
overloading.
Example
class Overloading{
int Sum(int a){ // 1st overloaded function with one argument

3
return a*a;
}
int Sum(int a, int b){ // 2nd overloaded function with two arguments
return ((a*a) + (b*b));
}
}

d. What is the output of the following statements when executed?


char ch[ ]= {„I‟, 'N', T', E', 'L', P', „E‟, „N', „T‟, „I‟, „U', 'M'};
String obj= new String(ch, 3, 4);
System.out.println("The result is = "+ obj ); [2]
Ans.:
Output:
ELPE

e. Differentiate between Character.toLowerCase() and Character.toUpperCase() methods.


With an example. [2]

Character.toLowerCase() Character.isDigit()
It is used to convert a string into lower case It returns true if character argument is a
form (Small letters). digit, otherwise returns false.
Example: Example:
char ch= 'd'; Char c=‟b‟;
char st= Character.toUpperCase( ch ); boolean st1= Character.isDigit(ch);

Question 3.
a. Explain the statements (i) and (ii) from the following code.
char x ='a';
(i) x+= 3; // why will this run?
(ii) x= x +3; //why will this gives compile time error? [2]
Ans.
(i) Because x += 3; is equivalent to x = (char) (x+3); // here (char) is type casting
(ii) Where x +3 is default to int operation, assign an int to char must be type cast.

b. What is Exception Handling? What is IOException and


NumberFormatException? [2]
Ans.
Exception is unexpected situation which arises at run time and which can potentially abort
the program. The process of catching the error using relevant exception handler to continue
to run the program successfully is called Exception handling.
IOException: This exception occurs due to some I/O problem occurring during reading or
writing to a device.
NumberFormatException: This appears when an invalid number format is encountered.

c. What is the difference between pure and impure function? [2]

4
Pure Function Impure Function
It does not modify the arguments It modifies the state of arguments
received OR
Relies only on parameters passed to it. Refers to variables outside of method.
e.g. e.g.
public class TestMax { public class TestMax {
/* Return the max between two int */ highestNo = 23;
public static int max(int n1, int n2) public static int max(int n1, int n2)
{ …; {
Return n1; …
} if (n1 < highestNo)
result = highestNo;
…}

d. What is this keyword? Also discuss the significance [2]


Ans.: Keyword THIS is a reference variable in Java that refers to the current object. It is
automatically created when an object is created.
It can be used -:
 To refer to instance variable of current class
 To invoke or initiate current class
 To return the current class instance
 To pass as argument to class method or constructor.

e.g
Class Simply {
int x, y;
// Constructor
Simply (int x, int y)
{
this.x = x;
this.y = y;
}
}

e. State the output of this program Segment?


String str1 = ”great”;
String str2= “Minds”;
System.out.println(str1.substring(0,2). Concat(str2.substring(1)));
System.out.println(( “WH”+(str1.substring(2).toUpperCase() ))); [2]
Ans.
The 1st output is= grinds ( because str1. Substring(0,2)gives “gr” & str2. Substring(1) gives
“inds”)
The 2 output is= WHEAT ( because str1. Substring(2). toUpperCase() gives “EAT”, so
nd

”WH”+”EAT”= “WHEAT”)

f. Write a statement each to perform the following task on a string:


i. Extract the second last character of a word stored in the variable wd.

5
ii. Cheek if the second character of a string str is in uppercase. [2]
Ans.
i. char ch = wd.charAt(wt.length() -2);
ii. if (Character.isUpperCase(str.charAt(1))) OR
if (str.charAt(1)> 'A ' && str.charAt(1) <= „z‟)

g. 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]
Ans.
The statement 1 has two errors: the square brackets „[ ]' is required as "int[ ] a" or "int a[ ]”.
Also, the size of the array 5 should be within the „[ ]‟ bracket instead of ( ).
The statement 2 has one error. The loop should be 0 to 4 i.e. for( int i=0; i< 5; i++) or for( int
i= 0; i <5;i++)
Correct program code
int a[ ]= new int[ 5 ];
for(int i= 0; i <5; i++)
a[i]= i;;

h. What do you mean by Punctuators? Give examples. [2]


Ans.
The specific symbols used to indicate how group of codes are divided and arranged are
known as punctuators.
Examples:
[ ] (used for creating array),
{} (used to make compound statement body),
() (used to perform arithmetic operations, used to enclose arguments of the function,
for type casting),
; (semicolon- used as statement terminator),
, (comma- used to separate list of variables),
. (dot or decimal- used make fraction value, include package, referencing object).

i. If String n1 = "99"; and String n2="100”; Give the output of the following:
i. String st= n1+n2; System.out.println (st) ;
ii. System.out.println( n1.charAt( 1 ));
iii. System.out.println( n2 + n1);
iv. System.out.printlnt (n1+ “ ”+n2); [2]
Ans.
i. 99100
ii. 9
iii. 10099
iv. 99 100

( )
j) Write an expression for [2]

Ans.
Math.pow ((x+y), 2) / (Math.cbrt(3)+y)

6
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 employee having the following description:

Data members:
int Epan : To store personal account number
Instance variables
String Ename : To store name.
double taxincome : To store annual taxable income.
double tax : To store tax that is calculated.
Member functions:
inputData () : Store the pan number, name, taxable income.
cal() : Calculate tax of an employee.
display() :Output details of an employee.

Write a program to compute the tax according to the given conditions and display the output as per
given format.

Total Annual Taxable Income Tax Rate


Up to 1, 00, 000 No tax
From 1, 00, 001 to 1, 50, 000 10% of the income exceeding 1, 00, 000
From 1, 50, 001 to 2, 50, 000 5000+20% of the income exceeding 1, 50, 000
Above 2, 50, 000 25000+30% of the income exceeding 2, 50, 000

Output:
Pan Number Name Tax-Income Tax
……………… ……………… ……………… ………………
……………… ……………… ……………… ………………
[15]
import java.io.*;
public class Employee
{
int Epan;
double inc, tax;
String Ename;

7
public void inputData()throws IOException
{
InputStreamReader read= new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
System.out.println("Enter the Pan Number");
Epan= Integer.parseInt(in.readLine());
System.out.println("Enter the name of the employee");
Ename=in.readLine();
System.out.println(" Enter the Taxable Income");
inc= Integer.parseInt(in.readLine());
}
public void cal()
{
if(inc<= 100000)
tax= 0;
else if(inc<= 150000)
tax=10* (inc-100000)/100;
else if(inc<= 250000)
tax= 5000+20*(inc-150000)/100;
else
tax= 25000+30* (inc-250000)/100;
}
public void display()
{
System.out.println("Pan Number\tName\tTaxablelncome\tTax ");
System.out.println(Epan+"\t" +Ename+"\t" + inc+"\t" +tax);
}
}

Variable Description table:


Variable Name Data type/ Variable Purpose
method
Epan Int To store personal account number
inc Double To store annual taxable income
tax Double To store tax that is calculated
Ename String To store name

Question 5.

Write a program in Java to store 10 numbers each in two different Single Dimensional Array. Now,
merge the numbers of both the arrays in a Single Dimensional Array. Display the elements of merged
array

Sample Input:
a[0] a[1] a[2] a[3] a[4]
10 21 44 45 32

8
b[0] b[1] b[2] b[3] b[4]
35 56 27 91 64

Sample Output:
The list after merging of two arrays:
c[0] c[1] c[2] c[3] c[4]
10 21 44 45 32

c[6] c[7] c[8] c[9] c[10]


35 56 27 91 64
[15]
Ans.

import java.io.*;
public class MergeArray
{
public static void main(String args[])throws IOException
{
int a[]=new int[5];
int b[]= new int[5];
int c[]= new int[10];
int k=0, i;
InputStreamReader read= new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
System.out.println("Enter 5 numbers in the first array: ");
for(i=0;i<5; i++)
{
a[i]=Integer.parseInt(in.readLine());
}
System.out.println("Enter 5 numbers in the second array: ");
for(i= 0;i<5; i++)
{
b[i]= Integer.parseInt(in.readLine());
}
for(i=0; i<5; i++)
{
c[i]=a[i];
}
for(i= 5; i<10; i++ )
{
c[i]=b[k];
k= k+1;
}
System.out.println("The list after merging of two arrays");
for(i=0;i<10; i++)
{
System.out.println(c[i]+" ");
}

9
}
}

Variable Description table:


Variable Name Data type/ Variable Purpose
method
a[ ], b[ ] Int To store input array
c[ ] Int To store and display merged array
i, k Int Loop variable

Question 6.

Write a class to design the given function to perform the the related tasks:

double volume1( double side )- to find and return volume of cube using (side*side*side).
double volume2( double l, double b, double h)- to find and return volume of cuboid
using:(length*breadth*height).
double volume3( double r )- to find and return volume of cylinder using: ((4/3)πr^3) [15]

Ans.

import java.util.Scanner;
public class Fuctions01
{
public double volume1(double s)
{
return (s*s*s);
}
public double volume2(double l, double b, double h)
{
return (l*b*h);
}
public double volume3(double r)
{
return ((4/3)*3.14*r);
}
}

Variable Description table:


Variable Name Data type/ Variable Purpose
method
s Double Function argument
L, b, h Double Function arguments
r Double Function argument

Question 7.

10
Using the switch statement, write a menu driven program for the following:
i. To print the Floyd‟s triangle [Given below]
1
23
456
7 8 9 10
11 12 13 14 15

i. To display the following pattern


I
IC
ICS
ICSE [15]
Ans.

import java.util.Scanner;
public class ICSE_Triangle
{
public static void main(String[] args)
{
System.out.print("(1)To print the Floyd‟s triangle:");
System.out.println("\n1 \n12 \n123 \n1234 \n12345");
System.out.print("(2)To display the following pattern:");
System.out.println("\nI \nIC \nICS \nICSE");
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
switch (choice)
{
case 1:
System.out.println("Enter the number of rows: ");
int n = scanner.nextInt();

int currentNumber = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(currentNumber + " ");
currentNumber++;
}
System.out.println();
}
break;

case 2:
String word = "ICSE";
for (int i = 0; i < word.length(); i++)
{
for (int j = 0; j <= i; j++)
{

11
System.out.print(word.charAt(j) + " ");
}
System.out.println();
}
break;

default:
System.out.println("Invalid choice");
break;
}
}
}

Variable Description table:


Variable Name Data type/ Variable Purpose
method
choice int To input choice given by user
n int To input number for Floyd‟s triangle
i,j int Loop variable

Question 8.

Write a program in java to store the numbers in 3 x 3 matrix in Double Dimensional Array. Display
the sus of:
i. left diagonal elements
ii. right diagonal elements
iii. difference between the sum of left and right diagonal elements [15]

Ans.

import java.io.*;
public class LeftRight
{
public static void main(String args[ ])throws IOException
{
int i, j,ld=0,rd=0,k=2;
int num[ ][ ]=new int[3][3];
InputStreamReader read= new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
System.out.println("Enter the numbers in the 3 x 3 matrix: ");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
num[i][j] =Integer.parseInt(in.readLine());
}

12
}
System.out.println ("The elements of 3 x 3 matrix are:");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
System.out.print(num[i][j]+" ");
}
System.out.println ();
}
for(i=0;i<3;i++)
{
ld=ld+num[i][i];
}
for(i=0;i<3;i++)
{
rd=rd+num[i][k];
k=k-1;
}
System.out.println("The sum left diagonal:"+ld);
System.out.println("The sum right diagonal:"+rd);
System.out.println("The diff. between left and right diagonal:"+(ld-rd));
}
}

Variable Description table:


Variable Name Data type/ Variable Purpose
method
num[ ][ ] int To store and display input array
ld int To calculate left diagonal
rd int To calculate right diagonal
i,j,k int Loop variable

Question 9.

Write a Java program to implement a class Strings with a following method named swapPairs that
accents a String as a parameter and returns that String with each pair of adjacent letters reversed. If
the String has on odd number of letters, the last letter is unchanged.

For example,
the call swapPairs("forget") should return "ofgrte" and the call swapPairs("hello there") should return
"ehll ohtree".
The class also has method main() that accepts a string and calls swapPairs() method to swap pairs of
characters in the passed string. [15]

Ans.
import java.util.Scanner;

13
public class Strings
{
String swap(String str)
{
int len = str.length();
int last = 0;
if (len % 2 != 0) // if len is even
last = len - 1 ;
else
last = len - 2 ;
StringBuffer sb = new StringBuffer(str);
char ch1,ch2 ;
for (int i =0 ; i< last ; i += 2)
{
ch1 = sb.charAt(i) ;
ch2 = sb.charAt(i + 1) ;
sb.setCharAt(i, ch2);
sb.setCharAt(i + 1, ch1) ;
}
return sb.toString();
}
public static void main(String[ ] args)
{
Scanner in = new Scanner (System.in) ;
System.out.println("Enter a string : ") ;
String inputStr = in.nextLine ();
Strings sobject = new Strings(); // create object of class
String outStr = sobject.swap(inputStr) ;
System.out.println("Output String after swapping characters :");
System.out.println(outStr);
}
}
Variable Description table:
Variable Name Data type/ Variable Purpose
method
len int To store length of String
last int To store last index of String
ch1, ch2 char To store and swap characters
i,j,k int Loop variable

14

You might also like