You are on page 1of 68

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

2 Replies

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.
1 public class Integer { 2 3 4 5 6 7 8 9 10 11 12 } public Integer(int num) { x = num; } public Integer() { x = 0; } int x;

(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]
1 int a = 63, b = 36; 2 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]


1 char c = 'A': 2 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]
1 int x=4; 2 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]
1 double x = 2.9, y = 2.5; 2 System.out.println(Math.min(Math.floor(x), y)); 3 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]
1 String s = "Examination"; 2 int n = s.length(); 3 System.out.println(s.startsWith(s.substring(5, n))); 4 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]
1 String s1 = "Computer", s2 = "Applications"; 2 a = (s1.compareTo(s2)); 3 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]
1 String s = "malayalam"; 2 System.out.println(s.indexOf('m')); 3 System.out.println(s.lastIndexOf('m'));

Ans. 0 8 (i) Rewrite the following program segment using while instead of for statement [2]
1 int f = 1, i; 2 for (i = 1; i <= 5; i++) { 3 4 5} f *= i; System.out.println(f);

Ans.
1 int f = 1, i = 1; 2 while (i <= 5) { 3 4 5 6} 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]


1 class myClass { 2 3 static int x = 7; 4 int y = 2; 5 6 public static void main(String args[]) { 7 myClass obj = new myClass(); 8 System.out.println(x); 9 obj.sampleMethod(5); 10 int a = 6; 11 System.out.println(a); 12 } 13 14 void sampleMethod(int n) { 15 System.out.println(n); 16 System.out.println(y); 17 } 18 }

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.
1 public class Library { 2 3 4 5 6 7 public void input() throws IOException { BufferedReader br 8 = new BufferedReader(newInputStreamReader(System.in)); 9 10 11 12 13 14 15 16 17 public void compute() throws IOException { BufferedReader br 18 = new BufferedReader(newInputStreamReader(System.in)); 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 public static void main(String[] args) throws IOException { Library library = new Library(); library.input(); library.compute(); } public void display() { System.out.println("Accession Number\tTitle\tAuthor"); System.out.println(acc_num + "\t" + title + "\t" + author); } 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); } 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(); int acc_num; String title; String author;

34 35 36 } }

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 Does not exceed 1,60,000 Is greater than 1,60,000 and less than or equal to 5,00,000 Is greater than 5,00,000 and less than or equal to 8,00,000 Is greater than 8,00,000 Income Tax in Nil ( TI 1,60,000 ) * 10% [ (TI - 5,00,000 ) *20% ] + 34,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.
1 import java.util.Scanner; 2 3 public class IncomeTax { 4 5 6 7 8 9 10 11 12 13 14 15 16 17 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; { * 10 / 100; 18 19 20 21 22 23 24 25 } } } }

} else if (income > 160000 && income <= 500000) tax = (income - 160000) }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.
1 import java.util.Scanner; 2 3 public class StringOperations { 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 } } 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.
1 public class Overloading { 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 public void polygon() { } } 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(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();

22 23 24 25 26 27 28 29 }

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.
1 import java.util.Scanner; 2 3 public class Menu { 4 5 6 7 8 9 10 11 12 13 14 15 16 + b; 1 b; 7 c; 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++) { System.out.print(c + " "); b = } break; System.out.print("Enter a number: "); scanner.nextInt(); intsum = 0; int c = a a = case2: int num = while (num

> 0) { 1 8 19 20 21 22 23 24 25 26 27 28 } } } } System.out.println("Sum of digits is " + sum); break; default: System.out.println("Invalid Choice"); int rem = num % 10; sum = sum + rem; num = num / 10;

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.
view source print?

1 import java.util.Scanner; 2 3 public class Cities { 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 } 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)) { 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();

20 21 22 23 24 25 26 27 28 29 30 31 } list"); } } } }

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

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


4 Replies

COMPUTER APPLCATIONS (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 the 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 bracket [ ]
SECTION A (40 Marks) Question 1. (a) What is the difference between an object and a class? [2] Ans. 1. A class is a blueprint or a prototype of a real world object. It contains instance variables and methods whereas an object is an instance of a class. 2. A class exists in the memory of a computer while an object does not. 3. There will be only one copy of a class whereas multiple objects can be instantiated from the same class. (b) What does the token keyword refer to in the context of Java? Give an example for keyword. [2] Ans. Keywords are reserved words which convey special meanings to the compiler and cannot be used as identifiers. Example of keywords : class, public, void, int (c) State the difference between entry controlled loop and exit controlled loop. [2] Ans. In an entry controlled loop, the loop condition is checked before executing the body of the loop. While loop and for loop are the entry controlled loops in Java. In exit controlled loops, the loop condition is checked after executing the body of the loop. do-while loop is the exit controlled loop in Java.

(d) What are the two ways of invoking functions? [2] Ans. If the function is static, it can be invoked by using the class name. If the function is non-static, an object of that class should be created and the function should be invoked using that object. (e) What is difference between / and % operator? [2] Ans. / is the division operator whereas % is the modulo (remainder) operator. a / b gives the result obtained on diving a by b whereas a % b gives the remainder obtained on diving a by b. Question 2. (a) State the total size in bytes, of the arrays a [4] of char data type and p [4] of float data type. [2] Ans. char is two bytes. So a[4] will be 2*4=8 bytes. float is 4 bytes. So p[4] will be 4*4=16 bytes. (b) (i) Name the package that contains Scanner class. (ii) Which unit of the class gets called, when the object of the class is created? [2] Ans. (i) java.util (ii) Constructor (c) Give the output of the following: [2]
String n = Computer Knowledge; String m = Computer Applications ; System.out.println(n.substring (0,8). concat (m.substring(9))); System.out.println(n.endsWith(e));

Ans. n.substring(0,8) gives Computer. m.substring(9) gives Applications. These two on concatenation gives ComputerApplications. n ends with e. So, it gives true. The output is:
ComputerApplications true

(d) Write the output of the following: [2] (i) System.out.println (Character.isUpperCase(R)); (ii) System.out.println(Character.toUpperCase(j)); Ans. (i) true (ii) J

(e) What is the role of keyword void in declaring functions? [2] Ans. void indicates that the function doesnt return any value. Question 3 (a) Analyse the following program segment and determine how many times the loop will be executed and what will be the output of the program segment ? [2]
int p = 200; while(true) { if (p<100) break; p=p-20; } System.out.println(p);

Ans.p values changes as follows : 200, 180, 160, 140, 120, 100, 80. So, the loop executes six times and value of p is 80. (b) What will be the output of the following code? [2] (i)
int k = 5, j = 9; k += k++ ++j + k; System.out.println("k= " +k); System.out.println("j= " +j);

Ans.
k = 6 j = 10

Explanation: k += k++ ++j + k k = k + k++ ++j + k k = 5 + 5 10 + 6 k=6 j = 10 as it has been incremented in the ++j operation. (ii) [2]
double b = -15.6; double a = Math.rint (Math.abs (b)); System.out.println("a= " +a);

Ans.
a =16.0

Maths.abs(-15.6) will give 15.6 and Math.rint(15.6) gives 16.0. (c) Explain the concept of constructor overloading with an example . [2] Ans. A class can have more than one constructor provided that the signatures differ. This is known as constructor overloading. Example:
class Age { int age; public Age() { age = -1; } public Age(int age) { this.age = age; } }

(d) Give the prototype of a function search which receives a sentence sentnc and a word wrd and returns 1 or 0 ? [2] Ans.
public boolean function ( sentence sentnc, word wrd )

or
public int function ( sentence sentnc, word wrd )

(e) Write an expression in Java for z = (53 + 2y ) / ( x + y) [2] Ans.


z = ( 5 * Math.pow ( x, 3 ) + 2 * y ) / ( x + y )

(f) Write a statement each to perform the following task on a string: [2] (i) Find and display the position of the last space in a string s. (ii) Convert a number stored in a string variable x to double data type Ans. (i) System.out.println(s.lastIndexOf( ); (ii) Double.parseDouble(x)

(g) Name the keyword that: [2] (i) informs that an error has occurred in an input/output operation. (ii) distinguishes between instance variable and class variables. Ans. (i) throw (ii) static (h) What are library classes ? Give an example. [2] Ans. Library classes are the predefined classes which are a part of java API. Ex: String, Scanner (i) Write one difference between Linear Search and Binary Search . [2] Ans. Linear search can be used with both sorted and unsorted arrays. Binary search can be used only with sorted arrays. 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 such that the logic of the program is clearly depicted. Flow-Charts and Algorithms are not required.
Question 4. Define a class called mobike with the following description: [15] Instance variables/data members: int bno to store the bikes number int phno to store the phone number of the customer String name to store the name of the customer int days to store the number of days the bike is taken on rent int charge to calculate and store the rental charge Member methods: void input( ) to input and store the detail of the customer. void computer( ) to compute the rental charge The rent for a mobike is charged on the following basis. First five days Rs 500 per day; Next five days Rs 400 per day Rest of the days Rs 200 per day void display ( ) to display the details in the following format: Bike No. PhoneNo. No. of days Charge

Ans.
import java.util.Scanner; public class mobike { int bno; int phno; String name; int days; int charge; public void input() { Scanner scanner = new Scanner(System.in); System.out.print("Enter bike number: "); bno = scanner.nextInt(); System.out.print("Enter phone number: "); phno = scanner.nextInt(); System.out.print("Enter your name: "); name = scanner.next(); System.out.print("Enter number of days: "); days = scanner.nextInt(); } public void compute() { if (days <= 5) { charge = 500 * days; } else if (days <= 10) { charge = 5 * 500 + (days - 5) * 400; } else { charge = 5 * 500 + 5 * 400 + (days - 10) * 200; } } public void display() { System.out.println("Bike No. \tPhone No. \t No. of Days \t Charge"); System.out.println(bno + "\t" + phno + "\t" + days + "\t" + charge); } }

Question 5. Write a program to input and sort the weight of ten people. Sort and display them in descending order using the selection sort technique. [15] Ans.
import java.util.Scanner; public class SelectionSort { public void program() {

Scanner scanner = new Scanner(System.in); int[] weights = new int[10]; System.out.println("Enter weights: "); for (int i = 0; i < 10; i++) { weights[i] = scanner.nextInt(); } for (int i = 0; i < 10; i++) { int highest = i; for (int j = i + 1; j < 10; j++) { weights[highest]) { highest = j; } } int temp = weights[highest]; weights[highest] = weights[i]; weights[i] = temp; } System.out.println("Sorted weights:"); for (int i = 0; i < 10; i++) { System.out.println(weights[i]); } } }

if (weights[j] >

Question 6. Write a program to input a number and print whether the number is a special number or not. (A number is said to be a special number, if the sum of the factorial of the digits of the number is same as the original number). [15] Ans.
import java.util.Scanner; public class SpecialNumber { public int factorial(int n) { int fact = 1; for (int i = 1; i <= n; i++) { fact = fact * i; } return fact; } public int sumOfDigita(int num) { int sum = 0; while (num > 0) { int rem = num % 10; sum = sum + rem; num = sum / 10; } return sum; } public boolean isSpecial(int num) { int fact = factorial(num); int sum = sumOfDigita(fact); if (sum == num) {

return true; } else { return false; } } public void check() { Scanner scanner = new Scanner(System.in); System.out.print("Enter a number: "); int num = scanner.nextInt(); if (isSpecial(num)) { System.out.println("It is a special number"); } else { System.out.println("It is not a special number"); } } }

Question 7 Write a program to accept a word and convert it into lowercase if it is in uppercase, and display the new word by replacing only the vowels with the character following it. [15] Example Sample Input : computer Sample Output : cpmpvtfr Ans.
import java.util.Scanner; public class StringConversion { public static void convert() { Scanner scanner = new Scanner(System.in); System.out.print("Enter a String: "); String input = scanner.next(); input = input.toLowerCase(); String answer = ""; for (int i = 0; i < input.length(); i++) { char c = input.charAt(i); if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') { answer = answer + (char) (c + 1); } else { answer = answer + c; } } System.out.println(answer); }

Question 8. Design a class to overload a function compare ( ) as follows: [15] (a) void compare (int, int) to compare two integer values and print the greater of the two integers. (b) void compare (char, char) to compare the numeric value of two character with higher numeric value (c) void compare (String, String) to compare the length of the two strings and print the longer of the two. Ans.
public class Overloading { public void compare(int a, int b) { int max = Math.max(a, b); System.out.println(max); } public void compare(char a, char b) { char max = (char) Math.max(a, b); System.out.println(max); } public void compare(String a, String b) { if (a.length() > b.length()) { System.out.println(a); } else if (a.length() < b.length()) { System.out.println(b); } else { System.out.println(a); System.out.println(b); } } }

Question 9 Write a menu driven program to perform the following . (Use switch-case statement) [15] (a) To print the series 0, 3, 8, 15, 24 . n terms (value of n is to be an input by the user). (b) To find the sum of the series given below: S = 1/2+ 3/4 + 5/6 + 7/8 19/20 Ans. Series 1 : The ith term is i2-1.

import java.util.Scanner; public class Menu { public void series1(int n) { for (int i = 1; i <= n; i++) { int term = i * i - 1; System.out.print(term + " "); } } public double series2(int n) { double sum = 0; for (int i = 1; i <= n; i++) { sum = sum + (double) (2 * i - 1) / (2 * i); } return sum; } public void menu() { Scanner scanner = new Scanner(System.in); System.out.println("1. Print 0, 3, 8, 15, 24... n tersm"); System.out.println("2. Sum of series 1/4 + 3/4 + 7/8 + ... n terms"); System.out.print("Enter your choice: "); int choice = scanner.nextInt(); System.out.print("Enter n: "); int n = scanner.nextInt(); switch (choice) { case 1: series1(n); break; case 2: double sum = series2(n); System.out.println(sum); break; default: System.out.println("Invalid choice"); } } public static void main(String[] args) { Menu menu = new Menu(); menu.menu(); } }

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


Leave a reply

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 the 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 bracket [ ]
SECTION A (40 Marks) Question 1. (a) Define the term Byte Code. [2] Ans. The Java compiler compiles the source programs into an intermediate code called the Java Byte Code which is interpreted by the Java Virtual Machine (JVM) (b) What do you understand by type conversion? [2] Ans. Type conversion or casting is the conversion of the data type of a literal from one type to another. There are tow types of types of casting implicit casting and explicit casting. (c) Name two jump statements and their use. [2] Ans. break and continue are the two jump statements in Java. break is used to force early termination of a loop. continue is used to move to the next iteration of the loop while skipping the remaining code in the current iteration. (d) What is Exception ? Name two Exception Handling Blocks. [2] Ans. An Exception is an error which occurs during the execution of a program. The exception handling blocks are try, catch and finally. (e) Write two advantages of using functions in a program. [2] Ans. i) Function make code reusable. ii) Functions improve modularity and facilitate easy debugging.
Ads by websave. More Info | Hide These Ads

Question 2.

(a) State the purpose and return data type of the following String functions: [2] (i) indexOf ( ) (ii) compareTo ( ) Ans. i) indexOf() returns the index of the character or String passed as the parameter in the string on which is invoked. Return type is int. ii) compareTo() lexicographically compares the String passed as an argument to the String on which it is invoked. Return type is int. (b) What is the result stored in x, after evaluating the following expression [2]
int x = 5; x = x++ * 2 + 3 * x;

Ans. x = 5 * 2 + 3 * -6 x = 10 18 x = -8 (c) Differentiate between static and non-static data members. [2] Ans. i) static variables belong to the class and all object share a single instance of the static variables. Non static varaiables belong to the objects. Each object has a copy of these members. ii) static functions can access only static data members. Non static function can access both static and non static data members. (d) Write the difference between length and length() functions. [2] Ans. length is a property of an array which gives the size of the array. length() is a function of the String class which returns the size of the String. (e) Differentiate between private and protected visibility modifiers. [2] Ans. private members are accessible only in the class in which they have been defined. protected members are accessible in the class in which they have been defined as well in the sub classes of that class. Question 3 (a) What do you understand by data abstraction? Explain with an example.[2] Ans. Abstraction refers to representing the essential features of a system without considering all the details. Example: When we drive a car, we concentrate on how to drive it without bothering ourselves on how the engine works and other things.

(b) What will be the output of the following code? (i) [2]
int m=2; int n=15; for(int i = 1; i<5; i++) m++; n; System.out.println("m=" +m); System.out.println("n="+n);

Ans.
m=1 n=14

Note that there is no semicolon at the end of the loop. So, it is an empty loop and doest affect the values of m and n. (ii) [2]
char x = 'A' ; int m; m=(x=='a') ? 'A' : a; System.out.println("m="+m);

Ans.
m=a

(c) Analyse the following program segment and determine how many times tne loop will be executed and what will be the output of the program segment. [2]
int k=1, i=2; while (++i<6) k*=i; System.out.println(k);

Ans. Following are the iterations of the loop


3 4 5 6 < < < < 6 6 6 6 ------------k = 1 * 3 = 3 k = 3 * 4 = 15 k = 12 * 5 = 60 false

The loop will run three times and output is 60


60

(d) Give the prototype of a function check which receives a character ch and an integer n and returns true or false. [2] Ans.
public boolean function(char ch, int n)

(e) State two features of a constructor. [2] Ans. i) A constructor has the same name as that of a class. ii) A constructor does not have any return type. iii) A constructor is automatically called during object creation. (f) Write a statement each to perform the following task on a string: (i) Extract the second last character of a word stored in the variable wd. [2] Ans.
char ch = wd.charAt(wd.length()-2);

(ii) Check if the second character of a string str is in uppercase. [2] Ans.
boolean result = Character.isUpperCase(str.charAt(1));

(g) What will the following functions return when executed? [2] (j) Math.max(-17, -19) (ii) Math.ceil(7.8) Ans. i) -17 ii) 8.0 (h) (i) Why is an object called an instance of a class? (ii) What is the use of the keyword import? [2] Ans. i) An object is called an instance of a class because the objects contains a copy of all the instance variables of the class. ii) The import keyword is used to import classes from external packages. 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 such that the logic of the program is clearly depicted. Flow-Charts and Algorithms are not required.

Question 4. Write a program to perform binary search on a list of integers given below, to search for an element input by the user. If it is found display the element along with its position, otherwise display the message Search element not found. [15] 5,7,9,11,15,20,30,45,89,97 Ans.
import java.util.Scanner; public class BinarySearch { public static void main(String[] args) { int[] array = {5, 7, 9, 11, 15, 20, 30, 45, 89, 97}; Scanner scanner = new Scanner(System.in); System.out.print("Enter the number you want to search for: "); int target = scanner.nextInt(); int left = 0; int right = array.length - 1; int result = -1; while (left <= right) { int middle = (left + right) / 2; if (array[middle] == target) { result = middle; break; } else if (array[middle] > target) { right = middle - 1; } else { left = middle + 1; } } if (result != -1) { System.out.println(target + " found at index " + result); } else { System.out.println("Search element not found"); } } }

Sample Output 1:
Enter the number you want to search for: 7 7 found at index 1

Sample Output 2:
Enter the number you want to search for: 34 Search element not found

Question 5 Define a class Student described as below: [15] Data members/instance variables : name,age,m1,m2,m3 (marks in 3 subjects), maximum,

average Member methods : (i) A parameterized constructor to initialize the data members. (ii) To accept the details of a student. (iii) To compute the average and the maximum out of three marks. (iv) To display the name, age, marks in three subjects, maximum and average. Write a main method to create an object of a class and call the above member methods. Ans.
import java.util.Scanner; public class Student { String name; int age; int m1, m2, m3; int maximum; double average; public Student() { } public Student(String n, int a, int marks1, int marks2, int marks3, int max, double avg) { name = n; age = a; m1 = marks1; m2 = marks2; m3 = marks3; maximum = max; average = avg; } public void acceptDetails() { Scanner scanner = new Scanner(System.in); System.out.print("Enter name: "); name = scanner.next(); System.out.print("Enter age: "); age = scanner.nextInt(); System.out.print("Enter marks1: "); m1 = scanner.nextInt(); System.out.print("Enter marks2: "); m2 = scanner.nextInt(); System.out.print("Enter marks3: "); m3 = scanner.nextInt(); } public void compute() { average = (m1 + m2 + m3) / 3.0; maximum = Math.max(m1, (Math.max(m2, m3)));

} public void display() { System.out.println("Name: " + name); System.out.println("Age: " + age); System.out.println("Marks1 " + m1); System.out.println("Marks2 " + m2); System.out.println("Marks3 " + m3); System.out.println("Maximum: " + maximum); System.out.println("Average: " + average); } public static void main(String[] args) { Student student = new Student(); student.acceptDetails(); student.compute(); student.display(); } }

Sample Output:
Enter name: Sai Enter age: 20 Enter marks1: 95 Enter marks2: 100 Enter marks3: 99 Name: Sai Age: 20 Marks1 95 Marks2 100 Marks3 99 Maximum: 100 Average: 98.0

Question 6 Shasha Travels Pvt. Ltd. gives the following discount to its customers: [15] Ticket amount Discount Above Rs 70000 18% Rs 55001 to Rs 70000 16% Rs 35001 to Rs 55000 12% Rs 25001 to Rs 35000 10% less than Rs 25001 2% Write a program to input the name and ticket amount for the customer and calculate the discount amount and net amount to be paid. Display the output in the following format for each customer :

SL. NO. 1

Name -

Ticket charges -

Discount -

Net amount -

(Assume that there are 15 customers, first customer is given the serial no (SlNo.) 1, next customer 2 and so on. Ans.
import java.util.Scanner; public class Travels { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter sno: "); int sno = scanner.nextInt(); System.out.print("Enter name: "); String name = scanner.next(); System.out.print("Enter ticket charges: "); int charges = scanner.nextInt(); int discountPercentage = 0; if (charges > 70000) { discountPercentage = 18; } else if (charges >= 55001 && charges <= 70000) { discountPercentage = 16; } else if (charges >= 35001 && charges <= 55000) { discountPercentage = 12; } else if (charges >= 25001 && charges <= 35000) { discountPercentage = 10; } else if (charges < 25001) { discountPercentage = 2; } double discount = discountPercentage * charges / 100.0; double netAmount = charges - discount; System.out.println("Sl. No. \t Name \t Ticket Charges \t Discount \t Net Amount"); System.out.println(sno + "\t" + charges + "\t" + discount + "\t" + netAmount); } }

Sample Output:
Enter sno: 3 Enter name: Sai Enter ticket charges: 27000 Sl. No. Name Ticket Charges 3 27000 2700.0 24300.0

Discount

Net Amount

Question 7

Write a menu driven program to accept a number and check and display whether it is a Prime Number or not OR an Automorphic Number or not. (Use switch-case statement). [15] (a) Prime number : A number is said to be a prime number if it is divisible only by 1 and itself and not by any other number. Example : 3,5,7,11,13 etc. (b) Automorphic number : An automorphic number is the number which is contained in the last digit(s) of its square. Example: 25 is an automorphic number as its square is 625 and 25 is present as the last two digits. Ans.
import java.util.Scanner; public class Menu { public boolean isPrime(int n) { for (int i = 1; i < n; i++) { if (n % i == 0) { return true; } } return false; } public boolean isAutomorphic(int n) { int square = n * n; String originalNumber = n + ""; String squareNumber = n + ""; String lastDigits = squareNumber.substring(squareNumber.length() originalNumber.length(), squareNumber.length()); return lastDigits.equals(originalNumber); } public void menu() { Scanner scanner = new Scanner(System.in); System.out.println("Enter 1 for prime number"); System.out.println("Enter 2 for automorphic number"); System.out.print("Enter your choice: "); int choice = scanner.nextInt(); System.out.print("Enter a number: "); int num = scanner.nextInt(); switch (choice) { case 1: boolean prime = isPrime(num); if (prime) { System.out.println(num + " is a prime number"); } else { System.out.println(num + " is not a prime number"); }

break; case 2: boolean automorphic = isAutomorphic(num); if (automorphic) { System.out.println(num + " is an automorphic number"); } else { System.out.println(num + " is not an automorphic number"); } break; default: System.out.println("Invalid choice"); } } public static void main(String[] args) { Menu menu = new Menu(); menu.menu(); } }

Sample Output 1:
Enter Enter Enter Enter 13 is 1 for prime number 2 for automorphic number your choice: 1 a number: 13 a prime number

Sample Output 2:
Enter Enter Enter Enter 25 is 1 for prime number 2 for automorphic number your choice: 2 a number: 25 an automorphic number

Question 8. Write a program to store 6 element in an array P, and 4 elements in an array Q and produce a third array R, containing all elements of array P and Q. Display the resultant array [15] Example:
INPUT P[] 4 6 1 2 3 10 OUTPUT R [] 4 6 1 2 3 10

Q [] 19 23 7 8

19 23 7 8

Ans.
import java.util.Scanner; public class ArrayStore { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int[] p = new int[6]; int[] q = new int[4]; int[] r = new int[10]; System.out.print("Enter elements of array P: "); for (int i = 0; i < 6; i++) { p[i] = scanner.nextInt(); } System.out.print("Enter elements of array Q: "); for (int i = 0; i < 4; i++) { q[i] = scanner.nextInt(); } for (int i = 0; i < 6; i++) { r[i] = p[i]; } for (int i = 0; i < 4; i++) { r[i + 6] = q[i]; } System.out.print("Elements of array R: "); for (int i = 0; i < 10; i++) { System.out.print(r[i] + " "); } } }

Sample Output:
Enter elements of array P: 4 6 1 2 3 10 Enter elements of array Q: 19 23 7 8 Elements of array R: 4 6 1 2 3 10 19 23 7 8

Question 9 Write a program to input a string in uppercase and print the frequency of each character. [15]
INPUT : COMPUTER HARDWARE OUTPUT : CHARACTERS FREQUENCY A 2

C D E H M O P R T U W

1 1 2 1 1 1 1 3 1 1 1

Ans.
import java.util.Scanner; public class Frequency { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter a String: "); String input = scanner.nextLine(); int[] frequency = new int[26]; for (int i = 0; i < input.length(); i++) { char ch = input.charAt(i); if (Character.isUpperCase(ch)) { frequency[ch - 65]++; } } System.out.println("Characters Frequency"); for (int i = 0; i < 26; i++) { if (frequency[i] != 0) { System.out.println((char) (i + 65) + "\t" + frequency[i]); } } } }

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


Leave a reply

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.
Ads by websave. More Info | Hide These Ads

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 [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=y1=11=0 ii) 0 > 0 is false, so if block will not be executed and therefore, the values of x and y wont 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 : Iteration 2 : Iteration 3 : 5 <= 50 - true 5 <= 10 - true 5 <= 2 - false y = y / x = 50 / 5 = 10 y = y / x = 10 / 5 = 2 10 will be printed 2 will be printed

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

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 doesnt 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 users 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 22 333 4444 55555 Example 2: Input: Type 1 for a triangle and type 2 for an inverted triangle

2 Enter the number of terms 6 Output: 666666 55555 4444 333 22 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 Enter marks in subject Enter marks in subject Enter Roll No: 2 Enter marks in subject Enter marks in subject Enter marks in subject Enter Roll No: 3 Enter marks in subject Enter marks in subject Enter marks in subject ... Roll No - Average 1 - 99.0 2 - 10.0

A: 100 B: 100 C: 97 A: 10 B: 10 C: 10 A: 50 B: 50 C: 50

3 - 50.0 ... Students with average greater than 80 1 - 99.0 Students with average less than 40 2 - 10.0 ...

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


9 Replies

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) Attempt ALL questions. 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 String String String s1 = "good"; s2="world matters"; str1 = s2.substring(5).replace('t','n'); str2 = s1.concat(str1);

Ans. s2.substring(5) gives matters. When t is replaced with n, we get manners. good when concatenated with world matters gives goodworld matters. So, str1 = manners and str2 = goodworld matters. 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&lt;=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=24. In the fifth iteration, ++x will change x from 10 to 11. y-=x++ will increase x to 12. And y becomes 24-11=13. Now the condition x<=10 fails. So, the loop executes five times and the value of y that will be returned is 13. 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&lt;=5;i++) for(int j=1;j&lt;=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) scanner.nextInt() ii) scanner.next() 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 scanner = new Scanner(System.in); System.out.print("Enter product code: "); product_code = scanner.nextInt(); System.out.print("Enter flavour: "); flavour = scanner.next(); System.out.print("Enter pack type: "); pack_type = scanner.next(); System.out.print("Enter pack size: "); pack_size = scanner.nextInt(); System.out.print("Enter product price: "); product_price = scanner.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=11 + 24 + 30 + 41 + 56 + 60 + 71 + 84 + 99 + 109 = 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.
import java.util.Scanner; public class ISBN { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter ISBN code: "); int isbnInteger = scanner.nextInt(); 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 scanner = new Scanner(System.in); System.out.print("Enter a String: "); String input = scanner.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 scanner = new Scanner(System.in); System.out.println("Enter ten numbers:"); int[] numbers = new int[10]; for (int i = 0; i < 10; i++) { numbers[i] = scanner.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 scanner = 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 = scanner.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; } }

ICSE Question Paper 2012 (Solved)


March 29, 2012Leave a commentGo to comments

ICSE Question Paper 2012 (Solved) Computer Applications Class X (Time: Two Hours) SECTION A (40 Marks) Answer all questions from this Section Question 1. (a)Give one example of a primitive data type and composite data type. [2] Ans. Primitive type: byte/short/int/long/float/double/char/boolean Composite type: classes/interface/arrays (b) Give one point of difference between unary and binary operators. [2] Ans. Unary operators work on a single operand eg. ++a while binary operators work on two operands eg. a+b Differentiate between call by value or pass by value and call by reference or pass by reference [2] Ans. Call by value method creates a new copy of formal parameters and the changes made to them in the called function are not reflected on the actual arguments in the calling function. They work for primitive data types while call by reference method does not create a new copy rather works on the reference of actual arguments and changes made to them in the called function are reflected in the calling function. They work for reference data types. (d) Write java expression for 2as+u2 [2] Ans. double d= Math.sqrt((2*a*s + u*u)); (e) Name the type of error (syntax, runtime or logical error) in each case given below: [2] Ans. (i) Division by a variable that contains a value of zero : Runtime error (ii) Multiplication operator used when the operation should be division : Logical error (iii) Missing semicolon: Syntax error Question 2. (a) Create a class with one integer instance variable. Initialize the variable using : (i) Default constructor (ii) parameterized constructor Ans. class Initialize { int x; //instance variable Initialize() //default constructor { x=0; } Initialize(int a) //parameterized constructor { x=a; }

} (b) Complete the code given below to create an object of Scanner class: Ans. Scanner sc=new Scanner (System.in); [2]

What is an array? Write a statement to declare an integer array of 10 elements[2] Ans. An array is a structure created in memory to store multiple similar type of data under a single subscripted variable name. int a[]=new int[10]; (d) Name the search or sort algorithm that : [2] (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 : Selection sort (ii) At each stage, compares the sought key value with the key value of the middle element of the array: Binary search (e) Differentiate between public and private modifiers for members of a class [2] Ans. The scope of private members of a class is within the class itself whereas the the scope of the public members of a class is outside the class also ( outside the package 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=true y=36 (b) State the values of n and ch. char c=A; int n=c+1; char ch=(char)n; Ans. n=66 , ch=B [2]

What will be the result stored in x after evaluating the following expression?[2] int x = 4; x+= (x++)+(++x)+x; Ans. x=4+4+6+6 =20 (d) Give output of the following program segment: 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)); [2]

Ans. 2.0 3.0 (e) State the output of the following program segment: 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 (f) State the method that: [2] (i) Converts a string to a primitive float data type : parseFloat() (ii) Determines if the specified character is an upper case character: isUpperCase() (g) State the data type and values of a and b after the following segment is executed: String s1= Computer, s2=Applications; a = (s1.compareTo(s2)); b = (s1.equals(s2)); Ans. a=2 or positive b= false data type : data type : boolean int [2] [2] [2]

(h) What will the following code output: 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: 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); } } State the name and value of the : (i) method argument or argument variable: (ii) class variable : x (iii) local variable: a (iv) instance variable : y 5 [2]

SECTION B(60 Marks) Answer any four questions Also write the variable description/pneumonic codes Question 4. Define a class called Library with the following description: Instance variables/data members: Int acc_num String title : stores the accession number of books : stores the title of book

String author Member methods:

: stores the name of author

Void input() : to input and store the accession number, title and author Void compute(): to accept the number of days late, calculate and display the fine charged t the rate of Rs. 2 per day Void display(): to display the details in the following format:

Accession number Title Author Write the main method to create an object of the class and call the above member methods [15] Ans import java.io.*; class Library { int acc_num; String title, author; void input() throws IOexception{

BufferedReader obj=new BufferedReader(new InputStreamReader(System.in)); System.out.println(enter the accession number, title and author); acc_num= Integer.parseInt(obj.readLine()); title= obj.readLine(); author = obj.readLine(); } void compute() throws IOException{ BufferedReader obj=new BufferedReader(new InputStreamReader(System.in)); System.out.println(enter the number of days late); int n= Integer.parseInt(obj.readLine()); int fine=n*2; System.out.println(fine : +fine); } void display() { System.out.println(Accession Number\t\tTitle\t\tAuthpr); System.out.println(acc_num+\t\t+title+\t\t+author); } public static void main(String args[]) throws IOException

{ Library ob=new Library(); ob.input(); ob. compute(); ob.display(); } } Question 5. Given below is a hypothetical table showing rates of income tax for male citizens below the age of 65 yrs: Does not exceed Rs. 1,60,000 Is > Rs. 1,60,000 & <=Rs. 50,000 -nil (TI- 1,60,000)*10%

Is >Rs.5,00,000 & <=Rs. 8,00,000 - [(TI-5,00,000)*20%]+34,000 Is >Rs. 8,00,000 [(TI-8,00,000)*30%]+94,000 Write a program to input the age, gender(male or female) and taxable income(TI) of a person. If the age is more than 65 yrs or the gender is female, display wrong category. If the age is less than or equal to 65 yrs and the gender is male, compute and display the income tax payable as per the table given above. [15] Ans. import java.io.*; class IncomeTax { public static void main(string args[]) throws IOException { BufferedReader ob=new BufferedReader(new InputStreamReader(System.in)); System.out.println(enter age, gender and taxable income); int age=Integer.parseInt(ob.readLine()); String gender= ob.readLine(); int TI= Integer.parseInt(ob.readLine()); double tax=0.0; if((age>65) || (gender.equals(female))) System.out.println(wrong category); else if((age<=65) && (gender.equals(male))) {

if(TI<160000) tax=0; else if(TI>160000 && ti<=500000) tax=(TI-160000)*(double)10/100*TI; else if(TI>500000 && TI<=800000) tax=(TI-500000)*((double)20/100*TI)+34000; else tax=(TI-800000)*((double)30/100*TI)+94000; } else System.out.println(wrong category); }//main ends } //class ends Question 6. Write a program to accept a string. Convert it to uppercase. Count and output the number of double letter words that exist in the string. [15] Sample Input: SHE WAS FEEDING THE LITTLE RABBIT WITH AN APPLE Sample Output: 4 Ans. class DoubleLetter { void count(String s1) { s=s1.toUpperCase(); int l=s.length(); int c=0; for( int p=0; p<l-1; p++) { if(s.charAt(p) == s.charAt(p+1)) c++; }//for ends System.out.println( c ); }//method ends }//class ends Question 7. Design a class to overload a function polygon() as follows: [15]

(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: * ** *** Ans. class Overload { void polygon(int n , char ch) for (int p= 1; p<=n; p++) { for(int q=1; q<=n; q++) System.out.print(ch); System.out.println(); } }//method ends void polygon(int x, int y) { for(int p = 1; { for ( int q=1; q<=y; q++) System.out.print(@); System.out.println(); } }//method ends void polygon() { for(int p= 1; p<=3; p++) { for( int q=1; q<=p; q++) System.out.print(*); System.out.println(); } p<=x; p++) {

}//method ends }//class ends Question 8. Using the switch statement, write a menu-driven program to: (i) Generate and display the first 10 terms of the Fibonacci series 0,1,1,2,3,5,. (ii) find the sum of the digits of an integer that is input. Eg 15390=18 For an incorrect choice, appropriate error message should be displayed. [15] Ans. import java.io.*; class Menudriven {

public static void main(String args[]) throws IOException { BufferedReader ob=new BufferedReader (new InputStreamReader (System.in)); System.out.print(Enter 1 for Fibonacci numbers/ 2 for sum of digits); int ch=Integer.parseInt(ob.readLine()); switch( ch) { case 1: int a=0, b=1, c; System.out.print(a+ + b);

for(int p=3; p<=10; p++) { c=a+b; System.out.print( a=b; b=c; }//for ends break; case 2: System.out.println\nenter an integer); int n = Integer .parseInt(ob.readLine()); int rem=0, sum=0; while(n!=0) +c);

{ rem= n%10; n/=10; sum+=rem; }//while ends System.out.println(\nsum of digits +sum); break; default: System.out.println( Incorrect choice. Enter 1 or 2 only); }//switch ends }//main ends }//class ends Question 9. Write a program to accept the names of 10 cities in a single dimension string array and their STD 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.io.*; class LinearSearch { void find(String city[] , int std[]) { BufferedReader ob=new BufferedReader (new InputstreamReader (System.in)); System.out.print(Enter the city to be searched); String ele = ob.readLine(); int c=0; for(int p=0; p<10; p++) { if(city[p] . equals(ele)) { c=1; break; } //end if }//end for

if(c==1) { System.out.print(Search Successful); System.out.print(City: } else System.out.print(Search Unsuccessful. No such city in the list); }//end method }//end class +city[p]+\tSTD :+std[p]);

You might also like