## ICSE Class 10 Computer Applications ( Java ) 2013 Solved Question Paper

**If you have any doubts, ask them in the comments section at the bottom of this page.**

**ICSE Paper – 2013**

**Class – X**

**Subject – Computer Applications**

**(Two Hours)**

**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)**

**Question 1**

**a) What is meant by precedence of operators? [2]**

**Ans.** Precedence of operators refers to the order in which the operators are applied to the operands in an expression. For example, * has higher precedence than +. So, the expression 8 + 2 * 5 will evaluate to 8 + 10 = 18

**b) What is a literal? [2]**

**Ans.** A literal is a constant data item. There are different literals like integer literals, floating point literals and character literals.

**c) State the Java concept that is implemented through:**

**i) a super class and a subclass.**

**ii) the act of representing essential features without including background details. [2]**

**Ans.** i) Inheritance

ii) Abstraction

**d) Give a difference between constructor and method. [2]**

**Ans.** i)A constructor has no return type which a method has a return type.

ii) The name of the constructor should be the same as that of the class while the name of a method can be any valid identifier.

iii) A constructor is automatically called upon object creation while methods are invoked explicitly.

**e) What are the types of casting shown by the following examples? [2]**

**i) double x =15.2;**

**int y =(int) x;**

**ii) int x =12;**

**long y = x;**

**Ans.** i) Explicit casting

ii) Implicit casting

**Question 2:**

**a) Name any two wrapper classes. [2]**

**Ans.** Byte, Short, Integer, Long, Float, Double, Boolean, Character

**b) What is the difference between break and continue statements when they occur in a loop. [2]**

**Ans.** The break statement terminates the loop while the continue statements current iteration of the loop to be skipped and continues with the next iteration.

**c) Write statements to show how finding the length of a character array and char[] differs from finding the length of a String object str. [2]**

**Ans.** The length of a character array is found by accessing the length attribute of the array as shown below:

char[] array = new char[7];

int lengthOfCharArray = array.length;

The length of a String object is found by invoking the length() method which returns the length as an int.

String str = “java”;

int lengthOfString = str.length();

**d) Name the Java keyword that: [2]**

**(i) indicates a method has no return type.**

**(ii) stores the address of the currently calling object.**

**Ans.** i) void

ii) this

**e) What is an exception? [2]**

**Ans.** An exception is an unforeseen situation that occurs during the execution of a program. In simpler words, they are the errors that occur during the execution of a program. The JRE throws an Exception object to indicate an exception which contains the information related to that exception.

**Question 3:**

**a) Write Java statement to create an object mp4 of class digital. [2]**

**Ans.**

digital mp4 = new digital();

**b) State the values stored in variables str1 and str2 [2]**

String s1 = "good"; String s2="world matters"; String str1 = s2.substring(5).replace('t','n'); String str2 = s1.concat(str1);

**Ans.** s2.substring(5) gives ” matters”. When ‘t’ is replaced with ‘n’, we get ” manners”.

“good” when concatenated with ” manners” gives “good manners”.

So, str1 = ” manners” and str2 = “good manners”.

**c) What does a class encapsulate? [2]**

**Ans.** A class encapsulated the data (instance variables) and methods.

**d) Rewrite the following program segment using the if..else statement. [2]**

comm =(sale>15000)?sale*5/100:0;

**Ans**.

if ( sale > 15000 ) { comm = sale * 5 / 100; } else { comm = 0; }

**e) How many times will the following loop execute? What value will be returned? [2]**

int x = 2, y = 50; do{ ++x; y-=x++; }while(x<=10); return y;

**Ans**. In the first iteration, ++x will change x from 2 to 3. y-=x++ will increase x to 4. And y becomes 50-3=47.

In the second iteration, ++x will change x from 4 to 5. y-=x++ will increase x to 6. And y becomes 47-5=42.

In the third iteration, ++x will change x from 6 to 7. y-=x++ will increase x to 8. And y becomes 42-7=35.

In the fourth iteration, ++x will change x from 8 to 9. y-=x++ will increase x to 10. And y becomes 35-9=26.

In the fifth iteration, ++x will change x from 10 to 11. y-=x++ will increase x to 12. And y becomes 26-11=15.

Now the condition x<=10 fails.

So, the loop executes five times and the value of y that will be returned is 15.

**f) What is the data type that the following library functions return? [2]**

**i) isWhitespace(char ch)**

**ii) Math.random()**

**Ans**. i) boolean

ii) double

**g) Write a Java expression for ut + ½ ft2 [2]**

**Ans.** u * t + 0.5 * f * Math.pow ( t, 2)

**h) If int n[] ={1, 2, 3, 5, 7, 9, 13, 16} what are the values of x and y? [2]**

x=Math.pow(n[4],n[2]); y=Math.sqrt(n[5]+[7]);

**Ans.** n[4] is 7 and n[2] is 3. So, Math.pow(7,3) is 343.0.

n[5] is 9 and n[7] is 16. So Math.sqrt(9+16) will give 5.0.

Note that pow() and sqrt() return double values and not int values.

**i) What is the final value of ctr after the iteration process given below, executes? [2]**

int ctr=0; for(int i=1;i<=5;i++) for(int j=1;j<=5;j+=2) ++ctr;

**Ans.** Outer loop runs five times. For each iteration of the outer loop, the inner loop runs 3 times. So, the statement ++ctr executes 5*3=15 times and so the value of ctr will be 15.

**j) Name the methods of Scanner class that: [2]**

**i) is used to input an integer data from standard input stream.**

**ii) is used to input a string data from standard input stream.**

**Ans.** i) nextInt()

ii) nextLine()

## SECTION B (60 Marks )

**Attempt any four questions from this Section.**

**The answers in this section should consist of the program in Blue J environment with Java as the base. Each program should be written using Variable descriptions / Mnemonics Codes such that the logic of the program is clearly depicted.**

**Flow-charts and Algorithms are not required.**

**Question 4:**

**Define a class called FruitJuice with the following description: [15]**

**Instance variables/data members:**

**int product_code – stores the product code number**

**String flavour – stores the flavor of the juice.(orange, apple, etc)**

**String pack_type – stores the type of packaging (tetra-pack, bottle etc)**

**int pack_size – stores package size (200ml, 400ml etc)**

**int product_price – stores the price of the product**

**Member Methods:**

**FriuitJuice() – default constructor to initialize integer data members**

**to zero and string data members to “”.**

**void input() – to input and store the product code, flavor, pack type,**

**pack size and product price.**

**void discount() – to reduce the product price by 10.**

**void display() – to display the product code, flavor, pack type,**

**pack size and product price.**

**Ans.**

import java.util.Scanner; public class FruitJuice { int product_code; String flavour; String pack_type; int pack_size; int product_price; public FruitJuice() { product_code = 0; flavour = ""; pack_type = ""; pack_size = 0; product_price = 0; } public void input() { Scanner kb = new Scanner(System.in); System.out.print("Enter product code: "); product_code = kb.nextInt(); System.out.print("Enter flavour: "); flavour = kb.next(); System.out.print("Enter pack type: "); pack_type = kb.next(); System.out.print("Enter pack size: "); pack_size = kb.nextInt(); System.out.print("Enter product price: "); product_price = kb.nextInt(); } public void discount() { product_price = (int) (0.9 * product_price); } public void display() { System.out.println("Product Code: " + product_code); System.out.println("Flavour: " + flavour); System.out.println("Pack Type: " + pack_type); System.out.println("Pack Size: " + pack_size); System.out.println("Product Price: " + product_price); } }

**Question 5:**

**The International Standard Book Number (ISBN) is a unique numeric book identifier which is printed on every book. The ISBN is based upon a 10-digit code. The ISBN is legal if:**

**1xdigit1 + 2xdigit2 + 3xdigit3 + 4xdigit4 + 5xdigit5 + 6xdigit6 + 7xdigit7 + 8xdigit8 + 9xdigit9 + 10xdigit10 is divisible by 11.**

**Example: For an ISBN 1401601499**

**Sum=1×1 + 2×4 + 3×0 + 4×1 + 5×6 + 6×0 + 7×1 + 8×4 + 9×9 + 10×9 = 253 which is divisible by 11.**

**Write a program to:**

**(i) input the ISBN code as a 10-digit integer.**

**(ii) If the ISBN is not a 10-digit integer, output the message “Illegal ISBN” and terminate the program.**

**(iii) If the number is 10-digit, extract the digits of the number and compute the sum as explained above.**

**If the sum is divisible by 11, output the message, “Legal ISBN”. If the sum is not divisible by 11, output the message, “Illegal ISBN”. [15]**

**Ans.**

The data type of ISBN should be long instead of int as the maximum value of an int is 2,147,483,647 which is less than 9999999999 – the maximum possible value of an ISBN.

import java.util.Scanner; public class ISBN { public static void main(String[] args) { Scanner kb = new Scanner(System.in); System.out.print("Enter ISBN code: "); long isbnInteger = kb.nextLong(); String isbn = isbnInteger + ""; if (isbn.length() != 10) { System.out.println("Ilegal ISBN"); } else { int sum = 0; for (int i = 0; i < 10; i++) { int digit = Integer.parseInt(isbn.charAt(i) + ""); sum = sum + (digit * (i + 1)); } if (sum % 11 == 0) { System.out.println("Legal ISBN"); } else { System.out.println("Illegal ISBN"); } } } }

**Question 6:**

**Write a program that encodes a word into Piglatin. To translate word into Piglatin word, convert the word into uppercase and then place the first vowel of the original word as the start of the new word along with the remaining alphabets. The alphabets present before the vowel being shifted towards the end followed by “AY”.**

**Sample Input(1): London Sample Output(1): ONDONLAY**

**Sample Input(2): Olympics Sample Output(2): OLYMPICSAY [15]**

Ans.

import java.util.Scanner; public class Piglatin { public static void main(String[] args) { Scanner kb = new Scanner(System.in); System.out.print("Enter a String: "); String input = kb.next(); input = input.toUpperCase(); String piglatin = ""; boolean vowelFound = false; for (int i = 0; i < input.length(); i++) { char c = input.charAt(i); if ((c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U') && !vowelFound) { piglatin = c + piglatin; vowelFound = true; } else { piglatin = piglatin + c; } } piglatin = piglatin + "AY"; System.out.println("Piglatin word is " + piglatin); } }

**Question 7:**

**Write a program to input 10 integer elements in an array and sort them**

**In descending order using bubble sort technique. [15]**

**Ans.**

import java.util.Scanner; public class BubbleSort { public static void main(String[] args) { Scanner kb = new Scanner(System.in); System.out.println("Enter ten numbers:"); int[] numbers = new int[10]; for (int i = 0; i < 10; i++) { numbers[i] = kb.nextInt(); } for (int i = 0; i < 10; i++) { for (int j = 0; j < 10 - i - 1; j++) { if (numbers[j] < numbers[j + 1]) { int temp = numbers[j]; numbers[j] = numbers[j + 1]; numbers[j + 1] = temp; } } } System.out.println("Sorted Numbers:"); for (int i = 0; i < 10; i++) { System.out.println(numbers[i]); } } }

**Question 8:**

**Design a class to overload a function series() as follows: [15]**

**(i) double series(double n) with one double argument and returns the sum of the series.**

**sum = 1/1 + 1/2 + 1/3 + ….. 1/n**

**(ii) double series(double a, double n) with two double arguments and returns the sum of the series.**

**sum = 1/a2 + 4/a5 + 7/a8 + 10/a11 ….. to n terms**

Ans.

public class Overload { public double series(double n) { double sum = 0; for (int i = 1; i <= n; i++) { sum = sum + (1.0 / i); } return sum; } public double series(double a, double n) { double sum = 0; for (int i = 0; i < n; i++) { sum = sum + ((3 * i + 1.0) / Math.pow(a, 3 * i + 2)); } return sum; } }

**Question 9:**

**Using the switch statement, write a menu driven program: [15]**

**(i) To check and display whether a number input by the user is**

**a composite number or not (A number is said to be a composite, if it**

**has one or more then one factors excluding 1 and the number itself).**

**Example: 4, 6, 8, 9…**

**(ii) To find the smallest digit of an integer that is input:**

**Sample input: 6524**

**Sample output: Smallest digit is 2**

**For an incorrect choice, an appropriate error message should be displayed.**

**Ans.**

import java.util.Scanner; public class Menu { public static void main(String[] args) { Scanner kb = new Scanner(System.in); System.out.println("Menu"); System.out.println("1. Check composite number"); System.out.println("2. Find smallest digit of a number"); System.out.print("Enter your choice: "); int choice = kb.nextInt(); switch (choice) { case 1: System.out.print("Enter a number: "); int number = scanner.nextInt(); if(isComposite(number)) { System.out.println("It is a composite number"); } else { System.out.println("It is not a composite number"); } break; case 2: System.out.print("Enter a number: "); int num = scanner.nextInt(); int smallest = smallestDigit(num); System.out.println("Smallest digit is " + smallest); break; default: System.out.println("Incorrect choice"); break; } } public static boolean isComposite(int n) { for (int i = 2; i < n; i++) { if (n % i == 0) { return true; } } return false; } public static int smallestDigit(int number) { int smallest = 9; while (number > 0) { int rem = number % 10; if (rem < smallest) { smallest = rem; } number = number / 10; } return smallest; } }