ICSE Class 10 Computer Application Solved Question Paper Year 2008


COMPUTER APPLICATIONS ICSE – 2008
(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 [2]

    Mention any two attributes required for class declaration.
    Ans. When you define a class, you declare the data that it contains and the code that operates on the data. A class is declared by use of the class keyword. The general form of a class definition is shown below:

    class class_name
    {
    type instance-variable1;
    type instance-variable2;
    ........
    type instance-variableN;
    type methodname1(parameter-list)
    {
    // body of the method
    }
    type methodnameN(parameter-list)
    {
    // body of method
    }
    }
    Where,
    
    1. class is a keyword that identifies class declaration.
    2. class_name is the tag name for the class. It becomes the name of this user defined type. The class_name is used to declare variables, called objects or instances of the class.
    3. Collectively, the methods and variables defined within a class are called members of the class.
    1. Instance Variables: The data, or variables defined within the class are called instance variables. In most classes, the instance variables are accessed by the methods defined in the class.
    2. Methods: Set of operations that may be applied to objects of the class. Class methods are also called class functions.
  2. Marks [2]

    State the difference between token and identifier.
    Ans.

    1. Token: The smallest individual unit in a program is called a token. The tokens available in Java are: Keywords, Identifiers, Literals, Punctuators and Operators.
    2. Identifier: Identifiers are names given to different parts of a program e.g., variables, functions, classes, etc. An identifier is a sequence of uppercase or lowercase letters, digits, underscore and dollar sign characters. The first character of an identifier must not begin with a number. Java is case sensitive. Uppercase and lowercase letters are considered different from each other. Hence, an identifier is case-sensitive. Also, an identifier can have any length and it cannot be Java key word.
  3. Marks [2]

    Explain instance variable. Give an example.
    Ans. Instance Variables: The data, or variables defined within the class are called instance variables. most classes, the instance variables are accessed by the methods defined in the class. The general form of a class definition is shown below:

    class class_name
    {
    type instance-variable1;
    type instance-variable2;
    ........
    type instance-variableN;
    type methodname1(parameter-list)
    {
    // body of the method
    }
    type methodnameN(parameter-list)
    {
    // body of method
    }
    }
    

    Example: Consider a class Ticket which has three instance variables: price, balance and total. A of the instance variables are associated with monetary items that a ticket machine object has to deal with.

    • The price variable stores the fixed price of a ticket in Rupees.
    • The balance variable stores the amount of money inserted into the machine by a user prior tasking for a ticket to be printed.
    • The total variable stores a record of the total amount of money inserted into the machine by users since the machine object was constructed.
    public class Ticket
    {
    int price;
    int balance;
    int total;
    // Methods omitted.
    }
    

    Instance variables can be visualized as small amounts of space inside an object that can be used to store values. Every object created of the class, will have some space for every instance variable declared in its class.
    The figure given below is a diagrammatic representation of an object of Ticket class, with it three instance variables.
    The instance variables have not yet been assigned any values; once they have, we can write each value into the box representing the field.
    All three instance variables are of type int. This indicates that each can store a single whole number.

  4. Marks [2]

    What is inheritance and how is it useful in Java?
    Ans.Inheritance: It is the process by which the property (data or function or both) of one class can be acquired (reused) by another class. The class whose property is acquired is called as BASE CLASS (Super Class, Main Class, and Parent Class). The class in which the property of the base class is acquired is called as DERIVED CLASS (Extended Class, Sub Class, and Child Class).
    From the above diagram we can conclude that TEST is a Base class and if Examiner wants to use either any Class_Test or Term_End_Test, it can easily be used from the TEST. It means that property of Base Class (TEST) is inherited in Class_Test and Term_End_Test derived class.
    Advantages of inheritance are as follows:

    1. Reusability of the code.
    2. Gives ways to divide the program into an economical and useful set of classes.
    3. Changes made in the original class are reflected in all the inherited classes.
  5. Marks [2]

    Explain any two types of access specifier.
    Ans.Access Specifiers: They control the access to the members of a class by modifying its declaration. Java’s access specifiers are public, private and protected. Java also defines a default access level.

    1. Public specifier: When a member of a class is modified by the public specifier, then that member can be accessed by any other code i.e., it is directly accessible from all other classes.
    2. Private specifier: When a member of a class is specified as private, then that member can only be accessed by other members of its class i.e., it is private to its class.
    3. Protected specifier: When a member of a class is specified as protected, then that member is public to subclasses of its class but private to all other classes outside the current package.
    • In object oriented programming, we have a concept of inheritance. Using inheritance, we can create a general class that defines traints common to a set of related items. This class can then be inherited by other classes, called subclasses, each adding those things that are unique to it.
    • A package is, essentially, a grouping of classes.
      When no access specifier is used, then by default the member of a class is public within its own package, but cannot be accessed outside of its package.
      Access specifiers are applicable to both: the class variables as well as class methods.

Question 2

  1. Marks [2]

    What is meant by an infinite loop? Give an example.
    Ans.Infinite loop: An infinite loop is a non-terminating loop.
    Example:
    Where the condition never fulfills to terminate

    x = 6;
    y = 2;
    while(x > y)
    {
    x = x + y; 
    ………
    }
    
  2. Marks [2]

    State the difference between = = operator and equals( ) method.
    Ans. = = operator: = = stands for “equal to” operator i.e., = = is a rational operator which tests for equality.
    equals( ): The 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 returns 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.
    The equals( ) method compares the characters inside a string object with the characters inside another string object.
    The = = operator compares two object references to see whether they refer to the same instance.

  3. Marks [2]

    Differentiate between actual parameter and formal parameter.
    Ans.Actual Parameters: Parameters which appear in function call statement are called actual parameters of a function.
    Formal Parameters: Parameters which appear in function prototype rather in function signature i.e., function definition are called formal parameters of a function.
    For example:

    int length = 10;
    int width = 15;
    int area = method (length, width);	//Appearing in function call statement
    public int method (int ln, int wd)	//Appearing in function signature
    {
    return ln * wd;
    }
    

    In the above code snippet; length and width are actual parameters whereas ln and wd are formal parameters.

  4. Marks [2]

    What is the use of exception handling in Java?
    Ans. Use of exception handling in Java:

    1. Exception handling separates error-handling code from normal code.
    2. It clarifies the code and enhances readability.
    3. It stimulates consequences as the error-handling takes place at one place and in one manner.
    4. It makes for clear, robust, fault-tolerant programs.
  5. Marks [2]

    Differentiate between base and derived class.
    Ans.Base class: The class whose property is acquired is called as BASE CLASS (Super Class, Main Class, Parent Class).
    Derived Class: The class in which the property of the base class is acquired is called as DERIVED CLASS (Extended Class, Sub Class, Child Class).
    From the above diagram we can conclude that TEST is a Base class and if Examiner wants to use either any Class_Test or Term_End_Test, it can easily be used from the TEST. It means that property of Base Class (TEST) is inherited in Class_Test and Term_End_Test derived class. It means that property Base Class TEST is Inherited in Class_Test and Term_End_Test derived class.

Question 3

  1. Marks [4]

    Explain the function of each of the following with an example:

    1. break;
    2. continue;

    Ans.

    1. break: The break statement is used inside the body of switch to terminate a statement sequence. When a break statement is encountered, execution branches to the first line of code outside the body of switch statement.
      Example of break statement inside the body of switch:

      class ItallianFood
      {
      public static void main (String args[ ])
      {
      int choice = 2;
      int Price = 0;
      String Burger;
      switch(choice)
      {
      case 1:
      Burger = “Prawn”;
      Price = 100;
      break;
      case 2:
      Burger = “Chicken”;
      Price = 50;
      break;
      case 3:
      Burger = “Ham”;
      Price = 40;
      break;
      default:
      Burger = “Mixed Veg”;
      Price = 30;
      break;
      }
      System.out.println(“You have chosen ”+Burger +“ Burger for Rs.”+Price + “ each” );
      }
      }
      

      The break statement is used to exit a loop and also inside a switch statement. When a break statement is encountered inside a loop, the loop is terminated and program control resumes at the next statement following the loop. Example of break statement inside a loop:

      int m = 100;
      while (true)
      {
      if (m < 10)
      break;
      m = m - 10;
      }
      System.out.println (“m is” +m);
      
    2. Continue: The continue statement is used to terminate the current iteration of the loop and proceed with the next iteration of the loop. Example:
      int line = 0;
      char ch = (char) System, in.read ( ) ;
      while (ch ! = '&")
      {
      (char) System.in.read ( );
      if(ch = = 'Q')
      break ;
      if(ch! = '\n')
      line++;
      continue;
      }
      
  2. Marks [2]

    Convert the following segment into equivalent for loop

    {
    int i = 0;
    while (I <= 20)
    System.out.print(i +“ ”);
    i++;
    }
    

    Ans. Equivalent for loop:

    for (int i = 0; i < = 20; i++)
    System. out.print(i +“ ”);
    
  3. Marks [2]

    If a = 5, b = 9 calculate the value of a+ = a++ – ++b +a
    Ans.
    a = 5, b = 9
    a+ = a++ – ++b + a
    a+ = 5++ – ++9+5
    a+ = 5++ – 10 + 5
    a+ = 5++ – 5
    a+ = 6 – 5
    a+ = l
    =>a = a + 1
    = 5 + 1
    = 6

  4. Marks [2]

    Give the output of the following expressions.

    1. if x = – 9.99, calculate Math.abs.(x);
    2. if x = 9.0, calculate Matfa.sqrt (x);

    Ans.

    1. x = – 9.99
      Math.abs (x)
      = Math.abs (-9.99)
      = 9.99
    2. x = 9.0
      Math.sqrt (x)
      = Math.sqrt (9.0)
      = 3.0
  5. Marks [4]

    If, String x = “Computer”;
    String y = “Applications”;
    What do the following functions return for?

    1. System.out.println(x.subslring(l,5));
    2. System.out.println(x.indexOf(x.charAt(4)));
    3. System.out.println(y+x.substring(5));
    4. System,out.println(x.equals(y));

    Ans. String x = “Computer”
    String y = “Applications”

    1. Comp
    2. 4
    3. Applicationsuter
    4. false
  6. Marks [2]

    If, array [ ]={1,9,8,5,2};

    1. What is array.length( ) ?
    2. What is array [2]?

    Ans. array[ ] = { 1,9,8,5,2};

    1. array.length( ) = 5
    2. array [2] = 8
  7. Marks [2]

    What does the following mean?
    Employee staff = new Employee( );
    Ans. Employee staff = new Employee( );
    The above statement creates a new object called staff of the class Employee.

  8. Marks [2]

    Write a Java statement to input / read the following from the user using the keyboard.

    1. Character.
    2. String.

    Ans.

    1. download
      char p = (char) (in.read( );
    2. Syntax:
      String p = in.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 description/Mnemonic Codes
so that the logic of the program is clearly depicted.
Flow-Charts and Algorithms are not required.

Question 4

Marks [15]

Define a class employee having the following description:

Data members
int pan to store personal account number
Instance variables
String name to store name
double taxincome 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.

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. 5000 + 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

Output:

Pan Number Name Tax-income Tax
….. ….. ….. …..

Ans.

import java.io.*;
class Employee
{
int pan;
String name;
double taxincome;
double tax;
void input( )throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the name: ");
name = br.readLine( );
System.out.print("Enter the PAN number: ");
pan = Integer.parseInt(br.readLine( ));
System.out.print("Enter the income amount: ");
taxincome = Double.parseDouble(br.readLine());
}
void calc( )
{
if(taxincome<=100000)
tax=0;
else if((taxincome>100000)&&(taxincome<=150000))
tax = 0.10*(taxincome-100000);
else if((taxincome>150000)&& (taxincome<250000))
tax = 5000+(0.20*(taxincome-150000));
else
tax = 25000+(0.30*(taxincome-250000));
}
void display()
{
System.out.println("Pan number \t Name \t Tax-Income \t Tax \n ");
System.out.println(pan + "\t\t" + name + "\t" + taxincome + "\t" + tax );
}
public static void main(String args[]) throws IOException
{
Employee e = new Employee();
e.input( );
e.calc( );
e.display( );
}
}

Question 5

Marks [15]

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

import java.io.*;
public class changecase
{
public static void main(String args[])throws IOException
{
String str,str1=" ";
int a,i;
char chr,chr1=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a sentence:");
str= br.readLine();
a=str.length();
for(i=0;i<a;i++)
{
chr=str.charAt(i);
if(chr>='A'&&chr<='Z')
{
chr1 =Character.toLowerCase(chr);
str1=str1+chr1;
}
if(chr>='a'&& chr<='z')
{
chr1 =Character.toUpperCase(chr);
str1=str1+chr1;
}
if(chr==' ')
str1=str1+" ";
}
System.out.println(str1);
}
}

Question 6

Marks [15]

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

import java.io.*;
public class sortstrings
{
public static void main(String args[])
{
String arr[] = {"Delhi", "Bangalore", "Agra", "Mumbai", "Calcutta"};
System.out.println("lnput: Delhi, Bangalore , Agra , Mumbai, Calcutta" );
String t;
for(int j=0; j<arr.length; j++)
{
for(int i = j+1; i< arr.length; i++)
{
if(arr[i].compareTo(arr[j]) <0)
{
t = arr[j];
arr[j] = arr[i];
arr[i] = t;
}
}
System.out.print( "Output:");
System.out.println(arr[j]);
}
}
}

Question 7

Marks [15]

Write a menu driven to accept a number from the user and check whether it is a Palindrome or a Perfect number.

  1. Palindrome number – (a number is a Palindrome which when read in reserve order is same as read in the right order)
    Example: 11, 101, 151, etc.
  2. Perfect number – (a number is called Perfect if it is equal to the sum of its factors others than the number itself.)
    Example: 6 = 1 + 2 + 3

Ans.

import java.io.*;
public class Number
{ 
void palindrome(int n)
{
int c, d, r=0;
c=n;
do
{
d=n%10;
r=r*10+d;
n=n/10;
}while(n!=0);
if(r==c)
System. out.println("The number " +c +" is a palindrome");
else
System.out.println(" The number " +c +" is not a palindrome");
}
void perfect(int n)
{
int a,s=0;
for(a = 1; a<n; a++)
{
if(n%a==0)
s = s + a;
}
if(s == n)
System.out.println("The number " +n +" is a perfect number");
else
System.out.println("The number " +n +" is not a perfect number");
}
public static void main(String args[]) throws IOException
{
int n, m = 1,r = 0;
int s = 0;
int choice;
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
System.out.print("Enter the number: ");
n=Integer.parseInt(in.readLine());
Number obj = new Number();
System.out.println("Menu");
System.out.println(" Check for palindrome number : Code -[1]");
System.out.println(" Check for perfect number : Code -[2]");
System.out.println(" Exit: Code -[3]");
while(m != 0)
{
System.out.print("Enter your choice: ");
m=Integer.parseInt(in.readLine());
choice = m;
switch(choice)
{
case 1:
obj.palindrome(n);
break;
case 2:
obj.perfect(n);
break;
case 3:
System.out.println("Thank You! ! ! ! ");
System.exit(0);
}
}
}
}

Question 8

Marks [15]

Write a class with the name volume using function overloading that computes the volume of a cube, a sphere and a cuboid.

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

Ans.

import java.io.*;
public class overlaod
{
//Overload volumes for volume of a cube
void volumes (double s)
{
System.out.println( " Volume of a cube:" + (s*s*s));
}
//Overload volumes for volume of a sphere
void volumes (double pi, double r)
{
System.out.println(" Volume of a sphere:" + (1.33*pi*r*r*r));
}
//Overload volumes for volume of a cuboid
void volumes (double l, double b, double h)
{
System.out.println(" Volume of a cuboid:" + (l*b*h));
}
public static void main(String args[]) throws IOException
{
overlaod vl = new overlaod();
//call to all versions of volumes()
vl.volumes(9.0);
vl.volumes(3.14,6.0);
vl.volumes(4.0,5.0,6.0);
}
}

Question 9

Marks [15]

Write a program to calculate and print the sum of each of the following series

  1. Sum(S) = 2 – 4 + 6 – 8 + ………… – 20
  2. Sum(S) x/2 + x/5 + x/8 + ………… + x/20 (Value of x to be input by the user.)

Ans.

import java.io.*;
class Series
{
public static void main(String args[]) throws IOException
{
int i,j,x;
double sum1=0,sum2=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
int term;
int n = 1;
for(i=2;i<=20;i+=2)
{
term = i * n;
n = -1 * n;
sum1 += term;
}
System.out.print("Enter the value of x: ");
str=br.readLine();
x=Integer.parseInt(str);
for(j=2; j<=20; j+=3)	
{
sum2 += x/j;
}
System.out.println("The Series 1 sum= " + sum1);
System.out.println("The Series 2 sum= " + sum2);
}
}
2 Comments

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.