Sunteți pe pagina 1din 10

ICSE J

Java for Class X Computer Applications

Menu

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


9 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 prototy pe of a real world object. It contains instance v ariables 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. Key words are reserv ed words which conv ey special meanings to the compiler and cannot be used as identifiers. Example of
key words : class, public, v oid, 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 Jav a.
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
Jav a.

(d) What are the two ways of invoking functions? [2]


Ans. If the function is static, it can be inv oked by using the class name. If the function is non-static, an object of that class should be
created and the function should be inv oked using that object.

(e) What is difference between / and % operator? [2]


Ans. / is the div ision operator whereas % is the modulo (remainder) operator. a / b giv es the result obtained on div ing a by b whereas a
% b giv es the remainder obtained on div ing a by b.

Question 2.

converted by W eb2PDFConvert.com
(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 by tes. So a[4] will be 2*4=8 by tes.
float is 4 by tes. So p[4] will be 4*4=16 by tes.

(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) jav a.util
(ii) Constructor

(c) Give the output of the following: [2]

1 String n = Computer Knowledge;


2 String m = Computer Applications;
3 System.out.println(n.substring (0,8). concat (m.substring(9)));
4 System.out.println(n.endsWith(e));

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

1 ComputerApplications
2 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. v oid indicates that the function doesnt return any v alue.

Question 3
1
Like how many times the loop will be executed and what will be the
(a) Analyse the following program segment and determine
output of the program segment ? [2]

1 int p = 200;
2 while(true)
3 {
4 if (p<100)
5 break;
6 p=p-20;
7 }
8 System.out.println(p);

Ans.p v alues changes as follows : 200, 180, 160, 140, 120, 100, 80. So, the loop executes six times and v alue of p is 80.

(b) What will be the output of the following code? [2]


(i)

1 int k = 5, j = 9;
2 k += k++ ++j + k;
3 System.out.println("k= " +k);
4 System.out.println("j= " +j);

Ans.

1 k = 6
2 j = 10

Explanation:
k += k++ ++j + k

converted by W eb2PDFConvert.com
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]

1 double b = -15.6;
2 double a = Math.rint (Math.abs (b));
3 System.out.println("a= " +a);

Ans.

1 a =16.0

Maths.abs(-15.6) will giv e 15.6 and Math.rint(15.6) giv es 16.0.

(c) Explain the concept of constructor overloading with an example . [2]


Ans. A class can hav e more than one constructor prov ided that the signatures differ. This is known as constructor ov erloading.
Example:

1 class Age {
2
3 int age;
4
5 public Age() {
6 age = -1;
7 }
8
9 public Age(int age) {
10 this.age = age;
11 }
12 }

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

1 public boolean function ( sentence sentnc, word wrd )

or

1 public int function ( sentence sentnc, word wrd )

(e) Write an expression in Jav a for z = (53 + 2y ) / ( x + y ) [2]


Ans.

1 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) Sy stem.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 jav a API. Ex: String, Scanner

converted by W eb2PDFConvert.com
(i) Write one difference between Linear Search and Binary Search . [2]
Ans. Linear search can be used with both sorted and unsorted array s. Binary search can be used only with sorted array s.

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 v ariables/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 day s to store the number of day s the bike is taken on rent
int charge to calculate and store the rental charge
Member methods:
v oid input( ) to input and store the detail of the customer.
v oid computer( ) to compute the rental charge
The rent for a mobike is charged on the following basis.
First fiv e day s Rs 500 per day ;
Next fiv e day s Rs 400 per day
Rest of the day s Rs 200 per day
v oid display ( ) to display the details in the following format:
Bike No. PhoneNo. No. of day s Charge

Ans.

1 import java.util.Scanner;
2
3 public class mobike {
4
5 int bno;
6 int phno;
7 String name;
8 int days;
9 int charge;
10
11 public void input() {
12 Scanner scanner = new Scanner(System.in);
13 System.out.print("Enter bike number: ");
14 bno = scanner.nextInt();
15 System.out.print("Enter phone number: ");
16 phno = scanner.nextInt();
17 System.out.print("Enter your name: ");
18 name = scanner.next();
19 System.out.print("Enter number of days: ");
20 days = scanner.nextInt();
21 }
22
23 public void compute() {
24 if (days <= 5) {
25 charge = 500 * days;
26 } else if (days <= 10) {
27 charge = 5 * 500 + (days - 5) * 400;
28 } else {
29 charge = 5 * 500 + 5 * 400 + (days - 10) * 200;
30 }
31 }
32
33 public void display() {
34 System.out.println("Bike No. \tPhone No. \t No. of Days \t Charge");
35 System.out.println(bno + "\t" + phno + "\t" + days + "\t" + charge);
36 }
37 }

converted by W eb2PDFConvert.com
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.

1 import java.util.Scanner;
2
3 public class SelectionSort {
4
5 public void program() {
6 Scanner scanner = new Scanner(System.in);
7 int[] weights = new int[10];
8 System.out.println("Enter weights: ");
9 for (int i = 0; i < 10; i++) {
10 weights[i] = scanner.nextInt();
11 }
12 for (int i = 0; i < 10; i++) {
13 int highest = i;
14 for (int j = i + 1; j < 10; j++) { if (weights[j] > weights[highest]) {
15 highest = j;
16 }
17 }
18 int temp = weights[highest];
19 weights[highest] = weights[i];
20 weights[i] = temp;
21 }
22 System.out.println("Sorted weights:");
23 for (int i = 0; i < 10; i++) {
24 System.out.println(weights[i]);
25 }
26 }
27 }

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.

1 import java.util.Scanner;
2
3 public class SpecialNumber {
4
5 public int factorial(int n) {
6 int fact = 1;
7 for (int i = 1; i <= n; i++) { fact = fact * i; } return fact;
} public int sumOfDigita(int num) { int sum = 0; while (num > 0) {
8 int rem = num % 10;
9 sum = sum + rem;
10 num = sum / 10;
11 }
12 return sum;
13 }
14
15 public boolean isSpecial(int num) {
16 int fact = factorial(num);
17 int sum = sumOfDigita(fact);
18 if (sum == num) {
19 return true;
20 } else {
21 return false;
22 }
23 }
24
25 public void check() {
26 Scanner scanner = new Scanner(System.in);
27 System.out.print("Enter a number: ");
28 int num = scanner.nextInt();
29 if (isSpecial(num)) {
30 System.out.println("It is a special number");
31 } else {
32 System.out.println("It is not a special number");
33 }
34 }
35

converted by W eb2PDFConvert.com
36 }

Question 7

Write a program to accept a word and conv ert it into lowercase if it is in uppercase, and display the new word by replacing only the
v owels with the character following it. [15]

Example
Sample Input : computer
Sample Output : cpmpv tfr

Ans.

1 import java.util.Scanner;
2
3 public class StringConversion {
4
5 public static void convert() {
6 Scanner scanner = new Scanner(System.in);
7 System.out.print("Enter a String: ");
8 String input = scanner.next();
9 input = input.toLowerCase();
10 String answer = "";
11 for (int i = 0; i < input.length(); i++) {
12 char c = input.charAt(i);
13 if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
14 answer = answer + (char) (c + 1);
15 } else {
16 answer = answer + c;
17 }
18 }
19 System.out.println(answer);
20 }
21
22 }

Question 8.
Design a class to ov erload a function compare ( ) as follows: [15]
(a) v oid compare (int, int) to compare two integer v alues and print the greater of the two integers.
(b) v oid compare (char, char) to compare the numeric v alue of two character with higher numeric v alue
(c) v oid compare (String, String) to compare the length of the two strings and print the longer of the two.

Ans.

1 public class Overloading {


2
3 public void compare(int a, int b) {
4 int max = Math.max(a, b);
5 System.out.println(max);
6 }
7
8 public void compare(char a, char b) {
9 char max = (char) Math.max(a, b);
10 System.out.println(max);
11 }
12
13 public void compare(String a, String b) {
14 if (a.length() > b.length()) {
15 System.out.println(a);
16 } else if (a.length() < b.length()) {
17 System.out.println(b);
18 } else {
19 System.out.println(a);
20 System.out.println(b);
21 }
22 }
23 }

Question 9
Write a menu driv en program to perform the following . (Use switch-case statement) [15]
(a) To print the series 0, 3, 8, 15, 24 . n terms (v alue of n is to be an input by the user).
(b) To find the sum of the series giv en below:

converted by W eb2PDFConvert.com
S = 1/2+ 3/4 + 5/6 + 7/8 19/20

Ans.

Series 1 : The ith term is i2-1.

1 import java.util.Scanner;
2
3 public class Menu {
4
5 public void series1(int n) {
6 for (int i = 1; i <= n; i++) {
7 int term = i * i - 1;
8 System.out.print(term + " ");
9 }
10 }
11
12 public double series2(int n) {
13 double sum = 0;
14 for (int i = 1; i <= n; i++) {
15 sum = sum + (double) (2 * i - 1) / (2 * i);
16 }
17 return sum;
18 }
19
20 public void menu() {
21 Scanner scanner = new Scanner(System.in);
22 System.out.println("1. Print 0, 3, 8, 15, 24... n tersm");
23 System.out.println("2. Sum of series 1/4 + 3/4 + 7/8 + ... n terms");
24 System.out.print("Enter your choice: ");
25 int choice = scanner.nextInt();
26 System.out.print("Enter n: ");
27 int n = scanner.nextInt();
28 switch (choice) {
29 case 1:
30 series1(n);
31 break;
32 case 2:
33 double sum = series2(n);
34 System.out.println(sum);
35 break;
36 default:
37 System.out.println("Invalid choice");
38 }
39 }
40
41 public static void main(String[] args) {
42 Menu menu = new Menu();
43 menu.menu();
44 }
45 }

Jav a Program Pattern 5 ICSE Class 10 Computer Applications ( Jav a ) 2010 Solv ed Question
Paper

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

Yashvi Kandoi
January 27, 2014 at 5:24 pm

What is the answer to question 9, series one of the 2011 icse board paper of computer science of class 10?

Reply

converted by W eb2PDFConvert.com
ICSE Java Post author
January 29, 2014 at 8:39 am

The series is 0, 3, 8, 15, 24. We hav e incorrectly mentioned it as 0, 3, 7, 15, 24. The error has been corrected and the solution has also
been updated.

kritika
February 25, 2014 at 7:56 am

what is the use of this operator

Reply

ICSE Java Post author


February 25, 2014 at 1:15 pm

You can read about this key word here : http://www.icsejav a.com/theory /this-key word

leharika
March 13, 2014 at 2:29 am

Sir,in Q3 a) once p is ev aluated to 100 then wont the condition(p<100)turn false?how is p again deducted to 80?I am not
understanding..kindly help

Reply

ICSE Java Post author


March 13, 2014 at 1:49 pm

while(true){
if (p<100)
break;
p=p-20;
}

Consider the iteration when p is 120. p < 100 i.e. 120 < 100 is false, so break will not be excuted. The statement p = p - 20 will make p
100.

When p becomes 100, the condition p <100 is false. ( 100 is not less than 100. 100 is equal to 100 ) . As the 'if' condition is false, the
break statement won't be executed. The statement p = p - 20 will be executed which will reduce p to 80.

converted by W eb2PDFConvert.com
Now, p < 100 i.e. 80 < 100 is true. So, the break statement will be executed and control will come out of the loop.

Mandarin
June 10, 2014 at 11:55 am

ICSE Computers 2011: Question 6 (Program to check for special no.) :

The program giv en is incorrect. There is no need to find sum of digits. Instead, we hav e to find sum of factorials of digits.

Reply

tulip
March 19, 2015 at 5:45 pm

Answer to Q-3 d part is incorrect because sentence and word is not a return ty pe . Return ty pe should be String.

Reply

Ranjith Post author


March 19, 2015 at 6:01 pm

sentence and word are class ty pes as per the question.

The question say s


receiv es a sentence sentnc
According to the question, sentence is a class ty pe and the v ariable accepted by the method is sentence of ty pe sentnc.

Leave a Reply

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

Email *

Website

converted by W eb2PDFConvert.com
CAPTCHA Code
*
Comment

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

Post Comment

Java is a registered trademark of Oracle. This site is in no way related to or endorsed by Oracle.

ICSE J Answers

Ask and Answer questions related to Java. Get help from experts and get all your doubts cleared!

Search

ICSE Java
2,054 likes

Like Page Share

Be the first of your friends to like this

(C) ICSE Jav a, All Rights Reserv ed

converted by W eb2PDFConvert.com

S-ar putea să vă placă și