ICSE Class 10 Computer Applications Sample Question Paper 5 with Answers
Section – A
Attempt all questions
Question 1
(a) What is the use of ‘this’ keyword in parameterized constructor?
(b) State the differences between static and dynamic initialization.
(c) What is local variable and global variable? Explain with example.
(d) Which is not keyword in Java:
(i) boolean
(ii) void
(iii) public
(e) int a [ ]; int b [ ] = new int [100]; what is the difference between two initialization.
Answer:
(a) This keyword in parameterized constructor is used to refer to the currently calling object.
(b) Static initialization is used when memory is already allocated and then value is assigned.
Dynamic initialization is used to calculate the value at the run time and then allocate the memory.
E.g. int a = 6,b=9;//static memory allocated.
int c = a*b; //dynamic memory allocation.
(c) Local variable is a variable whose scope remains inside a method or a block of statements in a java program. The Global variable is a variable whose scope lies throughout the class in the java program.
(d) boolean
(e) int a[ ]: the array is declared without any allocation of memory space to it.
int b[ ] = new int [100]; The array is declared along with the allocation of memory to it. ie. 400 bytes.
Question 2
(a) State difference between constructor and method of class.
(b) char ch[ ] = {‘a’, ‘b’, ‘c’, ‘d’};
System.out.println( “hello world”+ch);
What will be the output of the above code?
(c) Define Java byte code.
(d) State the difference between operator and expression.
(e) What parse function does? Explain with example.
Answer:
(a)
Constructor | Method |
It has same name as that of class. | It has different name than that of class. |
It has no return type. It is called when object is created. | It has a return type and is called by the object. |
(b) Hello world abed
(c) The set of instructions to be executed by the JVM is called java byte code. JVM is the interpreter for java byte code.
(d)
Operator | Expression |
It is used to perform an operation. | Set of operators used to perform multiple function. |
int a =1, b =2; int c = a+b; |
inta =1; a+ = (a++) – ++ a +– a; |
(e) Parse function converts the value of a primitive data to the value of another primitive data type.
E.g.: String a = “24”;
int a = Integer.parselnt(a);
Question 3
(a) What is the use of keyword in void in function declaration.
(b) Which OOP principle is used in function overloading?
(c) Attempt the following:
(i) Name string function which compares two strings and returns boolean value
(ii) Write Java statement to do the reverse loop from 19 to 0.
(iii) Define Java token.
(iv) What’s the value of y after execution.
Inty = 5;
y – – = ++y + ++y + ++y *3;
(v) int a [ ] = {‘a1, ‘b\ Tc’, ‘A1, ‘B’, ‘C, ‘D’, ‘E’};
System.out.println ((int) a[3]);
System.out.println (a.length);
System.out.println (a[4]);
What will the output of the above code?
(d) Write output
inti = 20
for(; I<=30; i+=4)
System.out.print(i);
System.out.println(i)
(e) Name the formal and actual parameter.
(f) What is the difference between next ( ) and nextLine ( )?
Answer:
(a) The keyword void is used to tell that function has no return type.
(b) Polymorphism
(c) (i) equals( )
(ii) int i = 19;
do {
System.out.println(i);
i – -;
}
while(i>0);
(iii) Java token is the smallest unit of a java program.
(iv) 5 + 6 + 7*3 = 5+6+24 = 32.
(v) 65
8
66
(vi) 20 24 28 32
(vii) Formal parameter: When the identifier used in function definition to accept the values from the calling function is called the formal parameter.
Actual parameter: when the function is called by passing the identifiers which has values are called as actual parameter.
(viii) next( ): it accepts only the word without blank spaces.
nextLine( ) : It can accept more than one word as well.
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 salary described as below:
Data Members: Name, Address, Phone, Subject Specialization, Monthly Salary, Income Tax
Member methods:
(i) To accept the details of a teacher including the monthly salary.
(ii) To display the details of the teacher.
(iii) To compute the annual income tax as 5% of the annual salary above rs. 1,75,000/.Write the main method to create object of the class and call the above member method.
Answer:
import java.util.*; class salary { String name, address; String sub; double ms, it; long ph; salary ( ) { name = " " address = " " sub=" "; ms = 0.0; it = 0.0; ph=0; } void input ( ) { Scanner sc = new Scanner(System.in); System.out.println("Enter name address subject monthly salary and phone number:"); name = sc.nextLine( ); address = sc.nextLine( ); sub = sc.nextLine ( ); ms = sc.nextDouble( ); ph = sc.nextLong( ); } void display( ) { System.out.println(" Name: "+name+'\n"+sub+''\n"+"monthly salary:"+ms+ "\n"+"Phone no:"+ph); } void calc( ) { if(ms*12<=175000) it = 0; else it = 5.0/100.0 * (ms*12); ms = ms*12 - it; } public static void main( ) { salary oly = new salary( ); oly.input( ); oly.display( ); oly.calc( ); } }
Question 5
Write a program to initialize the given data in an array and find the minimum and maximum values along with the sum of the given elements.
Numbers: 2 5 4 1 3
Output: Minimum value:1
Maximum value: 5
Sum of the elements:
Answer:
import java.util.*; public class Main { public static void main(String[ ] args) { int arr[ ] = new int[10]; Scanner sc = new Scanner(System.in); for(int i =0;i<10;i++) { System.out.printlnC'enter a number: "); arr[i] = sc.nextlnt( ); } int min = 100000; int max = 0; int sum = 0; for(int i =0;i<10;i++) { if (arr[i] < min) min = arr[i]; if(arr[i]>max) max = arr[i]; sum+= arr[i]; } System.out.println('Minimum value: "+min); System.out.println("Maxmimu value: "+max); System.out.println("Sum of elements: "+sum); }//end of main }//end of class
Question 6
Define a class to overload following function
double area (double a, double b, double c) A = √s (s-a) (s-b) (s-c)
S = (a+b+c)/2
double area (double x, double y, double h) area = 1/2 h* (x+y)
double area (double m, double n) area = 1/2 m*n
Answer:
import java.util .*; import java.math *; class lol { double area(double a, double b, double c) { double s = (a + b + c)/2.0; double ar = Math.sqrt(s*(s-a)*(s-b)*(s-c)); return ar; } double area(double x,double y,double h,int a) { double ar1 = 1.0/2.0 *h*(x+y); return ar1; } double area(double m, double n) { double ar2 = 1.0/2.0*m*n; return ar2; } }
Question 7
Write a program to enter a sentence from the keyboard and count the number of times a particular word occurs in it. Display the frequency of the search word.
Example:
INPUT:
Enter a sentence: the quick brown fox jumps over the lazy dog.
Enter a word to be searched: the
OUTPUT:
Searched word occurs: 2 times.
Answer:
import java.util.*; class lol { public static void process(String a, String str) { String word =""; int count =0 ; for(int i =0; i <str.length( );i++) { char ch = str.charAt(i); if(ch!='') word = word+ch; else { if(a.equals(word)) count++; } } // end of for loop System.out.println(count); } }
Question 8
Write a program to create two array names A and B of same size 7. Perform the following operation:
(i) Input in an array A and find square of each number and store in array B and display both array simultaneously.
(ii) Display square root of each number from array A and display square root.
Answer:
import java.util.*; import java.math.*; class lot { public static void main( ) { Scanner sc = new Scanner(System.in); int a[ ] = new int [7]; int b[ ] = new int[7]; System.out.println("enter a number: "); for(int i =0;i <a.length; i++) { a[i] = sc.nextlntO; b[i] = a[i]*a[i]; } for(int i =0;i <a.length; i++) { System.out.println(a[i]+""+b[i]); } for(int i =0; i<a.length; i++) { double k= Math.sqrt(a[i]); System.out.println(k); } }//end of main }//end of class
Question 9
Write a program to input a number from user and using binary search method find the number is present in the given array or not. Display proper message.
Array is A [ ] = (24,39,330,343, 763, 789, 909,1001,1212, 2000}
Answer:
import java.util.*; import java.math.*; class lol { public static void main( ) { int arr[ ] = {24,39,330,343,763,789,909,1001,1212,2000}; int first = 0; Scanner sc = new Scanner(System.in); System.out.printlnC'enter a number:"); int key = sc.nextlnt( ); int last = arr.length-1; int mid = (first + last)/2; while(first <= last) { if (arr[mid] < key) { first = mid + 1; } else if (arr[mid] == key) { System.out.println("Element is found at index:" + mid); break; } else { last = mid - 1; } mid = (first + last)/2; } if (first > last) { System.out.println("Element is not found!"); } }//end of main } //end of class
Variable | Data Type | Description |
ms | double | Store monthly salary |
it | double | Income tax |
arr[] | int | Store 10 integers |
min,max,sum | int | Minimum value maximum value and sum of all elements. |
s a b c | double | Semiperimeter lengths of triangle. |
ar,ar1,ar2 | double | Area of shapes |
word | String | Store new word |
count | int | Store number of similar words. |
a[ ]b[ ] | int | Array of integers and squares |
k | double | Square root of number |
arr[ ] | int | Static array |
key | int | Number to be searched. |
first last and mid | int | Indexes of array |