ICSE Class 10 Computer Application Solved Question Paper Year 2016


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

    Define Encapsulation.
    Ans.
    Encapsulation: It is the way of combining both data and the function that operates on the data under a single unit.

  2. Marks [2]

    What are keywords? Give an example.
    Ans.Keywords are predefined, reserved words used in programming that have special meanings to the compiler. Keywords are part of the syntax and they cannot be used as an identifier. For example:
    int, float, etc.

  3. Marks [2]

    Name any two library packages.
    Ans.Built-in or existing Java library package to name any two are java.lang, java.util

  4. Marks [2]

    Name the type of error (syntax, runtime or logical error) in each case given below:

    1. Math.sqrt (36-45)
    2. int a;b;c;

    Ans.

    1. Run Time Error – Not a Number, NaN
    2. Syntax Error – Not a Statement
  5. Marks [2]

    if int x [ ] = {4,3,7,8,9,10}; what are the values of p and q?

    1. p = x.length
    2. q = x[2] + x[5] * x[1]

    Ans.Values for p and q

    1. p will be 6
      Work out: As because the size of the array x [ ] is 6
    2. q will be 37
      Work out: x[2] = 7, x[5] = 10 and x[1] = 3
      So, q = x[2] + x[5] * x[1] = 7 + 10 * 3 = 7 + (10 * 3) as of higher precession = 7 + 30 = 37

Question 2

  1. Marks [2]

    State the difference between == operator and equals( ) method.
    Ans.First difference between them is, equals() is a method defined inside the java.lang.Object class and == is a type of operator known as equality operator in Java that can compare both primitive and objects.
    Second difference between equals() and == operator is that, == is used to check primitives for equalities and reference or memory address of the objects whether they point to same location or not, and equals() method is used to compare the contents of the object e.g. in case of comparing String its characters, in case of Integer it’s their numeric values etc.
    Third difference between equals and the == operator is that we cannot change the behavior of == operator but we can override equals() method and define the criteria for the objects equality.

    Let clear all these differences between equals() and == operator using one Java example :

    String s1=new String(“BlueJ”);
    String s2=new String(“BlueJ”);

    Two strings are created s1 and s2, now using == and equals() method to compare these two String to check whether they are equal or not.

    First, we use equality operator == for comparison which only returns true if both reference variables are pointing to the same object.

    if(s1==s2)
    {
    System.out.printlln(“s1==s2 is TRUE”);
    }else{
    System.out.println(“s1==s2 is FALSE”);
    }

    The output of this comparison is FALSE because created two objects which have a different location in the heap so == compare their reference or address location and return false. Now if we use equals method to check their equivalence what will be the output

    if(s1.equals(s2))
    {
    System.out.println(“s1.equals(s2) is TRUE”);
    }else{
    System.out.println(“s1.equals(s2) is FALSE”);
    }

    The output of this comparison is TRUE because they check that contents are same or not. They both have same value ‘BlueJ’ so they are equal according to String class equals() method .

  2. Marks [2]

    What are the types of casting shown by the following examples:

    1. char c = (char) 120;
    2. int x = ‘t’;

    Ans.

    1. Explicit type conversion or manual type casting and the character value for numeric ‘120’ will be ‘x’ and store to character variable ‘c’.
    2. Implicit or automatic type conversion and the integer value for character ‘t’ will be ‘116’ and store to integer variable ‘x’.
  3. Marks [2]

    Differentiate between formal parameter and actual parameter.
    Ans.
    Differentiating with examples:
    //Invoke (call) the method
    int no1 = 45;
    int no2 = 35;
    int sum = add(no1, no2); // actual parameters or arguments, passing to method that is caller method

    //Method definition
    public int add(int a, int b) //formal parameters or parameters, receiving of ‘type’ data
    {
    return (a + b);
    }
    So,
    Formal parameter — the identifier used in a method to stand for the value that is passed into the method by a caller.
    From the above example, integer a and b are formal parameters of add() method.
    formal parameters are often called parameters. Whereas,
    Actual parameter — the actual value that is passed into the method by a caller.
    For example, the no1 and no2 used when add() is called is an actual parameter.
    actual parameters are often called arguments.

  4. Marks [2]

    Write a function prototype of the following:
    A function PosChar which takes a string argument and a character argument and returns an integer value.
    Ans.
    public int PosChar(String str, char c)

  5. Marks [2]

    Name any two types of access specifiers.
    Ans.
    To name any two types of access specifiers, they are a) public b) private

Question 3

  1. Marks [2]

    Give the output of the following string functions:

    1. “MISSISSIPPI”.indexOf(‘S’) + “MISSlSSIPPI.lastIndexOf(‘I’)
    2. “CABLE”.compareTo(“CADET”)

    Ans.

    1. We will get 2 from “MISSISSIPPI”.indexOf(‘S’) and 10 from “MISSlSSIPPI.lastIndexOf(‘I’) so 2 + 10,
      Hence 12 will be the output of the string function expression
    2. -2
  2. Marks [2]

    Give the output of the following Math functions:

    1. Math.ceil(4.2)
    2. Math.abs(-4)

    Ans.

    1. Math.ceil(4.2) will produce the output as 5
    2. Math.abs(-4) will produce the output as 4
  3. Marks [2]

    What is a parameterized constructor?
    Ans.
    A Constructor is a special type of subroutine called to create an object. In the case of Constructor which has parameters in it called as Parameterized Constructors, this constructor is used to assign different values for the different objects. In the below example we have a constructor for the Dress class which takes in the value and sets to the property, let’s try to set the value for the property “dressColor”

    	
    public class Dress 
    {
    String carColor;
    Dress(String dressColor)
    {
    this.dressColor = dressColor;
    }
    public void disp()
    {
    System.out.println("Color of the Dress is : " + dressColor);
    }
    public static void main(String args[])
    {
    //Calling the parameterized constructor
    Dress d = new Dress("White");
    d.disp();
    }
    }
    
  4. Marks [2]

    Write down Java expression, for:
    mathematical expression
    Ans.
    double r = Math.sqrt(Math.pow(A,2) + Math.pow(B,2) + Math.pow(C,2))

  5. Marks [2]

    Rewrite the following using ternary operator:
    if(x%2==0)
    System.out.print(‘EVEN”);
    else
    System.out.print(“ODD”);
    Ans.
    x%2==0?; System.out.print(‘EVEN”); System.out.print(“ODD”);

  6. Marks [2]

    Convert the following while loop to the corresponding for loop:

    int m = 5, n = 10;
    while (n>=1)
    {
    System.out.println(m*n);
    n--;
    }
    

    Ans.

    for(int n=10, m=5; n>=1; n--)
    {
    System.out.println(+m +" " +n +" " +m*n);
    }
    
  7. Marks [2]

    Write one difference between primitive data types and composite data types
    Ans.
    (i) Primitive data types are built-in data types. Java provides these data types. User-defined or Composite or Compound data type data types are created by users in a program using the java primitive data types and other composite types..
    (ii) The size of primitive data types are fixed. The size of user-defined data types are variable.
    (iii) Primitive data types are available in all parts of Java programs. The availability of user-defined data types depends upon their scope.

  8. Marks [2]

    Analyze the given program segment and answer the following questions:

    1. Write the output of the program segment
    2. How many times does the body of the loop gets executed?
      for (int m=5; m<=20; m+=5)
      {
      if(m%3==0)
      break;
      else
      if(m%5==0)
      System.out.println(m);
      continue;
      }
      

    Ans.

    1. Output of the program segment:
      5
      10
    2. The loop times: 2
      Work out:
      Initial value of m is 5, in next run it will be 10, in both the case else if part will be executed due to there will be remainder more than 0 in if case and the loop will continues but in third run of the loop the value of m will reach at 15 and it will create remainder 0 after modular division with 3 hence in execution the code will reach the code break and loops terminate.
  9. Marks [2]

    Give the output of the following expression:
    a+= a++ + ++a + –a + a–; when a=7
    Ans.int a=7;
    a+= a++ + ++a + –a + a–;
    Output for a will be: 39
    Work out:
    a+= a++ + ++a + –a + a–
    -> a += (a++) + (++a) + (–a) + (a–) unary (post fix and pre fix) are highest precedence operators
    -> a = a + (a++) + (++a) + (–a) + (a–) += operator simplified and re written the expression
    -> a = 7 + (7) + (9) + (9) + (7) Association of unary are Right to Left,
    -> a = 7 + (7 + 9 + 9 + 7) Will be evaluated as Left to Right for Binary + and –
    -> a = 7 + (7 + 9 + 16) = 7 + (7 + 25) = 7 + (32) = 7 + 32 = 39

  10. Marks [2]

    Write the return type of the following library functions:

    1. isLetterOrDigit(char)
    2. replace(char, char)

    Ans.Return type of the following library functions – isLetterOrDigit(char)

    1. Is: boolean
    2. Return type of the following library functions – replace(char, char)
      Is: String. It returns a string derived from this string by replacing every occurrence of old char with new char.

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 named BookFair with the following description:
Class : ElectricBill
Instance variables / data member:
String n – to store the name of the customer
int units – to store the number of units consumed
double bill – to store the amount to be paid
Member methods:
void accept( ) – to accept the name of the customer and number of units consumed
void calculate( ) – to calculate the bill as per the following tariff:
Number of units Rate per unit
First 100 units1 Rs.2.00
Next 200 units Rs,3.00
Above 300 units Rs.5.00
A surcharge of 2.5% charged if the number of units consumed is above 300 units.
void print( )- To print the details as follows:
Name of the customer: ………………………
Number of units consumed: ………………………
Bill amount: ………………………
Write a main method to create an object of the class and call the above member methods.
Ans.

import java.io.*;
public class BookFair
{
String Bname;
double price;
public BookFair()
{
Bname = "";
price = 0.00;
}
void Input( )throws IOException
{
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter Book Name: ");
Bname = read.readLine();
System.out.print("Enter Book Price: ");
price = Double.parseDouble(read.readLine());
}
void calculate( )
{
double dis;
if (price <= 1000)
dis = price * .02;
else if (price > 1000 && price <= 3000)
dis = price * .1;
else
dis = price * .15;
price = price - dis;
}
void display( )
{
System.out.println("Book : " +Bname +" Price : " +price);
}
public static void main(String args[])throws IOException
{
BookFair book = new BookFair();
book.Input( );
book.calculate( );
book.display( );
}
}

Question 5

Marks [15]

Using the switch statement, write a menu driven program for the following:
(i) To print the Floyd’s triangle [Given below] 1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

(ii) To display the following pattern
I
IC
ICS
ICSE
For an incorrect option, an appropriate error message should be displayed.

Ans.

import java.io.*;
public class FloydTriangles
{
public static void main(String args[])throws IOException
{
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Floyd Triangle MENU");
System.out.println("1. Floyd Triangle using Numbers");
System.out.println("2. Floyd Triangle Using Words");
System.out.print("Please Enter your choice: ");
int cho = Integer.parseInt(read.readLine());
int i=1,j=1;
switch(cho)
{
case 1:
System.out.println("You have choosen number 1");
int no = 1;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
System.out.print(" " +no++);
System.out.println();
}
break;
case 2:
System.out.println("You have choosen number 2");
String str = "ICSE";
int len = str.length();
for(i=1;i<=len;i++)
{
for(j=0;j<i;j++)
System.out.print(str.charAt(j));
System.out.println();
}
break;
default:
System.out.println("You have Enter a wrong option");
}
}
}

Question 6

Marks [15]

Special words are those words which start and end with the same letter.
Examples:
EXISTENCE
COMIC
WINDOW

Palindrome words are those words which read the same from left to right and vice-versa
Examples:
MAIAVALAM
MADAM
LEVEL
ROTATOR
CIVIC
All palindromes are special words, but all special words are not palindromes.
Write a program to accept a word check and print whether the word is a palindrome or only special word.
Ans.

import java.io.*;
public class PalindromeSpecial
{
public static void main(String args[])throws IOException
{
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a word to check whether it is a palindrome or special: ");
String str = read.readLine();
int len = str.length();
if (str.charAt(0) == str.charAt(len-1))
{
System.out.print("The word is a special word");
StringBuffer temp = new StringBuffer(str);
StringBuffer strr = temp.reverse(); //reversing the String
String p = new String(strr);
if(str.equalsIgnoreCase(p))
System.out.print(" and the word is a Palindrome");
else
System.out.print(" but the word is not a Palindrome");
}
else
System.out.print("The word is not a special word, hence not a Palindrome");
}
}

Question 7

Marks [15]

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

  1. void SumSeries(int n, double x) – with one integer argument and one double argument to find and display the sum of the series given below:
    mathematical expression to n terms

  2. void SumSeries( ) – To find and display the sum of the following series:
    S= 1 + (1 x 2) + (1 x 2 x 3) + .. + (1 x 2 x 3 x 4 x … … x 20)

Ans.

import java.io.*;
public class Summation
{
double s;
public Summation()
{
s = 0.0;
}
void SumSeries(int n, double x)
{
System.out.println("Display from function no. 1");
s = 0.0;
for(int i = 1; i<= n; i++)
{
if(i % 2 == 0)
s -= x / i;
else
s += x / i;
}
System.out.println("Sum of the series is " +s);
}
void SumSeries( )
{
System.out.println("Display from function no. 2");
s = 0.0;
int n = 20;
double fact = 1.0;
for(int i = 1; i<= n; i++)
{
fact = fact * i;
s = s + fact;
}
System.out.println("Sum of the series is " +s);
}
public static void main(String args[])throws IOException
{
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
Summation sum = new Summation();
System.out.print("Enter the term n: ");
int n = Integer.parseInt(read.readLine());
System.out.print("Enter the value of x: ");
double x = Double.parseDouble(read.readLine());
sum.SumSeries(n, x);
sum.SumSeries( );
}
}

Question 8

Marks [15]

Write a program to accept a number and check and display whether it is a Niven number or not.
(Niven number is that number which is divisible by its sum of digits).

Example:
Consider the number 126.
Sum of its digits is 1+2+6 = 9 and 126 is divisible by 9.
Ans.

import java.io.*;
public class NivenNumber
{
public static void main(String args[])throws IOException
{
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a word to check whether the number is Niven or not: ");
int n = Integer.parseInt(read.readLine());
int s = 0;
int temp = n;
while(temp > 0)
{
s = temp % 10 + s;
temp = temp / 10;
}
if (n % s == 0)
System.out.print("The number is a Niven Number. " 
+n +" is Divisible by " +s +" the sum of its digit");
else
System.out.print("The number is not a Niven Number");
}
}

Question 9

Marks [15]

Write a program to initialize the Seven Wonders of the World along with their locations in two different arrays. Search for a name of the country input by the user. If found, display the name of the country along with its Wonder, otherwise display “Sorry Not Found!”.

Seven wonders – CHICHEN ITZA, CHRIST THE REDEEMER, TAJMAHAL, GREAT WALL OF CHINA, MACHU PICCHU, PETRA, COLOSSEUM
Locations – MEXICO, BRAZIL, INDIA, CHINA, PERU, JORDAN, ITALY

Example – Country Name: INDIA Output: INDIA – TAJMAHAL
Country Name: USA Output; Sorry Not Found!

Ans.

import java.io.*;
public class SevenWonders
{
public static void main(String args[])throws IOException
{
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
String[] Wonders7 = new String[] {"CHICHEN ITZA", "CHRIST THE REDEEMER", 	"TAJMAHAL", "GREAT WALL OF CHINA", "MACHU PICCHU", "PETRA, 	COLOSSEUM"};
String[] Location = new String[] {"MEXICO", "BRAZIL", "INDIA", "CHINA", "PERU", 	"JORDAN", "ITALY"};
System.out.print("Enter country name: ");
String country = read.readLine();
int i = 0;
boolean contains = false;
for(i = 0; i < Location.length; i++)
{	//check if string array contains the string
if(Location[i].equals(country.toUpperCase()))
{	//string found
contains = true;
break;
}
}
if(contains)
{
System.out.println(Location[i] +" - " +Wonders7[i]);
}			
else
{
System.out.println("Sorry Not Found!");
}
}
}

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.