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

ICSE Computer Applications 2009
(Two Hours)

Attempt all questions from Section A and any four four questions from Section B. The intended marks for each question are given in brackets []

Section A

Question 1:

(a) Why is a class called a factory of objects? [2]
Ans.
A class is known as a factory of objects because objects are instantiated from classes. Each object gets a copy of the instance variables present in the class. It is like a factory producing objects.

(b) State the difference between a boolean literal and a character literal. [2]
Ans.
i) A boolean literal can store one of two values – true and false. A character literal can store a single Unicode character.
ii) The memory required by a boolean literal depends on the implementation. The memory required by a character literal is 2 bytes.

(c) What is the use and syntax of a ternary operator? [2]
Ans.
The ternary operator is a decision making operator which can be used to replace certain if else statement.
Syntax: condition ? expression1 : expression2

(d) Write one word answer for the following: [2]
i) A method that converts a string to a primitive integer data type
ii) The default initial value of a boolean variable data type
Ans.
i) Integer.parseInt()
ii) false

(e) State one similarity and one difference between while and for loop. [2]
Ans.
A while loop contains only a condition while a for loop contains initialization, condition and iteration.

Question 2:

(a) Write the function prototype for the function “sum” that takes an integer variable (x) as its argument and returns a value of float data type. [2]
Ans.

public float sum(int x)

(b) What is the use of the keyword this? [2]
Ans.
this refers to the object on which the method has been invoked. If an instance variable and a local variable in a method have the same name, the local variable hides the instance variable. The keyword this can be used to access the instance variable as shown in the example below:

public class thisKeywordExample {

    int a; // varaible 1

    public void method() {
        int a; // variable 2
        a = 4; // varaible 1 will be changed
        a = 3; // varaible 2 will be changed

    }
}

(c) Why is a class known as a composite data type? [2]
Ans.
A class is composed of instance variables which are of different data types. hence, a class can be viewed as a composite data type which is composed of primitive and other composite data types.

(d) Name the keyword that: [2]
i) is used for allocating memory to an array
ii) causes the control to transfer back to the method call
Ans. i) new
ii) return

(e) Differentiate between pure and impure functions. [2]
Ans. i) A pure function does not change the state of the object whereas an impure function changes the state of the object by modifying instance variables.
ii) get functions are examples of pure functions and set functions are examples if impure functions.

Question 3:
(a) Write an expression for 2009 paper question 3 a expression image [2]
Ans. (Math.pow(a+b),n)/(Math.sqrt(3)+b)

(b) The following is a segment of a program.

x = 1; y = 1;
if(n > 0)
{
    x = x + 1;
    y = y - 1;
}

What will be the value of x and y, if n assumes a value (i) 1 (ii) 0? [2]
Ans. i) 1 > 0 is true, so if block will be executed.
x = x + 1 = 1 + 1 = 2
y = y – 1 = 1 – 1 = 0
ii) 0 > 0 is false, so if block will not be executed and therefore, the values of x and y won’t change.
x = 1
y = 1

(c) Analyze the following program segment and determine how many times the body of loop will be executed (show the working). [2]

x = 5; y = 50;
while(x<=y)
{
    y=y/x;
    System.out.println(y);
}

Ans.

Iteration 1 :   5 <= 50 - true     y = y / x = 50 / 5 = 10   10 will be printed
Iteration 2 :   5 <= 10 - true     y = y / x = 10 / 5 = 2     2 will be printed
Iteration 3 :   5 <= 2  - false

The loop will be executed two times.

(d) When there are multiple definitions with the same function name, what makes them different from each other? [2]
Ans. The function prototype make multiple definitions of a function different from each other. Either the number, type or order or arguments should be different for the functions having identical names.

Q3. (e) Given that int x[][] = { {2,4,6}, {3,5,7} };
What will be the value of x[1][0] and x[0][2] ? [2]
Ans. We can write the array as
2009 paper question 3 e multi dimensional array image
As shown in the figure x[1][0] is 3 and x[0][2] is 6.

(f) Give the output of the following code segment when (i) opn = ‘b’ (ii) opn = ‘x’ (iii) opn = ‘a’. [3]

switch(opn)
{
    case 'a':
      System.out.println("Platform Independent");
      break;
    case 'b':
      System.out.println("Object Oriented");
    case 'c':
      System.out.println("Robust and Secure");
      break;
    default:
      System.out.println("Wrong Input");
}

Ans. i) Output will be

Object Oriented
Robust and Secure

As there is no break statement for case ‘b’, statements in case ‘c’ will also be printed when opn = ‘b’.
ii) Output will be

Wrong Input

As ‘x’ doesn’t match with either ‘a’, ‘b’ or ‘c’, the default statement will be executed.
iii) Output will be

Platform Independent

(g) Consider the following code and answer the questions that follow: [4]

class academic
{
    int x, y;
    void access()
    {
        int a, b;
        academic student = new academic();
        System.out.println("Object created");
    }
}

i) What is the object name of class academic?
ii) Name the class variables used in the program?
iii) Write the local variables used in the program.
iv) Give the type of function used and its name.
Ans. i) student
ii) x and y
iii) a and b
iv) Type: Non Static
Name: access

Q3 (h) Convert the following segment into an equivalent do loop. [3]

int x,c;
for(x=10,c=20;c>10;c=c-2)
x++;

Ans.

int x, c;
x = 10;
c = 20;
do {
    x++;
    c = c - 2;
} while (c > 10);


Section B

Question 4
An electronics shop has announced the following seasonal discounts on the purchase of certain items.

Purchase Amount in Rs. Discount on Laptop Discount on Desktop PC
0 – 25000 0.0% 5.0%
25001 – 57000 5.0% 7.6%
57001 – 100000 7.5% 10.0%
More than 100000 10.0% 15.0%

Write a program based on the above criteria to input name, address, amount of purchase and type of purchase (L for Laptop and D for Desktop) by a customer. Compute and print the net amount to be paid by a customer along with his name and address. [15]

(Hint: discount = (discount rate/100)* amount of purchase

Net amount = amount of purchase – discount)

Ans.

import java.util.Scanner;

public class Electronics {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter name: ");
        String name = scanner.nextLine();
        System.out.print("Enter address: ");
        String address = scanner.nextLine();
        System.out.print("Enter type of purchase: ");
        String type = scanner.nextLine();
        System.out.print("Enter amount of purchase: ");
        int amount = scanner.nextInt();
        double discountRate = 0.0;
        if (type.equals("L")) {
            if (amount <= 25000) {
                discountRate = 0;
            } else if (amount >= 25001 && amount <= 57000) {
                discountRate = 5.0;
            } else if (amount >= 57001 && amount <= 100000) {
                discountRate = 7.5;
            } else if (amount > 100000) {
                discountRate = 10.0;
            }
        } else if (type.equals("D")) {
            if (amount <= 25000) {
                discountRate = 5.0;
            } else if (amount >= 25001 && amount <= 57000) {
                discountRate = 7.6;
            } else if (amount >= 57001 && amount <= 100000) {
                discountRate = 10.0;
            } else if (amount > 100000) {
                discountRate = 15.0;
            }
        }
        double discount = (discountRate / 100) * amount;
        double netAmount = amount - discount;
        System.out.println("Name: " + name);
        System.out.println("Address: " + address);
        System.out.println("Net Amount: " + netAmount);
    }

}

Sample Output:

Enter name: Ram
Enter address: 12-5/6
Enter type of purchase: L
Enter amount of purchase: 200000
Name: Ram
Address: 12-5/6
Net Amount: 180000.0


Question 5:
Write a program to generate a triangle or an inverted triangle till n terms based upon the user’s choice of triangle to be displayed. [15]

Example 1
Input: Type 1 for a triangle and
type 2 for an inverted triangle
1
Enter the number of terms
5
Output:
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

Example 2:
Input: Type 1 for a triangle and
type 2 for an inverted triangle
2
Enter the number of terms
6
Output:
6 6 6 6 6 6
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1

Ans.

import java.util.Scanner;

public class Traingle {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Type 1 for a triangle and type 2 for an inverted triangle: ");
        int choice = scanner.nextInt();
        System.out.print("Enter number of terms: ");
        int n = scanner.nextInt();
        if (choice == 1) {
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= i; j++) {
                    System.out.print(i + " ");
                }
                System.out.println();
            }
        } else if (choice == 2) {
            for (int i = n; i >= 1; i--) {
                for (int j = 1; j <= i; j++) {
                    System.out.print(i + " ");
                }
                System.out.println();
            }
        }
    }

}


Question 6:
Write a program to input a sentence and print the number of characters found in the longest word of the given sentence.
For example is S = “India is my country” then the output should be 7. [15]

Ans.

import java.util.Scanner;

public class LongestWord {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter a sentence: ");
        String sentence = scanner.nextLine();
        int longest = 0;
        int currentWordLength = 0;
        for (int i = 0; i < sentence.length(); i++) {
            char ch = sentence.charAt(i);
            if (ch == ' ') {
                if (currentWordLength > longest) {
                    longest = currentWordLength;
                }
                currentWordLength = 0;
            } else {
                currentWordLength++;
            }
        }
        if (currentWordLength > longest) {
            longest = currentWordLength;
        }
        System.out.println("The longest word has " + longest + " characters");
    }
}


Question 7:

Write a class to overload a function num_calc() as follows: [15]

i) void num_calc(int num, char ch) with one integer argument and one character argument, computes the square of integer argument if choice ch is ‘s’ otherwise finds its cube.

ii) void num_calc(int a, int b, char ch) with two integer arguments and one character argument. It computes the product of integer arguments if ch is ‘p’ else adds the integers.

iii) void num_calc(String s1, String s2) with two string arguments, which prints whether the strings are equal or not.

Ans.

public class Overloading {

    public void num_calc(int num, char ch) {
        if (ch == 's') {
            double square = Math.pow(num, 2);
            System.out.println("Square is " + square);
        } else {
            double cube = Math.pow(num, 3);
            System.out.println("Cube is " + cube);
        }
    }

    public void num_calc(int a, int b, char ch) {
        if (ch == 'p') {
            int product = a * b;
            System.out.println("Product is " + product);
        } else {
            int sum = a + b;
            System.out.println("Sum is " + sum);
        }
    }

    public void num_calc(String s1, String s2) {
        if (s1.equals(s2)) {
            System.out.println("Strings are same");
        } else {
            System.out.println("Strings are different");
        }
    }
}


Question 8
Write a menu driven program to access a number from the user and check whether it is a BUZZ number or to accept any two numbers and to print the GCD of them. [15]

a) A BUZZ number is the number which either ends with 7 is is divisible by 7.

b) GCD (Greatest Common Divisor) of two integers is calculated by continued division method. Divide the larger number by the smaller; the remainder then divides the previous divisor. The process is repeated till the remainder is zero. The divisor then results the GCD.

Ans.

import java.util.Scanner;

public class Menu {

    public boolean isBuzzNumber(int num) {
        int lastDigit = num % 10;
        int remainder = num % 7;
        if (lastDigit == 7 || remainder == 0) {
            return true;
        } else {
            return false;
        }
    }

    public int gcd(int a, int b) {
        int dividend, divisor;
        if (a > b) {
            dividend = a;
            divisor = b;
        } else {
            dividend = b;
            divisor = a;
        }
        int gcd;
        while (true) {
            int remainder = dividend % divisor;
            if (remainder == 0) {
                gcd = divisor;
                break;
            }
            dividend = divisor;
            divisor = remainder;
        }
        return gcd;
    }

    public void menu() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("1. Buzz Number");
        System.out.println("2. GCD");
        System.out.print("Enter your choice: ");
        int choice = scanner.nextInt();
        if (choice == 1) {
            System.out.print("Enter a number: ");
            int num = scanner.nextInt();
            if (isBuzzNumber(num)) {
                System.out.println(num + " is a buzz number");
            } else {
                System.out.println(num + " is not a buzz number");
            }
        } else if (choice == 2) {
            System.out.print("Enter two numbers: ");
            int num1 = scanner.nextInt();
            int num2 = scanner.nextInt();
            int gcd = gcd(num1, num2);
            System.out.println("GCD: " + gcd);
        } else {
            System.out.println("Invalid Choice");
        }
    }

    public static void main(String[] args) {
        Menu menu = new Menu();
        menu.menu();
    }

}

Sample Output 1:

1. Buzz Number
2. GCD
Enter your choice: 1
Enter a number: 49
49 is a buzz number

Sample Output 2:

1. Buzz Number
2. GCD
Enter your choice: 2
Enter two numbers: 49 77
GCD: 7


Question 9
The annual examination results of 50 students in a class is tabulated as follows.

Roll no.  Subject A  Subject B  Subject C

Write a program to read the data, calculate and display the following:

a) Average mark obtained by each student.
b) Print the roll number and average marks of the students whose average mark is above 80.
c) Print the roll number and average marks of the students whose average mark is below 40.

Ans.

import java.util.Scanner;

public class StudentMarks {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] rno = new int[50];
        int[] subjectA = new int[50];
        int[] subjectB = new int[50];
        int[] subjectC = new int[50];
        double[] average = new double[50];
        for (int i = 0; i < 50; i++) {
            System.out.print("Enter Roll No: ");
            rno[i] = scanner.nextInt();
            System.out.print("Enter marks in subject A: ");
            subjectA[i] = scanner.nextInt();
            System.out.print("Enter marks in subject B: ");
            subjectB[i] = scanner.nextInt();
            System.out.print("Enter marks in subject C: ");
            subjectC[i] = scanner.nextInt();
            average[i] = (subjectA[i] + subjectB[i] + subjectC[i]) / 3.0;
        }
        System.out.println("Roll No - Average");
        for (int i = 0; i < 50; i++) {
            System.out.println(rno[i] + " - " + average[i]);
        }
        System.out.println("Students with average greater than 80");
        for (int i = 0; i < 50; i++) {
            if (average[i] > 80) {
                System.out.println(rno[i] + " - " + average[i]);
            }
        }
        System.out.println("Students with average less than 40");
        for (int i = 0; i < 50; i++) {
            if (average[i] < 40) {
                System.out.println(rno[i] + " - " + average[i]);
            }
        }
    }
}

Sample Output:

run:
Enter Roll No: 1
Enter marks in subject A: 100
Enter marks in subject B: 100
Enter marks in subject C: 97
Enter Roll No: 2
Enter marks in subject A: 10
Enter marks in subject B: 10
Enter marks in subject C: 10
Enter Roll No: 3
Enter marks in subject A: 50
Enter marks in subject B: 50
Enter marks in subject C: 50
...
Roll No - Average
1 - 99.0
2 - 10.0
3 - 50.0
...
Students with average greater than 80
1 - 99.0
Students with average less than 40
2 - 10.0
...

One thought on “ICSE Class 10 Computer Applications ( Java ) 2009 Solved Question Paper

  1. Deepika

    In section A, ques g,
    Since x and y haven’t been declared using keyword static,Aren’t they instance variables?

    Reply

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>