ICSE Computer Applications Previous Year Question Paper 2008 Solved for Class 10
ICSE Paper 2008
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) Mention any two attributes required for class declaration. [2]
(b) State the difference between token and identifier. [2]
(c) Explain instance variable. Give an example. [2]
(d) What is inheritance and how is it useful in Java ? [2]
(e) Explain any two types of access specifier. [2]
Answer:
(a) Two attributes required for class declaration :
(1) Access specifier (2) Class name.
(b) A token is the smallest individual unit in a program. E.g. : keyword, identifiers, literals etc. whereas an identifier is the name given to different parts of a program. E.g. : variable, functions, classes etc.
(c) Instance variables are variables that are created for each instance of a class. These variables represent property/state of object.
e.g.
class text
{
int data 1; // These are instance
int data 2; // variables
:
:
}
(d) Inheritance is the process by which objects of one class can link and share some common properties of objects from another class.
It helps in reusability in such a way that it adds some additional features to a class without modifying the contents of a class.
(e) Two types of access specifier :
(i) private: accessible only to the class in which it is defined.
(ii) public: can be accessible in any class.
Question 2:
(a) What is meant by an infinite loop ? Give an example. [2]
(b) State the difference between = = operator and equals () method. [2]
(c) Differentiate between actual parameter and formal parameter. [2]
(d) What is the use of exception handling in Java ? [2]
(e) Differentiate between base and derived class. [2]
Answer:
(a) An infinite loop is a loop whose test condition is always true. This type of loop never ends by itself.
For example :
for (i=l; i>0; i++)
{
System.out.println(“Prashant Arora”);
base class
}
(b) equals () is a string function where as = = is a relational operator equals ( ) checks for the equality of strings, whereas = = checks the equality of 2 primitive type values.
(c) The parameter listed in the function prototype are termed as the formal parameters whereas the parameter used in the function call statement are the actual parameters.
(d) Exception handling is a term associated with handling irregular situations that occur while a program is executing. When some error is occurred in a program then an exception is created by its throwable class. It helps Java not to terminate the program when the error occurs rather the program is able to continue execution.
(e) The base class is a class whose properties will be inherited and the derived class is a class which inherits the base class. E.g. of base class is Super and derived class is Subclass.
Question 3:
(a) Explain the function of each of the following with an example:
(i) break;
(ii) continue; [4]
(b) Convert the following segment into equivalent for loop [2]
{
int i, 1=0;
while (i<=20)
System.out.print (i+“”);
1++;
}
(c) If a = 5, b = 9 calculate the value of a+ = a++ – ++b +a [2]
(d) Give the output of the following expressions :
(i) If x = -9.99, calculate Math.abs(x);
(ii) If x=9.0, calculate Math.sqrt (x); [2]
(e) If, String x = “Computer”;
String y = “Applications”;
What do the following functions return for :
(i) System.out.print(x.substring(1,5));
(ii) System.out.print(x.indexOf(x.charAt(4)));
(iii) System.out.print(y+x.substring(5));
(iv) System.out.print(x.equals(y)); [4]
(f) If, array [] = {1, 9, 8, 5 2};
(i) What is array.length()?
(ii) What is array[2] ? [2]
(g) What does the following mean ?
Employee staff = new Employee (); [2]
(h) Write a Java statement to input tread the following from the user using the keyboard.
(i) Character.
(ii) String. [2]
Answer:
(a) (i) A break statement terminates the current loop and proceeds to the first statement that follows the loop. For example:
boolean prime=true;
for(int i=2; i<n; i++)
{
prime=(n%i==0);
if (prime) break;
}
(ii) A continue statement transfers the control to the next iteration leaving all the other statement unexecuted that follows after the continue statement.
For example :
for(int i=1; i<20; i++)
{
if(i%2==0)
continue;
System.out.println(i);
}
The above loop will print all the odd numbers.
(b) After converting the while loop into for :
for(int i=0; i<=20; i++)
{
System.out.print(i+“ ”);
}
(c) a + = a ++ – ++ b + a
= 5 – 10 + 6
a + = 1
The value of a after execution will be 6.
(d) (i) 9.99
(ii) 3.0
(e) (i) ompu
(ii) 4
(iii) Applicationster
(iv) False
(f) (i) array length = 5.
(ii) array [2] = 8.
(g) Employee staff=new Employee() means that staff is an object of class Employee and it is being created.
(h) (i) char ch=(char)object.read();
(ii) String str=object.readLine();
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/instance variables:
int pan — to store personal account number
String name — to store name
double tax income — to store annual taxable income
double tax — to store tax that is calculated
Member functions:
input() — Store the pan number, name, taxable income
calc() — Calculate tax for 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. [15]
Total annual Taxable Income | Tax Rate |
Upto Rs. 1,00;000 | No tax |
From 1,00,001 to 1,50,000 | 10% of the income exceeding Rs. 1,00,000 |
From 1,50,001 to 2,50,000 | Rs. 5,000 + 20% of the income exceeding Rs. 1,50,000 |
Above Rs. 2,50,000 | Rs. 25,000 + 30% of the income exceeding Rs. 2,50,000. |
Answer:
class employee
{
int pan;
String name;
double taxincome, tax;
void input(int p, String n, Double income)
{
pan=p;
name=n;
taxincome=income;
}
void calc()
{
if(taxincome<=100000)
{
tax=0.0;
}
else if(taxincome<=150000)
{
tax=1*(taxincome-100000);
}
else if(taxincome<=250000)
{
tax=5000 + 2*(taxincome-150000);
}
else
{
tax=25000 + 3*(taxincome-250000);
}
}
void display()
{
System.out.println(“Pan Number\tName\tTax-income\tTax”);
System.out.println(pan+“ \ t”+name+“ \ t”+taxincome+“ \ t”+tax);
}
}
Question 5:
Write a program to input a string and print out the text with the uppercase and lowercase letters reversed, but all other characters should remain the same as before.
Example:
INPUT : WelComE TO School
OUTPUT : wELcOMe to SCHOOL [15]
Answer:
class letter
{
public static void main( )throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println(“Enter any string :”);
String s = br.readLine ( );
int len=s.length();
String s1=””;//second string
for(int i=0; i<len; i++)
{
char ch=s.charAt(i);
if(Character.isUpperCase(ch))
{
s1=s1+Character.toLowerCase(ch);
}
else if(Character.isLowerCase(s.charAt(i)))
{
s1=s1+Character.toUpperCase(ch);
}
else
{
s1=s1+s.charAt(i);
}
}
s=s1,
System.out.println(s);
}
}
Question 6:
Define a class and store the given city names in a single dimensional array. Sort these names in alphabetical order using the Bubble Sort technique only.
INPUT : Delhi, Bangalore, Agra, Mumbai, Calcutta
OUTPUT : Agra, Bangalore, Calcutta, Delhi, Mumbai [15]
Answer:
import java.io.*;
class city
{
public static void main( )
{
String [ ] name = {“Delhi”, “Bangalore”, “Agra”, “Mumbai”, “Calcutta”};
int i, j;
String temp;
//bubble sort begins
for(i=0; i<4; i++)
{
for (j=0; j<4—i; j++)
{
if((name[j].compareTo(name[j+1]))>0)
{
temp=name[j];
name[j]=name[j+1];
name[j+1]=temp;
}
}
}
//printing
for(i=0; i<5; i++)
{
System.out.println(name [i]);
}
}
}
Question 7:
Write a menu driven class to accept a number from the user and check whether it is a Palindrome or a Perfect number.
(a) Palindrome number— (a number is a Palindrome which when read in reverse order is same as read in the right order)
Example : 11, 101, 151 etc.
(b) Perfect number— (a number is called Perfect if it is equal to the sum of its factors other than the number itself.) Example : 6 = 1 + 2 + 3 [15]
Answer:
import java.io.*;
class number
{
public static void main()throws IOException
{
InputStreamReader IR=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(IR);
System.out.println(“Press 1 for Palindrome Number”);
System.out.println(“Press 2 for Perfect Number”);
System.out.println(“Enter your choice”);
int ch=Integer.parseInt(br.readLine());
int num1, num2;
switch(ch)
{
case 1:
System.out.println(“Enter the Number :”);
num1=Integer.parseInt(br.readLine());
int rev=0;
int x=num1; //duplicate copy
while (x!=0)
{
rev=rev*10+x%10;
x=x/10;
}
if(rev==num1)
{
System.out.println(“The number is Palindrome”);
}
else
{
System.out.println(“The Number is Not Palindrome”);
}
break;
case 2:
System.out.print(“Enter the Number :”);
num2=Integer.parseInt(br.readLine());
int sum=0;
for(int i=1; i<num2; i++)
{
if(num2%i==0)
{
sum=sum+i;
}
}
if(sum==num2)
{
System.out.println(“The Number is Perfect Number”);
}
else
{
System.out.println(“Tbe Number is Not a Perfect Number”);
}
break;
default:
System.out.println(“Wrong Choice! Run the program again”);
break;
}
}
}
Question 8:
Write a class with the name volume using function overloading that computes the volume of a cube, a sphere and a cuboid.
Formula
volume of a cube (vc) = s*s*s
volume of a sphere (vs) = 4/3* π* r* r*r (where π = 3.14 or 22/7)
Volume of a cuboid (vcd) = l* b* h [15]
Answer:
class vol
{
void volume(int s)
{
int vc=s*s*s;
System.out.println(“The Volume of a Cube is”+vc);
}
void volume(double r)
{
double vs=(4/3.0)*3.15*r*r*r;
System.out.println(“The Volume of Sphere is”+vs);
}
void volume(int l, int b, int h)
{
int vcd=l*b*h;
System.out.println(“The Volume of a Cuboid is”+vcd);
}
}
Question 9:
Write a program to calculate and print the sum of each of the following series: [15]
Answer:
(a)
class series
{
public static void main()
{
int s=0;
for(int i=2; i<=20; i=i+2)
{
if(i%4==0)
{
s=s-i;
}
else
{
s=s+i;
}
}
System.out.println(“The Sum of the Series is”+s);
}
}
(b) class series
{
public static void main() throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println(“Enter the value of x:”);
int x = Integer.parseInt(br.readLine( ));
double s=0;
for(int i=2; i<=20; i=i+3)
{
s=s+(double)x/i;
}
System.out.println(“The Sum of the Series is”+s);
}
}