ICSE Class 10 Computer Applications Sample Question Paper 6 with Answers
Section – A (40- Marks)
Attempt all questions
Question 1
(a) Define encapsulation.
(b) What are keywords? Give an example.
(c) Name any three library packages.
(d) Name the three types of error, syntax, runtime or logical error in the following case below:
(i) Math.sqrt (36 – 45)
(ii) inta;b;c
(c) If int x [ ] = {4,3,7,8,9,10}; what are the values of p and q?
(i) p = x.length
(ii) q = x[2] + x[5]*x[1]
Answer:
(a) Encapsulation is wrapping up of data and its associated functions into a single unit. It is achieved by the use of access specifiers like 1 public, private, and protected.
(b) Keywords are tokens in java that have a specific meaning.
E.g. static
(c) java.lang
java.io
java.util
(d) (i) logical
(ii) Syntax
(e) (i) 6
(ii) 37
Question 2
(a) State the difference between = = operator and equals ( ) method.
(b) What are the type of casting shown by the following examples:
(i) char c (char) 120;
(ii) int x = ‘t’;
(c) Differentiate between formal parameter and actual parameter.
(d) Write a function prototype of the following:
A function PosChar which takes a string argument and a character argument and returns an integer value.
(e) Name any two types of access specifiers.
Answer:
(a)
== operator | equals( ) |
It compares two primitive data types | It compares two strings |
(b) (i) Explicit
(ii) Implicit
(c) Formal parameters are used in the function definition using arguments as the input to the function. Actual parameters are used in calling the above function by passing values.
(d) int PosChar(String str, char ch);
(e) private and protected.
Question 3
(a) Define an impure function.
Answer:
(a) An impure function is a function where the values passed in the formal arguments of function is reflected back in the main function when values are changed by the called function.
(b) Explain the function overloading with example.
Answer:
void lol( ) { String str = "lol"; } void lol(int a) { String str1 = "lol"; }
(c) What is default constructor and where is it useful?
Answer:
Default constructor is a constructor without any parameter. It is used to initialize class variables to their default values.
(d) State the difference between selection sort and bubble sort.
Answer:
Selection Sort | Bubble Sort |
One element is compared with all the elements of the array and position is exchanged at the end of comparison. | Adjacent elements of the array are compared and exchanged. |
(e) Int i = 5;
if (++5/2 = =0)
System.out.printC’EVEN”);
else
System.out.printC’ODD”);
Answer:
error
(f) Convert the following while loop to the corresponding fir loop:
int m = 5, n =10; while (n>=1)
{
System.out.println(m*n); n – -;
}
Answer:
50
45
35
30
25
20
15
10
5
(g) Write one difference between primitive data types and composite date types.
Answer:
Primitive data type: Its fundamental data types of java.
Composite data type: It’s a combination of primitive data type.
(h) Analyze the given program segment and answer the following question:
Answer:
(i) 5
10
(ii) 3
(i) Write the output of the program segment
Answer:
39
(ii) How many times does the body of the loop get executed?
for (int m = 5; m<=20; m+=5)
{
if(m%3==0)
break;
else
if (m%5==0)
System.out.println(m);
continue;
}
a. Give the output of the following expression:
a+=a++ + ++a +– a + a–; when a=7
b. Write the return type of the following library
(i) isLetterOrDigit(Char)
(ii) replace(char, char)
Answer:
(i) boolean
(ii) String
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 named BookFair with the following description:
Instance variables/Data members
String Bname – stores the name of the book
double price – stores the price of the book member method.
(i) Book Fair( ) – Default constructor to initialize data members
(ii) void Input ( ) – To input and store the name and the price of the book.
(iii) Avoid Calculation ( ) – To calculate the price after discount. Discount is calculated based of the following criteria
Write a main method to create an object of the class and call the above member methods.
Answer:
import java.util.*; class BookFair { String Bname; double price; BookFair ( ) { Bname = price = 0.0; } void input ( ) { Scanner sc = new Scanner(System.in); System.out.println("Enter name and price of the book:"); Bname = sc.nextLine( ); price = sc.nextDouble( ); } void display!) { System.out.println(" Name: "+Bname+"\n"+"Price:"+price); } void calculate!) { double discount =0; if(price <= 1000) discount = (2.0/100.0)*price; else if(price >1000 && price <= 3000) discount = (10.0/100.0)*price; else if(price >3000) discount = (15.0/100.0)*price; else; price = price - discount; } public static void main!) { BookFair bf = new BookFair!); bf.input( ); bf.calculate( ); bf.display( ); } }
Question 5
Using the switch statement, write a menu driven program
(i) To print the Floyd’s triangle [Given below]
(ii) To display the following pattern
For an incorrect option, an appropriate error message should be displayed
Answer:
import java.util.*; import java.math.*; class lol { public static void main(String[ ] args) { Scanner sc = new Scanner(System.in); System.out.println(''Enter 1 for number pattern and 2 for string pattern"); int opt = sc.nextlnt( ); switch(opt) { case 1: int a = 1; forfint i =1;i<=5;i++) { for(int j = 1;j<=i;j++) { System.out.print(a+""); a++; } System.out.println( ); } break; case 2 : String str = "ICSE"; for(int i =0;i <str.length( );i++) { forfint j =0;j<=i; j++) { char ch = str.charAt(j); System.out.print(ch+" "); } System.out.println( ); } break; default: System.out.println("ERROR"); }// end of switch }//end of main }//end of class
Question 6
Special words are those words which starts and ends with the same letter
Example:
EXISTENCE
COMIC
WINDOW
Palindrome words are those words which read the same from left to right and vice versa
Example:
MALYALAM
MADAM
LEVEL
ROTATOR
CIVIC
All palindromes are special words but all words are not palindromes.
Write a program to accept a word check and print whether the word is a palindrome or only a special word
Answer:
import java.util.*; class Main { public static void main(String [ Jargs) { Scanner sc = new Scanner(System.in); System.out.println("Enter a word:"); String str = sc.next( ); String word =""; for (int i = str.length()-1;i >=0;i--) { char ch = str.charAt(i); word = word+ch; } if(word.equals(str)) System.out.println("Palindrome"); else { if(str.charAt(0)==str.charAt(str.length( )-1)) System.out.println("special word"); } } }
Question 7
Design a class to overload a function SumSeriesQ as follows:
(i) void SumSeries(int n, double x) – with one integer argument and one double argument to find and display the sum of the series given below:
\(s+\frac{x}{1}-\frac{x}{2}+\frac{x}{3}-\frac{x}{4}+\frac{x}{5} \ldots \ldots \ldots \text { to n terms }\)
(ii) void SumSeries( ) – To find and display the sum of the following series:
s = 1+(1*2)+(1*2*3)+ ………… +(1*2*3*4* ………… n)
Answer:
import java.util .*; class lol { void sumseries(int n, double x) { double sum =0; for(int i =1;i<=n;i++) { if(i % 2 == 0) { sum = sum -(x/i); } else { sum = sum + (x/i); } } System.out.printlnC'sum = "+sum); } void sumseriesO { long sum = 0; long product = 1; for(int i = 1;i <=20;i++) { product = product * i; sum+= product; } System.out.printlnC'sum = "+sum); } }
Question 8
Write a program to accept a number and check and display whether it is a Niven number or not. (Niven number is that number which is divisible by its sum of digits).
Example:
Consider the number 126.
Sum of its digits is 1+2+6 = 9 and 126 is divisible by 9.
Answer:
import java.util.*; class lol { public static void main(String [ jargs) { Scanner sc = new Scanner("System.in"); System.out.println("Enter a num:"); int a = sc.nextlnt( ); int al = a; int sum =0; while(a1!=0) { int k = a 1 % 10; sum = sum+ k; a 1 /= 10; } if(a%sum ==0) System.out.println("Niven number"); else System.out.println("Not Niven number"); }//end of main }// end of class
Question 9
Write a program to initialize the seven Wonders of the World along with their locations in two different arrays. Search for a name of the country input by the user. If found, display the name of the country along with its Wonder, otherwise display “Sorry Not Found!”
Seven wonders – CHICHEN ITZA, CHRIST THE REDEEMER, TAJMAHAL, GREAT WALL
OF CHINA, MACHU PICCHU, PETRA, COLOSSEUM
Locations – MEXICO, BRAZIL, INDIA, CHINA, PERU, JORDAN,
ITALY
Example – Country Name: INDIA Output: INDIA -TAJMAHAL
Country Name: USA Output: Sorry Not Found!
Answer:
import java.util.*; class lol { public static void main(String args[ ]) { String wonder[ ]={"CHICHEN ITZA","CHRISTTHE REDEEMER", "TAJMAHAL", "GREATWALL OF CHINA","MACHU PICCHU","PETRA","COLOSSEUM"}; String country} ]={"MEXICO","BRAZIL1,"INDIA","CHINA","PERU","JORDAN","ITALY"}; String str; int i,len; Scanner sc=new Scanner(System.in); System.out.printlnC'Enter the name"); str=sc.nextLine(); len=str.length(); boolean flag=false; for (i=0;i<len;i++) { if(str.equalslgnoreCase(country[i])) { System.out.println(country[i]+""+ wonderfi]); flag =true; break; } } if(flag== false) System.out.println("Sorry Not Found"); }//end of main }//end of class
Variable | Data Type | Description |
discount | Double | store discount value |
opt | int | Option number |
ij | int | For looping |
a | int | For printing pattern |
ch | char | Reading each character of word. |
str | String | To read word |
word | String | To store reverse word |
sum | double | Store the series of sum |
product | long | Stores product of integers. |
a | int | Read users number |
a1 | int | Modifying the digits |
flag | boolean | To check true or false |