ICSE Class 10 Computer Applications Sample Question Paper 4 with Answers

ICSE Class 10 Computer Applications Sample Question Paper 4 with Answers

Section – A (40- Marks)
Attempt all questions

Question 1
(a) What is encapsulation? How does Java achieve encapsulation?
Answer:
(a) Encapsulation is the wrapping of the data and its associated functions into a single unit. Java achieve encapsulation by enclosing the data and methods in the class.

(b) True or False:
(i) The default case is compulsory in the switch case statement
(ii) The default initial value of a boolean variable data type is false.
Answer:
(i) False
(ii) false

(c) Define the term byte code.
Answer:
High level program is compiled by java compiler to put in language called bytecode. This is understood by JVM in executing it.

ICSE Class 10 Computer Applications Sample Question Paper 4 with Answers

(d) What is the result code stored in x, after evaluating the following expression:
int x = 5;
x+ =++*2+3*- -x;
Answer:
30

(e) What is function prototype? Write a function prototype of:
A function poschar which takes a string argument and a character argument and returns an integer value.
Answer:
Function prototype is the declaration of function with its return type and number of arguments and data type of arguments.
int PosChar(String str, char ch);

Question 2
(a) Show how the sequence {10,5,8,12,45,1,9,11,2,23} changes step by step during the first two passes while arranging in ascending order using the bubble sort technique.
Answer:
10,5,8,12,45,1,9,11,2,23
5.10.8.12.45.1.9.11.2.23
5.8.10.12.45.1.9.11.2.23

(b) How will you import a scanner package? What is the default delimiter of an instance of the scanner class?
Answer:
import java.util.*; Default delimiter for scanner class is white space or tab or newline.

ICSE Class 10 Computer Applications Sample Question Paper 4 with Answers

(c) Differentiate between Character. isl)pperCase( ) and Character, to UpperCase( )
Answer:
lsUpperCaseO checks the uppercase character and returns boolean value.
Character.toUpperCase( ) converts lower case character to upper case character and returns upper case character.

(d) Write a Java expression:! = 2π√L/g
Answer:
doubeT = 2*3.14 * Math.sqrt(l/g);

(e) What is fall through? Give example.
Answer:
Fall through is a way in which all the cases of switch statement will be executed one by one if break is not encountered.
E.g. After case B is executed it executes case C to F.

switch(grade)
{
case 'A':
System.out.printlnC'Excellent!");
break;
case 'B':
case 'C':
System.out.printlnC'Well done"); case 'D' :
System.out.println("You passed"); case 'F':
System.out.println("Better try again");
break;
default:
System.out.println("lnvalid grade");
}

ICSE Class 10 Computer Applications Sample Question Paper 4 with Answers

Question 3
Write the output of the following print statement:
(a) out.print (“IXIXI”,replace(‘X ‘C’).indexOf(‘C’).indexOf(‘C’,2));
(b) out.print(“robotics”.substring(1,3).concat(“subject”.substring(3)));
(c) out.printC’FUN WORLD”.startsWith(“FUN”)==
(“COMPUTER IS FUN”.endsWith(“FUN”)));
(d) out.print(Math.sqrt(Math.abs(Math.ceil(-25.25))));
(e) out.print(Math.max(Math.pow(Math.round(6.25),2),(Math. pow(Math.rint(1.8),3))));
Answer:
(a) 3
(b) object
(c) true
(d) 0
(e) 36

Question 4
Write the output of the following segment of code:

a. String x = “abyz”
Int i;
for(i=0; i<4; i++)
System.out.println(x.charAt(i) – 32);
b. Int a = 0, b = 10, c = 20, d = 0;
a=(b>1)? c >1 ||d>1? 100:200:300
System.out.print(a);
c. int m[ ] = {1,4,9,16,25);
int a[ ] = {11};
for(int i = 0;i<5;i++)
System.out.println(a[0] + m[i]);
d. forfint j = 16;j< = 25; j+ = 2
System.out.println(j + “” + j-1);
e. int m = 1,n=0.
for(; m+n<19++n)
{
System.out.printlnC’Hello”);
m=m+10;
}

Answer:
(a) 65
66
89
90

(b) 100

(c) 12
15
20
27
36

ICSE Class 10 Computer Applications Sample Question Paper 4 with Answers

(d) 1615
1817
2019
2221
2423

(e) Hello
Hello

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 5
Given below is hypothetical table showing rates of Income Tax for male citizens below the age of 65 years:

Taxable Income (Tl) in Rs. Income Tax in Rs.
Does not exceed 1,60,000 NIL
Is greater than 1,60,000 and less than or equal to 5,00,000 10% of the amount exceeding 1,60,000
Is greater than 5,00,000 and less than or equal to 8,00,000 20% of the amount exceeding 5,00,000 + 34000
Is greater than 8,00,000 30% of the amount exceeding 8,00,000 + 94000

Write a program to input the age, gender(male or female) and Taxable Income of the 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. Also if Income Tax calculated in over Rs.10,000/- then extra surcharge payable is 2% of the income tax.
Answer:

import java.util.*;
class Incometax 
{
public static void main( )
{
Scanner sc = new Scanner(System.in); 
System.out.print("Enter your gender m or f:"); 
char ch = sc.next( ).
charAt(0); 
if(ch==,f,||ch=='F')
{
System.out.println("Wrong Category");
}
else if(ch=='mj|ch=-M')
{
System.out.print("Enter your age:");
int age = sc.nextlnt( ); if(age>65)
{
System.out.println("Wrong Category");
}
else
{
System.out.print("Enteryour income:"); 
double inc = sc.nextDouble( ); 
double tax; if(inc<=l 60000)
{
tax=0;
}
else if((inc> 160000)&&(inc<=500000))
{
tax = (inc—160000)*0.1;
{
else if((inc>500000)&&(inc<=800000))
{
tax = (inc-500000)*0.2; 
tax += 34000;
}
else
{
tax = (inc-800000)*0.3; 
tax += 94000;
}
if(tax > 10000) tax+= tax* 0.02;
System.out.println("\nlncomeTax is INR "+tax);
} 
else
{
System.out.println("Invalid Gender");
}
}//end of main 
}//end of class

ICSE Class 10 Computer Applications Sample Question Paper 4 with Answers

Question 6
Define a class Customer described as below:
Data members/instance variables:
String card_holder: Name of the card holder, long cardholder: card Number
char card_type: type of card (Silver (S) / Gold (G) / Platinum (P)) double amt: purchase made using the card.

Member methods:
(i) Customer( ): Default constructor to initialize all the date members
(ii) void input( ): To accept the details of the cardholder
(iii) void compute( ): To compute the cashback after availing the discount of a specific card type as per the following:

Card Type Cash Back
Silver (S) 2% of purchase amount
Gold (G) 5% of purchase amount
Platinum (P) 8% of purchase amount

ICSE Class 10 Computer Applications Sample Question Paper 4 with Answers

(iv) void display!): To display the details in the format:

Card Card Card Purchase Cash
Holder Number Type Amount Back
XXX XXX XXX XXX XXX

Write a main method to create an object of the class and call the above member methods.
Answer:

import java.util.Scanner; 
class Customer 
{
String card_holder; 
long card_no;
charcard_type; 
double amt- double cash_back; 
public Customer( )
{
card_holder="";
card_no =0; 
card_type =' 
amt = 0.0;
}
public void input( )
{
Scanner scanner = new Scanner(System.in);
System.out.print("Enter customer name:"); 
card_holder = scanner.next( );
System.out.printfEnter card number:"); 
card_no = scanner.nextlnt( );
System.out.print("Entertype of the card [S/G/P: "); 
card_type = scanner.next( ).charAt(O);
System.out.print("Enter amount of purchase made using the card:"); 
amt = scanner.nextDouble( );
}
public void compute( )
{
if (card_type == ’S')
{
cash _back = amt * 0.02;
}
else if (card_type == 'G')
{
cash_back = amt * 0.05;
}
else if (card_type == 'P')
{
cash_back = amt * 0.08;
}
else
{
System.out.printf'lnvalid card type ");
}
}
public void display!)
{
System.out.println("Card Holder. \tCard Number. \t Card type \t 
Purchase Amount \t Cash back");
System.out.println(card_holder + "\t" + card_no + "\t" + card_type + "\t" + amt);
}
public void main( )
{
Customer cl = new Customer( );
cl.input( );
cl.compute( );
cl.display( );
}
}

ICSE Class 10 Computer Applications Sample Question Paper 4 with Answers

Question 7
Accept a sentence and print a new sentence with all the odd placed words in uppercase and even placed words in lower case.
Sample input: It is a beautiful world
Sample output: IT is A beautiful WORLD
Answer:

import java.util.*; 
class lol {
public static void main( )
{
Scanner sc = new Scanner(System.in); 
System.out.println("Enter a string:");
String str = sc.nextLine( );
String strl = str.toLowerCase( ); str1+=" ";
String word =" "; int count = 0;
for(int i =0; i < strl ,length( );i++)
{
char ch = strl .charAt(i); if(ch!='')
{
word+=ch;
}
else
{
count++; if (count %2 !=0)
{
System.out.print(word.toUpperCase( )+"");
}
else
System.out.print(word+""); word ="";
}
}
}
}

Question 8
Using switch statement, write a menu driven program to
(i) Accept a number and find a sum of all the even numbers in the number.
Sample input: 24567
Sample output: Sum = 12 (2+4+6)

(ii) Accept a number and print those digits which are divisible by 3
Sample input: 135689
Sample output: Numbers divisible by 3 are 3,6, 9
Answer:

import java.util.*; 
class lol {
public static void main( )
{
Scanner sc = new Scanner(System.in); 
double sum = 0; int b =0;
System.out.println("Enter 1 for even number addition and 2 for printing numbers divisible by 3"); 
int ch = sc.nextlnt( ); switch(ch)
{
case '1int a = sc.nextlnt( ); b=a;
while(b % 10 !=0)
{
int temp = b %10; if (temp %2 = = 0)
 sum+=temp; b = b/10;
}
System.out.println(sum);
break;
case '2': 
int k = sc.nextlnt( ); b =k;
while(b %10 !=0)
{
int temp = b %10; if (temp %3 == 0)
System.out.println(temp); b = b/10;
}
break;
default: System.out.println("Error"); break;
}
}//end of main 
}//end of class

ICSE Class 10 Computer Applications Sample Question Paper 4 with Answers

Question 9
Write a program to accept 50 student names and their school in two separate single dimension arrays. Search for the school name input by the user in the list. If found, display “Search Successful” and print the name of the school along with the student name, or else display the message “Search Unsuccessful.”
Answer:

import java.util.*; 
class lol {
public static void main( ) {
String[ ] student_name = new String[50];
Stringt ] schooLname = new String[50];
Scanner sc = new Scanner(System.in); 
forfint i = 0; i < 50; i++)
{
System.out.printlnC'Enter students name :"); 
student_name[i] = sc.nextLine( );
System.out.printlnC'Enter schools name;"); 
school_name[i] = sc.nextLine( );
}
System.out.println("Enter schools name you want to search:"); 
String str = sc.nextLineO; int flag =0;
for(int i =0; i < 50;i++)
{
if(school_name[i].compareTo(str)==0)
{
System.out.println( "Search successful ");
System,out.println(school_name[i]+""+student_name[i]);
flag = 1 ;
break;
}
}
if (flag == 0)
System.out.println("Search Unsuccessful");
}
}

Question 10
Design a class to overload a function pattern() as follows:
(i) void pattern(int n): with one int argument that prints the pattern as follows:
Input value of n = 5
ICSE Class 10 Computer Applications Sample Question Paper 4 with Answers 1

(ii) void pattern (int n, char ch): with one int argument and one. character argument to print the pattern as follows:
Input value of n = 5
Input value of ch =’*’
Output:
1*
1* 2*
1* 2* 3*
1* 2* 3* 4*
1* 2* 3* 4* 5*
Answer:

import java.util.*; 
public class Main 
{
public void pattern(int n)
{
for(int i = n; i>0; i- -)
{
for(int j = i ; j<=n; j++)
System.out.print(j+" "); 
System.out.println( );
}
}
public void pattern(int n, char ch)
{
for(int i = 1; i<n; i++)
{
for(int j = 1; j<=i*2; j++)
{
If(j %2 == 0)
System.out.print(ch);
else
System.out.print(T');
}
System.out.println( );
}
}
public static void main(String[ ] args)
{
System.out.println("Enter the value of n"); 
Scanner sc = new Scanner(System.in); 
int n = sc.nextlnt( );
System.out.println("Enter the character"); 
char ch = sc.next( ).charAt(0);
Main ob = new Main( );
ob.pattern(n);
ob.pattern(n,ch);
}//end of main 
}//end of class

ICSE Class 10 Computer Applications Sample Question Paper 4 with Answers

Variable Data Type Description
ch char For storing character m or f
age int Age of person
inc double Income of person
tax double Store tax
cash__back double To store the cashback
cl Customer Object of class customer
str String To store line or sentence
count int Store number of words
sum double Store the sum of series
a,b,k Int Get the number.
student_name,
school_name
String Array to store student name and school name
flag int To know name exists or not
ij int For looping
n int Number of times to be printed
ch char Storing character
ob Main Object of class Main

ICSE Class 10 Computer Applications Question Papers with Answers

Leave a Comment