ICSE Class 10 Computer Application Solved Question Paper Year 2006


COMPUTER APPLICATIONS ICSE – 2006
(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

Marks [2]

a) Name any two OOP’s principles.
Ans.The wrapping up of data and methods into a single unit called class is known as data encapsulation. Thus, encapsulation is the mechanism that binds together code and the data it manipulates, and keeps both safe from outside interference and misuse.

Marks [2]

b) Explain the term object using an example.
Ans. An object is a distinct entity with some characteristics and behavior.
Example:

class Box
{
double width; double height;
}
Box mybox = new Box( ); //Here, mybox is an object of the class Box.

Marks [2]

c) Define a variable.
Ans. A variable is the basic unit of storage in a Java program. Actually, it is a named memory location which holds a data value of a particular data type. A variable is defined by the combination of an identifier, a type and an optional initializer.

Marks [2]

d) What is a wrapper class? Give an example.
Ans. A wrapper class wraps a value of primitive type in an object.
For example:

Data type			Wrapper class
boolean				Boolean
long				Long
float				Float
short				Short

Marks [2]

e) What is the purpose of the new operator?
Ans. New operator allocates memory for an object during run time. The advantage of this approach is that the program can create as many or as few objects as it needs during the execution of the program

Question 2

Marks [2]

a) State the two kinds of data types.
Ans. Java provides two types of data types:

  1. Primitive/Simple/Elemental Data Types
    1. Integers
      1. byte
      2. short
      3. int
      4. long
    2. Floating point numbers
      1. float
      2. double
    3. Characters
      1. char
    4. Boolean
      1. boolean
  2. Reference Data Types
    1. Classes
    2. Interface
    3. Arrays

Marks [2]

b) Write the corresponding expressions for the following mathematical operations:-

  1. mathematical operation
  2. complex mathematical operation


Ans.

  1. math.pow(a, 2) + math.pow(b, 2);
  2. z = math.pow(x, 3) + math.pow(y, 3) - ((x*y)/z);

Marks [2]

c) Define an impure function.
Ans. An impure function changes the state of its parameters. It is also known as modifier function.

Marks [2]

d) Differentiate between if and switch statements.
Ans. The if statement tests a particular condition. If the condition is true, then the statement is executed. If condition is false, then the statement is bypassed.
The switch statement is Java’s multi-way branch statement. It provides an easy way to dispatch execution to different parts of the program code based on the value of an expression. The switch statement looks for a match between the value of the expression and one of its case constants i.e., switch can only test for equality whereas if can evaluate any type of Boolean expression.

Marks [2]

e) What will be the output for the following program segment?

String s = new String("abc");
System.out.println(s.toUpperCase());

Ans. Output: ABC

Question 3

Marks [2]

a) What is meant by private visibility of a method?
Ans. When a method of a class is specified as private, then that method can only be accessed by other members of its class i.e., it is private to its class. This is meant by private visibility of a method.

Marks [2]

b) Find and correct the errors in the following program segment:-

Int n[] = (2,4,6,8,10);
for (int i = 0; i < = 5; i + +)
System.out.println(n[+ i + ]= + n[i]);	

Ans. Rectified program segment:

int n[ ] = {2, 4, 6, 8, 10};
for (int i = 0; i < 5; i + +)
{
System.out.println("n [" + i + "] = " + n [i]);
}

Marks [4]

c) Explain function overloading with an example.
Ans. In Java it is possible to define two or more methods within the same class that share the same name, as long as their parameter declarations are different. When this is the case, the methods are said to be overloaded, and the process is referred to as method overloading (function overloading).
Example:

class Overload
{
void test ( )
{
System.out.println ("No parameters");
}
void test (int a)
{
System.out.println ("a :" + a);
}
}
public class Load
{
public static void main (String args [ ])
{
Overload ob = new Overload( );
ob. test ( );
ob. test (10);
}
}

This program generates the following output:-
No parameters
a : 10

Marks [2]

d) Find the output of the following program segment, when:

i.val = 500
ii.val =1600
int val, sum, n =550;
sum = n + val > 1750? 400:200;
System.out.println(sum);

Ans. (i) 200 , (ii) 400

Marks [2]

e) What is the default constructor?
Ans. When we do not explicitly define a constructor for a class, then Java creates a default constructor for the class. The default constructor automatically initializes all instance variables to zero.

Marks [2]

f) What will be the output for the following program segment?

int a = 0,b = 30,c = 40;
a =  b+ c+ + +b;
System.out.println("a="+ a);	

Ans. Output: a = 98

Marks [2]

g) Differentiate between compareTo( ) and equals( )methods.
Ans. compareTo( ): This method compares two strings to find out which string is less than, equal to or greater than the next.
A string is less than another if it comes before the other in dictionary order. A string is greater than another if it comes after the other in dictionary order. The general form of compareTo( ) method is:

int compareTo(String str)

Here, str is the string being compared with the invoking string.
The result of the comparison is returned and interpreted in the following manner:

	
Value					Meaning
Less than zero			The invoking string is less than str.
Greater than zero		The invoking string is greater than str.
Zero					The two strings are equal.

equals( ): This method is used to compare two strings for equality. It has the general form:

boolean equals(String str)

Here, str is the String object which is being compared with the invoking String object. It return true if the strings contain the same characters in the same order and false if the strings do not contain the same characters in the same order. The comparison is case-sensitive.

Marks [2]

h) What is a package? Give an example.
Ans. A package is a group of related classes, providing access protection and namespace management. The package is both a naming and a visibility control mechanism. We can define classes inside a package that are not accessible by code outside that package. Some of Java’s widely used packages are: java.lang, java.io, java.applet.

Marks [2]

i) Explain the function ofa return statement.
Ans. return is a reserved keyword in Java. It is used to cause an immediate exit from-a method, with control returning to the calling method. The return keyword is followed by an expression, a value to be returned to the calling program, or a variable name.

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

Write a program to calculate and print the sum of odd numbers and the sum of even numbers for the first n natural numbers.
The integer n is to be entered by the user.

Marks [15]

Answer 4

importjava.io.*;
class oddeven
{
public static void main(String args [ ]) throws lOException
{
int n, counter = 0, i, j;
BufferedReader br=new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.println ("Enter the number n till which the sums are to be calculated"); 		str=br.readLine();
n = Integer.parselnt(str);
int a[ ] = new int[n];
int osum = 0, esum = 0;
for (j=0; j<n; j++)
{
for (i=0; i<n; i++)
{	
if (a[i] %2 == 0)
esum += a [i];
else
osum += a[i];
}
}
System.out.println("Odd sum till " +n +" = " +osum);
System.out.println("Even sum till " +n +" = " +esum);
}
}

Question 5

A cloth showroom has announced the following festival discounts on the purchase of items, base on the total cost of the items purchased:-
Total cost Discount (in Percentage)

Total cost Discount (in Percentage)
Less than Rs.2000 5%
Rs. 2001 to Rs.5000 25%
Rs. 5001 to Rs.10000 35%
Above Rs. 10000 50%

Write a program to input the total cost and to compute and display the amount to be paid by the customer after availing the discount.

Marks [15]

Answer 5

import j ava. io. *;
class cloth
{
public static void main(String args[ ]) throws lOException
{	
int counter=0;
int i, j, temp, ptr;
double amt;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
System.out.println("Enter the total amount");
str=br.readLine();
amt=Double.parseDouble(str);
double dis;
if(amt<=2000)
{
dis=amt* (.05);
}
else if((amt>2000) && (amt<=5000))
{
dis=amt%25);
}
else if ((amt>5000) && (amt <=10000))
{
dis=amt*(.35);
}
else
{
dis=amt/2;
}
double net=amt-dis;
System.out.println("The net amount after discount is "+ net);
System.out.println("The amount without discount is" + amt);
System.out.println("The discount is" +dis);
}
}

Question 6

Consider the following statement:-
“January 26 is celebrated as the Republic Day of India”.
Write a program to change 26 to 15, January to August, Republic to Independence and finally print “August 15 is celebrated as the Independence Day of India”.

Marks [15]

Answer 6

import java.io.*;
class StringReplace
{
public static void main (String args[ ]) throws IOException
{
String str="January 26 is celebrated as the Republic Day of India";
System.out.println("The original string is: " +str);
//int posl=str.indexOf("January 26");
int len=str.length();
int len_s1 = "January 26 ".length();
String str2=str.substring(len_s1, len);
String s="August 15 " +str2;
int len_s2=s.length( );
int pos=s.indexOf("Republic");
int len_s3 = "Republic".length();
String str3=s.substring(0, pos);
String str4=s.substring(pos+len_s3, len_s2);
String str5=str3 + "Independence" + str4;
System.out.print("The final string is: " +str5);
}
}

Question 7

Write a program that outputs the result of the following evaluations based on the number entered by the user.

  1. Natural logarithm of the number
  2. Absolute value of the number
  3. Square root of the number
  4. Random numbers between 0 and 1.

Marks [15]

Answer 4

import java.io.*;
import java.math.*;
import java.util.Random;
class Numerics
{
public static void main(String args[])throws lOException
{
int n;
BufferedReader br=new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.print("Enter the number: ");
str=br.readLine( );
n=Double.parseDouble(str);
double(q = r = s = t = 0);
q = Math.log(n);
System.out.println("The natural logarithm of the number " + n + " is " + q);
r = Math.abs(n);
System.out.println("The absolute value of the number " + n + " is " + r);
s = Math.sqrt(n);
System.out.println ("The square root of the number " + n + " is " + s);
t = Math.random()
System.out.println("Random number between 0 and 1 is " + t);
}
}

Question 8

The marks obtained by 50 students in a subject are tabulated as follows:-

Name Marks
—– —–
—– —–
—– —–
—– —–

Write a program to input the names and marks of the students in the subject. Calculate and display:-

  1. The subject average marks (subject average marks = )
  2. The highest mark in the subject and the name of the student.

(The maximum marks in the subject are 100)

Marks [15]

Answer 4

import java.io.*;
class student
{
public static void main(String args[ ]) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int counter=0;
int sz = 50;
String names[ ]=new String[sz];
String str;
int marks[ ]=new int[sz];
int i,avg,sum=0;
int max=marks[0];
int num=0;
System.out.println("Please Enter Student Name & Marks Scored in 100:-");
while(counter<sz)
{
System.out.print("Enter " +(counter + 1) + " Names ");
names[counter]=br.readLine();
System.out.print("Enter marks ");
str=br.readLine();
marks[counter]=Integer.parseInt(str);
counter++;
}
//DISPLAY
System.out.println("NAME\t\t\t\tMARKS");
for(i=0; i<sz; i++)
{
System.out.println(names[i] +"\t\t\t\t" +marks[i]);
}
for(i=0; i<sz; i++)
{
sum += marks[i];
if(marks[i]>max)
{
max=marks[i];
num=i;
}
}
avg=sum/sz;
System.out.println("Average marks = " + avg);
System.out.println("Highest marks are " + max +" of " +names[num]);
}
}

Question 9

Write a program to accept 15 integers from the keyboard, assuming that no integer entered is a zero. Perform selection sort on the integers and then print them in ascending order.

Marks [15]

Answer 4

import java.io.*;
public class Sort
{
public static void selectionSort(int[] array)
{
for (int i = array.length-1; i >= 0; i--)
{
int maxIndex = i;
for(int j = i; j>= 0; j--)
{
if(array[j] > array[maxIndex])
maxIndex = j;
}
int temp = array[i];
array[i] = array[maxIndex];
array[maxIndex] = temp;
}
}
public static void display(int[] array)
{
for(int i = 0; i < array.length; i++)
{
System.out.print(array[i] + " ");
}
System.out.println();
}
public static void main(String[] args )throws IOException
{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
int[] array = new int [15];
System.out.println("Enter the 15 numbers to be sorted:-");
int i = 0;
while(i < 15)
{
array[i++] = Integer.parseInt(input.readLine());
}
System.out.println("Entered numbers are: ");
display(array);
selectionSort(array);
System.out.println("Numbers in ascending order: ");
display(array);
}
}
One Comment

Add a Comment

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.