ICSE Question Paper – 2019 Computer Applications Class X
SECTION A (40 Marks)
Answer all questions from this Section
SECTION A (40 MARKS)
Attempt all questions
Question
1
(a) Name any two basic principles of
Object-oriented programming.
Answer:
- Encapsulation
- Abstraction
(b)
Write a difference between unary and binary operators.
Answer
A binary operator requires two operands whereas the Unary operator requires
one operand. Example 10+5 the plus sign between 10 and 5
is a binary operator which requires two operands. But if we write -10
+10 here minus or plus sign 10 is a unary operator.
(c)
Name the keyword:
(i) indicates that a method has no
return type. (ii) makes the variable as a class variable.
Answer
-
void
-
static
(d)
Write the memory capacity (storage size) of short and float data types in
bytes.
Answer
short storage size 2 bytes 16bits.
float storage size 4 bytes 32 bits
(e)
Identify and name the following tokens:(i) public, (ii) ‘a’ , (iii) == , (iv)
{}
-
keyword
- a character literal or constant
-
equality operator
-
Block
Question
2
(a) Differentiate between if else if and
switch statements.
Answer
if-else return a Boolean value (true or false) and it can test for all types of
conditions, whereas switch statement, do not return Boolean but it passes int or
char value and only tests for equality.
(b)
Give the output of the following code:
Answer
String p = "20", q = "19";
int a = Integer.parseInt(p);
int b = Integer.valueOf(q);
System.out.println(a + "" + b);
The output is 2019
(c)
What are the various types of errors in Java?
Answer
There are three types of error in java Compile-time error, Runtime error, Logical
error
(d)
State the data type and value of res after the following is executed:
char ch = '9';
res = Character.isDigit(ch);Answer
The data type and value of res after the following is executed is boolean
(e) What is the difference between the linear search
and the binary search technique?
Answer
Linear search take longer time to search as it is Iterative
in nature, whereas binary search takes less time to search an element
from the sorted list of elements.
In
linear search no sorting is required but in Binary search, sorting is required.
SECTION
B (60 Marks)
Question
4
Design a class named ShowRoom with the following
description:
Instance variables/data members:
String name: to store the name of the customer.
long mobno: to store the mobile number of the customer.
double cost: to store the cost of the items purchased.
double dis: to store the discount amount.
double amount: to store the amount to be paid after a discount.
Member methods:
ShowRoom(): default constructor to initialize data members.
void input(): to input customer name, mobile number, cost.
void calculate(): to calculate the discount on the cost of purchased items, based
on the following criteria:
Cost
Discount
(in percentage)
Less than or equal to Rs. 10000
5%
More than Rs. 10000 and less than
or equal to Rs. 20000
10%
More than Rs. 20000 and less than
or equal to Rs. 35000
15%
More than Rs. 35000
20%
void display(): to display customer
name, mobile number, amount to be paid after discount.
Write a main() method to create an
object of the class and call the above member methods.
Answer
import java.util.Scanner;
class ShowRoom
{
String name; // Customer name
long mobno; // for mobile number of the customer.
double cost; // to store the cost of the items
purchased.
double dis; // for the cost of the items purchased.
double amount; // to store the discount amount.
ShowRoom() // default constructor for initialization
{
name="";
mobno=0L; // L is used for long data type
cost=0.0;
dis=0.0;
amount=0.0;
}
// input method for inputing customer
details
void input()
{
Scanner kb = new Scanner(System.in);
System.out.print("Enter your name:
");
name=kb.nextLine();
System.out.print("Enter your
Mobile Number: ");
mobno=kb.nextLong();
System.out.print("Enter cost of
item purchased: ");
cost=kb.nextDouble();
}
// this method calculate the discount on
the purchased item
void calculate()
{
if(cost<=10000)
{
dis = cost * 0.05;
amount = cost - dis;
}
else
if(cost>10000&&cost<=20000)
{
dis = cost * 0.1;
amount = cost - dis;
}
else
if(cost>20000&&cost<=35000)
{
dis = cost * 0.15;
amount = cost - dis;
}
else if(cost>35000)
{
dis = cost * 0.2;
amount = cost - dis;
}
}
// This method display the customer
// name, mobile and amount
void display()
{
System.out.println("Name of the
customer: "+name);
System.out.println("Mobile number
: "+mobno);
System.out.println("Amount to be
paid after discount: "+amount);
}
// main method
public static void main(String[]args)
{
// Object of ShowRoom
ShowRoom obj = new ShowRoom();
obj.input();
obj.calculate();
obj.display();
}
}
Output:
Enter your name: Sunil
Enter your Mobile Number:
9000999099
Enter cost of item purchased:
22000
Name of the customer: Sunil
Mobile number : 9000999099
Amount to be paid after
discount: 18700.0
Question
5
Using the switch-case statement, write a menu-driven program to do the
following:
(a) To generate and print letters from A to Z and their Unicode.
Letters Unicode
A 65
B 66
. .
. .
. .
Z 90
(b) Display the following pattern
using iteration (looping) statement:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Answer
import java.io.BufferedReader;
import
java.io.InputStreamReader;
import java.io.IOException;
public class MenuDrivenICSE2019
{
public static void main(String
args[])throws IOException
{
InputStreamReader in = new InputStreamReader(System.in);
BufferedReader br = new
BufferedReader(in);
int choice; // for user choice
int i, j; // using for loop
System.out.println("Press 1 to
Unicode of A to Z");
System.out.println("Press 2 for
pattern");
System.out.print("Enter your
choice: ");
choice =
Integer.parseInt(br.readLine());
switch(choice)
{
case 1:
System.out.println("Letters\tUnicode");
for(i = 65; i <= 90; i++)
{
System.out.println((char)i +
"\t" + i);
}
break;
case 2:
for(i = 1; i <= 5; i++){
for(j = 1; j <= i; j++){
System.out.print(j + "
");
}
System.out.println();
}
break;
default:
System.out.println("Invalid
choice!");
}
}
}
Output:
Press
1 to Unicode of A to Z
Press
2 for pattern
Enter
your choice: 1
Letters Unicode
A 65
B 66
C 67
D 68
E 69
F 70
G 71
H 72
I 73
J 74
K 75
L 76
M 77
N 78
O 79
P 80
Q 81
R 82
S 83
T 84
U 85
V 86
W 87
X 88
Y 89
Z 90
Press
1 to Unicode of A to Z
Press
2 for pattern
Enter
your choice: 2
1
1 2
1 2 3
1 2 3
4
1
2 3 4 5
Question
6
Write a program to input 15 integer elements in an array and sort them in
ascending order using the bubble sort technique.
Question
7
Design a class to overload a function series() as follows:
(a) void series(int x, int n): to display the sum of the series
given below:
x1 + x2 + x3 + … + xn terms
(b) void series(int p): to display the following series:
0, 7, 26, 63, … p terms.
(c) void series(): to display the sum of the series given
below:
1/2 + 1/3 + 1/4 + … + 1/10
Answer
//
Overload series methods
public
class OverloadICSE2019
{
long sum1 = 0L;
int i, num;
double sum2;
public void series(int x, int n)
{
for(i = 1; i <= n; i++)
{
sum1 += (long)Math.pow(x, i);
}
System.out.println("Sum = " +
sum1);
}
public void series(int p)
{
for( i = 1; i <= p; i++)
{
num = i*i*i - 1;
System.out.print(num +
"\t");
}
}
public void series()
{
sum2 = 0.0;
for(i = 2; i <= 10; i++)
sum2 += 1.0 / i;
System.out.println("Sum = " +
sum2);
}
}
Question
8
Write a program to input a sentence and convert it into uppercase and count and
display the total number of words starting with the letter ‘A’.
Example:
Sample Input: ADVANCEMENT AND APPLICATION OF INFORMATION TECHNOLOGY ARE EVER
CHANGING.
Sample Output: Total number of words starting with letter ‘A’ = 4.
Answer
import java.util.*;
public class
CountLetterA_ICSE2019
{
public static void main(String[]args)
{
// sc here is the object for Scanner
class
Scanner sc = new Scanner(System.in);
String sent; // used for sentence
int count=0; // counter for A
char ch; // used for character
System.out.print("Enter a
sentence: ");
sent = sc.nextLine();
sent = sent.toUpperCase();
for(int i=0; i<sent.length(); i++)
{
ch = sent.charAt(i);
if(ch =='A')
count++;
}
System.out.println("Total number
of words Starting with letter 'A'=" + count);
}
}
Output
Enter a sentence: Have a nice
day with a big smile
Total number of words Starting
with letter 'A'= 4
Question
9
A tech number has an even number of digits. If the
number is split in two equal halves, then the square of the sum of these halves is
equal to the number itself. Write a program to generate and print all four digits of tech numbers.
Example:
Consider the number 3025.
Square of the sum of the halves of 3025 = (30 + 25)2
= (55)2
= 3025 is a tech number.
Answer
public class TechNumberICSE2019
{
int firstHalf; // for the
first half
int secondHalf; // for the
second half
int sum; // sum of both
half
int flag; // flag
variable
// Method to check Tech number
public int isTechNumber(int num)
{
flag = 0;
firstHalf= num / 100;
secondHalf = num % 100;
sum = firstHalf + secondHalf;
if(num == sum * sum)
{
flag = 1;
}
return flag;
}
// main method
public static void main(String args[])
{
TechNumberICSE2019 ob = new TechNumberICSE2019();
int i, tech;
for(i = 1000; i <= 9999; i++)
{
tech = ob.isTechNumber(i);
if(tech == 1)
{
System.out.print(i + " ,
");
}
}
}
}
Output:
2025 , 3025 , 9801
Answer all questions from this Section
Attempt all questions
Question
1
(a) Name any two basic principles of Object-oriented programming.
Answer:- Encapsulation
- Abstraction
(b)
Write a difference between unary and binary operators.
Answer
A binary operator requires two operands whereas the Unary operator requires
one operand. Example 10+5 the plus sign between 10 and 5
is a binary operator which requires two operands. But if we write -10
+10 here minus or plus sign 10 is a unary operator.
(c) Name the keyword:
(i) indicates that a method has no return type. (ii) makes the variable as a class variable.
Answer
- void
- static
(d) Write the memory capacity (storage size) of short and float data types in bytes.
Answer
short storage size 2 bytes 16bits.float storage size 4 bytes 32 bits
(e) Identify and name the following tokens:(i) public, (ii) ‘a’ , (iii) == , (iv) {}
- keyword
- a character literal or constant
- equality operator
- Block
Question
2
(a) Differentiate between if else if and switch statements.
Answer
if-else return a Boolean value (true or false) and it can test for all types of
conditions, whereas switch statement, do not return Boolean but it passes int or
char value and only tests for equality.(b) Give the output of the following code:
Answer
String p = "20", q = "19";int a = Integer.parseInt(p);
int b = Integer.valueOf(q);
System.out.println(a + "" + b);
The output is 2019
(c) What are the various types of errors in Java?
Answer
There are three types of error in java Compile-time error, Runtime error, Logical
error
(d) State the data type and value of res after the following is executed:
char ch = '9';
res = Character.isDigit(ch);Answer
The data type and value of res after the following is executed is boolean
(e) What is the difference between the linear search and the binary search technique?
Answer
Linear search take longer time to search as it is Iterative in nature, whereas binary search takes less time to search an element from the sorted list of elements.
Linear search take longer time to search as it is Iterative in nature, whereas binary search takes less time to search an element from the sorted list of elements.
In
linear search no sorting is required but in Binary search, sorting is required.
SECTION
B (60 Marks)
Question
4
Design a class named ShowRoom with the following description:
Instance variables/data members:String name: to store the name of the customer.
long mobno: to store the mobile number of the customer.
double cost: to store the cost of the items purchased.
double dis: to store the discount amount.
double amount: to store the amount to be paid after a discount.
Member methods:
ShowRoom(): default constructor to initialize data members.
void input(): to input customer name, mobile number, cost.
void calculate(): to calculate the discount on the cost of purchased items, based on the following criteria:
Cost
|
Discount
(in percentage)
|
Less than or equal to Rs. 10000
|
5%
|
More than Rs. 10000 and less than
or equal to Rs. 20000
|
10%
|
More than Rs. 20000 and less than
or equal to Rs. 35000
|
15%
|
More than Rs. 35000
|
20%
|
void display(): to display customer
name, mobile number, amount to be paid after discount.
Write a main() method to create an object of the class and call the above member methods.
Write a main() method to create an object of the class and call the above member methods.
Answer
import java.util.Scanner;
class ShowRoom
{
String name; // Customer name
long mobno; // for mobile number of the customer.
double cost; // to store the cost of the items
purchased.
double dis; // for the cost of the items purchased.
double amount; // to store the discount amount.
ShowRoom() // default constructor for initialization
{
name="";
mobno=0L; // L is used for long data type
cost=0.0;
dis=0.0;
amount=0.0;
}
// input method for inputing customer
details
void input()
{
Scanner kb = new Scanner(System.in);
System.out.print("Enter your name:
");
name=kb.nextLine();
System.out.print("Enter your
Mobile Number: ");
mobno=kb.nextLong();
System.out.print("Enter cost of
item purchased: ");
cost=kb.nextDouble();
}
// this method calculate the discount on
the purchased item
void calculate()
{
if(cost<=10000)
{
dis = cost * 0.05;
amount = cost - dis;
}
else
if(cost>10000&&cost<=20000)
{
dis = cost * 0.1;
amount = cost - dis;
}
else
if(cost>20000&&cost<=35000)
{
dis = cost * 0.15;
amount = cost - dis;
}
else if(cost>35000)
{
dis = cost * 0.2;
amount = cost - dis;
}
}
// This method display the customer
// name, mobile and amount
void display()
{
System.out.println("Name of the
customer: "+name);
System.out.println("Mobile number
: "+mobno);
System.out.println("Amount to be
paid after discount: "+amount);
}
// main method
public static void main(String[]args)
{
// Object of ShowRoom
ShowRoom obj = new ShowRoom();
obj.input();
obj.calculate();
obj.display();
}
}
Output:
Enter your name: Sunil
Enter your Mobile Number:
9000999099
Enter cost of item purchased:
22000
Name of the customer: Sunil
Mobile number : 9000999099
Amount to be paid after
discount: 18700.0
Question
5
Using the switch-case statement, write a menu-driven program to do the
following:
Using the switch-case statement, write a menu-driven program to do the
following:
(a) To generate and print letters from A to Z and their Unicode.
Letters Unicode
A 65
B 66
. .
. .
. .
Z 90
(b) Display the following pattern
using iteration (looping) statement:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Answer
import java.io.BufferedReader;
import
java.io.InputStreamReader;
import java.io.IOException;
public class MenuDrivenICSE2019
{
public static void main(String
args[])throws IOException
{
InputStreamReader in = new InputStreamReader(System.in);
BufferedReader br = new
BufferedReader(in);
int choice; // for user choice
int i, j; // using for loop
System.out.println("Press 1 to
Unicode of A to Z");
System.out.println("Press 2 for
pattern");
System.out.print("Enter your
choice: ");
choice =
Integer.parseInt(br.readLine());
switch(choice)
{
case 1:
System.out.println("Letters\tUnicode");
for(i = 65; i <= 90; i++)
{
System.out.println((char)i +
"\t" + i);
}
break;
case 2:
for(i = 1; i <= 5; i++){
for(j = 1; j <= i; j++){
System.out.print(j + "
");
}
System.out.println();
}
break;
default:
System.out.println("Invalid
choice!");
}
}
}
Output:
Press
1 to Unicode of A to Z
Press
2 for pattern
Enter
your choice: 1
Letters Unicode
A 65
B 66
C 67
D 68
E 69
F 70
G 71
H 72
I 73
J 74
K 75
L 76
M 77
N 78
O 79
P 80
Q 81
R 82
S 83
T 84
U 85
V 86
W 87
X 88
Y 89
Z 90
Press
1 to Unicode of A to Z
Press
2 for pattern
Enter
your choice: 2
1
1 2
1 2 3
1 2 3
4
1
2 3 4 5
Question
6
Write a program to input 15 integer elements in an array and sort them in ascending order using the bubble sort technique.
Write a program to input 15 integer elements in an array and sort them in ascending order using the bubble sort technique.
Question
7
Design a class to overload a function series() as follows:
Design a class to overload a function series() as follows:
(a) void series(int x, int n): to display the sum of the series
given below:
x1 + x2 + x3 + … + xn terms
(b) void series(int p): to display the following series:
0, 7, 26, 63, … p terms.
(c) void series(): to display the sum of the series given
below:
1/2 + 1/3 + 1/4 + … + 1/10
Answer
//
Overload series methods
public
class OverloadICSE2019
{
long sum1 = 0L;
int i, num;
double sum2;
public void series(int x, int n)
{
for(i = 1; i <= n; i++)
{
sum1 += (long)Math.pow(x, i);
}
System.out.println("Sum = " +
sum1);
}
public void series(int p)
{
for( i = 1; i <= p; i++)
{
num = i*i*i - 1;
System.out.print(num +
"\t");
}
}
public void series()
{
sum2 = 0.0;
for(i = 2; i <= 10; i++)
sum2 += 1.0 / i;
System.out.println("Sum = " +
sum2);
}
}
Question
8
Sample Input: ADVANCEMENT AND APPLICATION OF INFORMATION TECHNOLOGY ARE EVER CHANGING.
Sample Output: Total number of words starting with letter ‘A’ = 4.
Write a program to input a sentence and convert it into uppercase and count and display the total number of words starting with the letter ‘A’.
Example:Sample Input: ADVANCEMENT AND APPLICATION OF INFORMATION TECHNOLOGY ARE EVER CHANGING.
Sample Output: Total number of words starting with letter ‘A’ = 4.
Answer
import java.util.*;
public class
CountLetterA_ICSE2019
{
public static void main(String[]args)
{
// sc here is the object for Scanner
class
Scanner sc = new Scanner(System.in);
String sent; // used for sentence
int count=0; // counter for A
char ch; // used for character
System.out.print("Enter a
sentence: ");
sent = sc.nextLine();
sent = sent.toUpperCase();
for(int i=0; i<sent.length(); i++)
{
ch = sent.charAt(i);
if(ch =='A')
count++;
}
System.out.println("Total number
of words Starting with letter 'A'=" + count);
}
}
Output
Enter a sentence: Have a nice
day with a big smile
Total number of words Starting
with letter 'A'= 4
Question
9
Consider the number 3025.
Square of the sum of the halves of 3025 = (30 + 25)2
= (55)2
= 3025 is a tech number.
A tech number has an even number of digits. If the number is split in two equal halves, then the square of the sum of these halves is equal to the number itself. Write a program to generate and print all four digits of tech numbers.
Example:Consider the number 3025.
Square of the sum of the halves of 3025 = (30 + 25)2
= (55)2
= 3025 is a tech number.
Answer
public class TechNumberICSE2019
{
int firstHalf; // for the
first half
int secondHalf; // for the
second half
int sum; // sum of both
half
int flag; // flag
variable
// Method to check Tech number
public int isTechNumber(int num)
{
flag = 0;
firstHalf= num / 100;
secondHalf = num % 100;
sum = firstHalf + secondHalf;
if(num == sum * sum)
{
flag = 1;
}
return flag;
}
// main method
public static void main(String args[])
{
TechNumberICSE2019 ob = new TechNumberICSE2019();
int i, tech;
for(i = 1000; i <= 9999; i++)
{
tech = ob.isTechNumber(i);
if(tech == 1)
{
System.out.print(i + " ,
");
}
}
}
}
Output:
2025 , 3025 , 9801