ICSE Class 10 Computer Applications ( Java ) 2012 Solved Question Paper

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) Give one example each of a primitive data type and a composite data type. [2]
Ans. Primitive Data Types – byte, short, int, long, float, double, char, boolean
Composite Data Type – Class, Array, Interface

(b) Give one point of difference between unary and binary operators. [2]
Ans. A unary operator requires a single operand whereas a binary operator requires two operands.
Examples of Unary Operators – Increment ( ++ ) and Decrement ( — ) Operators
Examples of Binary Operators – +, -, *, /, %

(c) Differentiate between call by value or pass by value and call by reference or pass by reference. [2]
Ans. In call by value, a copy of the data item is passed to the method which is called whereas in call by reference, a reference to the original data item is passed. No copy is made. Primitive types are passed by value whereas reference types are passed by reference.

(d) Write a Java expression for (under root of 2as+u2) [2]
Ans. Math.sqrt ( 2 * a * s + Math.pow ( u, 2 ) )
( or )
Math.sqrt ( 2 * a * s + u * u )

(e) Name the types of error (syntax, runtime or logical error) in each case given below:
(i) Division by a variable that contains a value of zero.
(ii) Multiplication operator used when the operation should be division.
(iii) Missing semicolon. [2]

Ans.
(i) Runtime Error
(ii) Logical Error
(iii) Syntax Error

Question 2

(a)Create a class with one integer instance variable. Initialize the variable using:
(i) default constructor
(ii) parameterized constructor. [2]

Ans.

public class Integer {

    int x;

    public Integer() {
        x = 0;
    }

    public Integer(int num) {
        x = num;
    }
}

(b)Complete the code below to create an object of Scanner class.
Scanner sc = ___________ Scanner( ___________ ) [2]

Ans. Scanner sc = new Scanner ( System.in )

(c) What is an array? Write a statement to declare an integer array of 10 elements. [2]
Ans. An array is a reference data used to hold a set of data of the same data type. The following statement declares an integer array of 10 elements -
int arr[] = new int[10];

(d) Name the search or sort algorithm that:
(i) Makes several passes through the array, selecting the next smallest item in the array each time and placing it where it belongs in the array.
(ii) At each stage, compares the sought key value with the key value of the middle element of the array. [2]

Ans. (i) Selection Sort
(ii) Binary Search

(e) Differentiate between public and private modifiers for members of a class. [2]
Ans. Variables and Methods whwith the public access modie the class also.

Question 3

(a) What are the values of x and y when the following statements are executed? [2]

int a = 63, b = 36;
boolean x = (a < b ) ? true : false; int y= (a > b ) ? a : b ;

Ans. x = false
y = 63

(b) State the values of n and ch [2]

char c = 'A':
int n = c + 1; 

Ans. The ASCII value for ‘A’ is 65. Therefore, n will be 66.

(c) What will be the result stored in x after evaluating the following expression? [2]

int x=4;
x += (x++) + (++x) + x;

Ans. x = x + (x++) + (++x) + x
x = 4 + 4 + 6 + 6
x = 20

(d) Give the output of the following program segment: [2]

double x = 2.9, y = 2.5;
System.out.println(Math.min(Math.floor(x), y));
System.out.println(Math.max(Math.ceil(x), y));

Ans.
2.0
3.0
Explanation : Math.min(Math.floor(x), y) = Math.min ( 2.0, 2.5 ) = 2.0
Math.max(Math.ceil(x), y)) = Math.max ( 3.0, 2.5 ) = 3.0

(e) State the output of the following program segment. [2]

String s = "Examination";
int n = s.length();
System.out.println(s.startsWith(s.substring(5, n)));
System.out.println(s.charAt(2) == s.charAt(6));

Ans.
false
true
Explanation : n = 11
s.startsWith(s.substring(5, n)) = s.startsWith ( “nation” ) = false
( s.charAt(2) == s.charAt(6) ) = ( ‘a’== ‘a’ ) = true

(f) State the method that:
(i) Converts a string to a primitive float data type
(ii) Determines if the specified character is an uppercase character [2]

Ans. (i) Float.parseFloat(String)
(ii) Character.isUpperCase(char)

(g) State the data type and values of a and b after the following segment is executed.[2]

String s1 = "Computer", s2 = "Applications";
a = (s1.compareTo(s2));
b = (s1.equals(s2));

Ans. Data type of a is int and b is boolean.
ASCII value of ‘C’ is 67 and ‘A’ is 65. So compare gives 67-65 = 2.
Therefore a = 2
b = false

(h) What will the following code output? [2]

 String s = "malayalam";
 System.out.println(s.indexOf('m'));
 System.out.println(s.lastIndexOf('m'));

Ans.
0
8

(i) Rewrite the following program segment using while instead of for statement [2]

int f = 1, i;
for (i = 1; i <= 5; i++) {
    f *= i;
    System.out.println(f);
}

Ans.

int f = 1, i = 1;
while (i <= 5) {
    f *= i;
    System.out.println(f);
    i++;
}

(j) In the program given below, state the name and the value of the
(i) method argument or argument variable
(ii) class variable
(iii) local variable
(iv) instance variable [2]

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);
}
}

Ans. (i) name = n value =5
(ii) name = y value = 7
(iii) name = a value = 6
(iv) name = obj value = new MyClass()

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 so that the logic of the program is clearly depicted.
Flow-Charts and Algorithms are not required.

Question 4

Define a class called Library with the following description:
Instance variables/data members:
Int acc_num – stores the accession number of the book
String title – stores the title of the book stores the name of the author
Member Methods:
(i) void input() – To input and store the accession number, title and author.
(ii)void compute – To accept the number of days late, calculate and display and fine charged at the rate of Rs.2 per day.
(iii) void display() To display the details in the following format:
Accession Number Title Author
Write a main method to create an object of the class and call the above member methods. [ 15]

Ans.

public class Library {

    int acc_num;
    String title;
    String author;

    public void input() throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.print("Enter accession number: ");
        acc_num = Integer.parseInt(br.readLine());
        System.out.print("Enter title: ");
        title = br.readLine();
        System.out.print("Enter author: ");
        author = br.readLine();
    }

    public void compute() throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.print("Enter number of days late: ");
        int daysLate = Integer.parseInt(br.readLine());;
        int fine = 2 * daysLate;
        System.out.println("Fine is Rs " + fine);
    }

    public void display() {
        System.out.println("Accession Number\tTitle\tAuthor");
        System.out.println(acc_num + "\t" + title + "\t" + author);
    }

    public static void main(String[] args) throws IOException {
        Library library = new Library();
        library.input();
        library.compute();
        library.display();
    }
}

Question 5

Given below is a hypothetical table showing rates of Income Tax for male citizens below the age of 65 years:

Taxable Income (TI) in Income Tax in
Does not exceed 1,60,000 Nil
Is greater than 1,60,000 and less than or equal to 5,00,000 ( TI – 1,60,000 ) * 10%
Is greater than 5,00,000 and less than or equal to 8,00,000 [ (TI - 5,00,000 ) *20% ] + 34,000
Is greater than 8,00,000 [ (TI - 8,00,000 ) *30% ] + 94,000

Write a program to input the age, gender (male or female) and Taxable Income of a person.If the age is more than 65 years or the gender is female, display “wrong category*.
If the age is less than or equal to 65 years and the gender is male, compute and display the Income Tax payable as per the table given above. [15]
Ans.

import java.util.Scanner;

public class IncomeTax {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter age: ");
        int age = scanner.nextInt();
        System.out.print("Enter gender: ");
        String gender = scanner.next();
        System.out.print("Enter taxable income: ");
        int income = scanner.nextInt();
        if (age > 65 || gender.equals("female")) {
            System.out.println("Wrong category");
        } else {
            double tax;
            if (income <= 160000) {                 tax = 0;             } else if (income > 160000 && income <= 500000) {                 tax = (income - 160000) * 10 / 100;             } else if (income >= 500000 && income <= 800000) {
                tax = (income - 500000) * 20 / 100 + 34000;
            } else {
                tax = (income - 800000) * 30 / 100 + 94000;
            }
            System.out.println("Income tax is " + tax);
        }
    }
}

Question 6

Write a program to accept a string. Convert the string to uppercase. Count and output the number of double letter sequences that exist in the string.
Sample Input: “SHE WAS FEEDING THE LITTLE RABBIT WITH AN APPLE
Sample Output: 4 [ 15]

Ans.

import java.util.Scanner;

public class StringOperations {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter a String: ");
        String input = scanner.nextLine();
        input = input.toUpperCase();
        int count = 0;
        for (int i = 1; i < input.length(); i++) {
            if (input.charAt(i) == input.charAt(i - 1)) {
                count++;
            }
        }
        System.out.println(count);
    }
}

Question 7

Design a class to overload a function polygon() as follows:
(i) void polygon(int n, char ch) : with one integer argument and one character type argument that draws a filled square of side n using the character stored in ch.
(ii) void polygon(int x, int y) : with two integer arguments that draws a filled rectangle of length x and breadth y, using the symbol ‘@’
(iii)void polygon( ) : with no argument that draws a filled triangle shown below.

Example:
(i) Input value of n=2, ch=’O’
Output:
OO
OO
(ii) Input value of x=2, y=5
Output:
@@@@@
@@@@@
(iii) Output:
*
**
*** [15]

Ans.

public class Overloading {

    public void polygon(int n, char ch) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                System.out.print(ch);
            }
            System.out.println();
        }
    }

    public void polygon(int x, int y) {
        for (int i = 1; i <= x; i++) {
            for (int j = 1; j <= y; j++) {
                System.out.print("@");
            }
            System.out.println();
        }
    }

    public void polygon() {
        for (int i = 1; i <= 3; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }
}

Question 8

Using the switch statement, writw a menu driven program to:
(i) Generate and display the first 10 terms of the Fibonacci series 0,1,1,2,3,5….The first two Fibonacci numbers are 0 and 1, and each subsequent number is the sum of the previous two.
(ii)Find the sum of the digits of an integer that is input.
Sample Input: 15390
Sample Output: Sum of the digits=18
For an incorrect choice, an appropriate error message should be displayed [15]

Ans.

import java.util.Scanner;

public class Menu {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Menu");
        System.out.println("1. Fibonacci Sequence");
        System.out.println("2. Sum of Digits");
        System.out.print("Enter choice: ");
        int choice = scanner.nextInt();
        switch (choice) {
            case 1:
                int a = 0;
                int b = 1;
                System.out.print("0 1 ");
                for (int i = 3; i <= 10; i++) {                     int c = a + b;                     System.out.print(c + " ");                     a = b;                     b = c;                 }                 break;             case 2:                 System.out.print("Enter a number: ");                 int num = scanner.nextInt();                 int sum = 0;                 while (num > 0) {
                    int rem = num % 10;
                    sum = sum + rem;
                    num = num / 10;
                }
                System.out.println("Sum of digits is " + sum);
                break;
            default:
                System.out.println("Invalid Choice");
        }
    }
}

Question 9

Write a program to accept the names of 10 cities in a single dimension string array and their STD (Subscribers Trunk Dialing) codes in another single dimension integer array. Search for a name of a city input by the user in the list. If found, display “Search Successful” and print the name of the city along with its STD code, or else display the message “Search Unsuccessful, No such city in the list’. [15]

Ans.

import java.util.Scanner;

public class Cities {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] cities = new String[10];
        int[] std = new int[10];
        for (int i = 0; i < 10; i++) {
            System.out.print("Enter city: ");
            cities[i] = scanner.next();
            System.out.print("Enter std code: ");
            std[i] = scanner.nextInt();
        }
        System.out.print("Enter city name to search: ");
        String target = scanner.next();
        boolean searchSuccessful = false;
        for (int i = 0; i < 10; i++) {
            if (cities[i].equals(target)) {
                System.out.println("Search successful");
                System.out.println("City : " + cities[i]);
                System.out.println("STD code : " + std[i]);
                searchSuccessful = true;
                break;
            }
        }
        if (!searchSuccessful) {
            System.out.println("Search Unsuccessful, No such city in the list");
        }
    }
}

3 thoughts on “ICSE Class 10 Computer Applications ( Java ) 2012 Solved Question Paper

Leave a Reply

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


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>