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

If you have any doubts, ask them in the comments section at the bottom of this page.

ICSE Question Paper – 2016 (Solved)
Computer Applications
Class X

SECTION A (40 Marks)
Answer all questions from this Section

Question 1.

(a) Define Encapsulation. [2]
Ans. Encapsulation is the process of bundling state (instance variables) and behaviour (methods) is a single unit (class).

(b) What are keywords? Give an example. [2]
Ans. Keywords are reserved words which convey special meaning to the compiler. They cannot be used as identifiers. Ex: class, void

(c) Name any two library packages. [2]
Ans. java.util, java.io

(d) Name the type of error (syntax, runtime or logical error) in each case given below: [2]
(i) Math.sqrt (36-45)
(ii) int a;b;c;

Ans. (i) Runtime error
Math.sqrt(36-45) = Math.sqrt(-9) which cannot be computed as square root of a negative number is not defined. Therefor, a runtime error will be thrown.
(ii) Syntax error
Multiple variables can be defined in one of the following ways
int a, b, c;
int a; int b; int c;

(e) If int x[] = { 4, 3, 7, 8, 9, 10 }; what are the values of p and q? [2]
(i) p = x.length
(ii) q = x[2] + x[5] * x[1]

Ans. (i) 6
(ii) q = x[2] + x[5] * x[1]
= 7 + 10 * 3
= 7 * 30
= 37

Question 2.

(a) State the difference between == operator and equals() method. [2]
Ans. == compares if the two objects being compared refer to the instance while equals() method which can be overridden by classes generally compares if the contents of the objects are equals.

(b) What are the types of casting shown by the following examples: [2]
(i) char c = (char)120;
(ii) int x = ‘t’;

Ans. (i) Explicit casting
(ii) Implicit casting

(c) Differentiate between formal parameter and actual parameter. [2]
Ans. Format parameters are the parameters defined in the signature of a method. Actual parameters are the values passed to the methods on function invocation.
Ex: Consider the following code snippet

public int add(int a, int b) {
   return a + b;
}

// Method invocation
int result = add(3, 4)

a and b are formal parameters while 3 and 4 are actual parameters.

(d) Write a function prototype of the following: [2]
A function PosChar which takes a string argument and a character argument and returns an integer value.

Ans.

public int PosChar(String s, char c)

(e) Name any two types of access specifiers. [2]
Ans. public, private, protected and default/package access specifiers

Question 3.

(a) Give the output of the following string functions : [2]
(i) “MISSISSIPPI”.indexOf(‘S’) + “MISSISSIPPI”.lastIndexOf(‘I’)
(ii) “CABLE”.compareTo(“CADET”)

Ans.
(i) “MISSISSIPPI”.indexOf(‘S’) + “MISSISSIPPI”.lastIndexOf(‘I’)
= 2 + 10
= 12
(ii) String’s compareTo method compares ASCII values of characters starting from the left.
“CABLE”.compareTo(“CADET”)
The first and seconds characters are the same in both the strings. So, we compare the third characters.
Compare B and D = ASCII value of B – ASCII value of D
= 66 – 68
= -2

(b) Give the output of the following Math functions: [2]
(i) Math.ceil(4.2)
(ii) Math.abs(-4)

Ans. (i) 5.0 (and not 5, as ceil() returns a double)
(ii) 4

(c) What is a parameterized constructor? [2]
Ans. A parameterized constructor is a constructor that accepts arguments which are used to initialize the object being created.

(d) Write down java expression for : [2]
T = square root (A2 + B2 + C2)

Ans.

double T = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2) + Math.pow(c, 2));

(e) Rewrite the following using ternary operator : [2]

if(x%2 == 0)
System.out.print("EVEN");
else
System.out.print("ODD");

Ans.

System.out.print(x % 2 == 0 ? "EVEN" : "ODD");

(f) Convert the following while loop to the corresponding for loop : [2]

int m = 5, n = 10;
while (n>=1)
{
System.out.println(m*n);
n–-;
}

Ans.

for(int m=5, n=10; n >=1; n--) {
   System.out.println(m*n);
}

(g) Write one difference between primitive data types and composite data types. [2]
Ans. A primitive data type is not composed of other data types. Ex: int, float, double while a composite data type is composed of other data types. Ex: class

(h) Analyze the given program segment and answer the following questions : [2]
(i) Write the output of the program segment
(ii) How many times does the body of the loop gets executed?

for(int m=5; m<=20; m+=5)
{
            if(m%3 == 0)
                        break;
            else
            if(m%5 == 0)
            System.out.println(m);
               continue;
}

Ans.
For loop initialization: m = 5
Loop condition check: m <= 20 = 5 <=20 = true
Loop execution for first time
m%3 == 0
= 5 % 3 == 0
= 2 == 0
= false
else is executed
m%5 == 0
= 5 % 5 == 0
= 0 == 0
= true
5 is printed
Loop increment statement is executed: m+=5 = m = m + 5 = 5 + 5 = 10
Loop condition check: m <= 20 = 10 <=20 = true
Loop body is executed second time and 10 is printed
Loop increment statement is executed: m+=5 = m = m + 5 = 10 + 5 = 15
Loop condition check: m <= 20 = 15 <=20 = true
Loop body is executed third time

m%3 == 0
= 15 % 3 == 0
= 0 == 0
= true
break statement is executed and loop terminates

(i) 5
10
(ii) 3 times

(i) Give the output of the following expression : [2]
a+=a++ + ++a + -–a + a-– ; when a = 7

Ans.
a+=a++ + ++a + –-a + a–- ;
a = 7 + (a++ + ++a + -–a + a–-);
a = 7 + (7 + 9 + 8 + 8);
a = 39

(j) Write the return type of the following library functions : [2]
(i) isLetterOrDigit(char)
(ii) replace(char,char)

Ans. (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 BlueJ environment or any program environment with Java as the base.
Each program should be written using Variable descriptions/Mneumonic codes so 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: [15]

Instance variables/Data members:
String Bname – stores the name of the book.
double price – stores the price of the book.

Member Methods:
(i) BookFair() – Default constructor to initialize data members.
(ii) void Input() – To input and store the name and the price of the book.
(iii) void calculate() – To calculate the price after discount. Discount is calculated based on the following criteria.

Price Discount
Less than or equal to Rs 1000 2% of price
More than Rs 1000 and less than or equal to Rs 3000 10% of price
More than Rs 3000 15% of price

(iv) void display() – To display the name and price of the book after discount.

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

Ans.

import java.util.Scanner;

public class BookFair {
	private String Bname;
	private double price;

	public BookFair() {
		Bname = null;
		price = 0.0;
	}

	public void Input() {
		Scanner scanner = new Scanner(System.in);
		System.out.print("Enter book name: ");
		Bname = scanner.nextLine();
		System.out.print("Enter price: ");
		price = scanner.nextDouble();
	}

	public void calculate() {
		double discountPercentage = 0;
		if (price <= 1000) {
			discountPercentage = 2;
		} else if (price > 1000 && price <= 3000) {
			discountPercentage = 10;
		} else if (price > 3000) {
			discountPercentage = 15;
		}
		price = price - (price * discountPercentage / 100);
	}

	public void display() {
		System.out.println("Name: " + Bname);
		System.out.println("Price after discount: " + price);
	}

	public static void main(String[] args) {
		BookFair bookFair = new BookFair();
		bookFair.Input();
		bookFair.calculate();
		bookFair.display();
	}
}

Sample output

Enter book name: How to Java
Enter price: 2500
Name: How to Java
Price after discount: 2250.0

Question 5.

Using the switch statement, write a menu driven program for the following: [15]

(i) To print the Floyd’s triangle [Given below]

1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

(ii) To display the following pattern

I
I C
I C S
I C S E

For an incorrect option, an appropriate error message should be displayed.

Ans.

import java.util.Scanner;

public class Menu {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.println("1. Floyd's triangle");
		System.out.println("2. ICSE Pattern");
		System.out.print("Enter your choice: ");
		int choice = scanner.nextInt();
		switch (choice) {
		case 1:
			System.out.print("Enter n (number of lines): ");
			int n = scanner.nextInt();
			int currentNumber = 1;
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= i; j++) {
					System.out.print(currentNumber + " ");
					currentNumber++;
				}
				System.out.println();
			}
			break;
		case 2:
			System.out.print("Enter word: ");
			String word = scanner.next();
			for (int i = 0; i < word.length(); i++) {
				for (int j = 0; j <= i; j++) {
					System.out.print(word.charAt(j) + " ");
				}
				System.out.println();
			}
			break;
		default:
			System.out.println("Invalid choice");
			break;
		}
	}
}

Sample output 1

1. Floyd's triangle
2. ICSE Pattern
Enter your choice: 1
Enter n (number of lines): 5
1 
2 3 
4 5 6 
7 8 9 10 
11 12 13 14 15 

Sample output 2

1. Floyd's triangle
2. ICSE Pattern
Enter your choice: 2
Enter word: ICSE
I 
I C 
I C S 
I C S E 

Sample output 3

1. Floyd's triangle
2. ICSE Pattern
Enter your choice: 3
Invalid choice

Question 6.
Special words are those words which starts and ends with the same letter. [15]
Examples:
EXISTENCE
COMIC
WINDOW

Palindrome words are those words which read the same from left to right and vice-versa.
Example:
MALAYALAM
MADAM
LEVEL
ROTATOR
CIVIC

All palindromes are special words, but all special words are not palindromes.

Write a program to accept a word check and print whether the word is a palindrome or only special word.

Ans.

import java.util.Scanner;

public class Words {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.print("Enter word: ");
		String word = scanner.next();

		// Check if word is palindrome
		String reverse = "";
		for (int i = word.length() - 1; i >= 0; i--) {
			reverse = reverse + word.charAt(i);
		}
		if (word.equals(reverse)) {
			System.out.println("Palindrome");
		}

		// Check if word is a special word
		char firstLetter = word.charAt(0);
		char lastLetter = word.charAt(word.length() - 1);
		if (firstLetter == lastLetter) {
			System.out.println("Special word");
		}
	}
}

Sample output 1

Enter word: MALAYALAM
Palindrome
Special word

Sample output 2

Enter word: COMIC
Special word

Question 7:
Design a class to overload a function SumSeries() as follows: [15]
(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 = (x/1) – (x/2) + (x/3) – (x/4) + (x/5) … to n terms
(ii) void SumSeries() – To find and display the sum of the following series:
s = 1 + (1 X 2) + (1 X 2 X 3) + … + (1 X 2 X 3 X 4 X … 20)

Ans.

public class Series {

	public void SumSeries(int n, double x) {
		double sum = 0;
		for (int i = 1; i <= n; i++) {
			if (i % 2 == 1) {
				sum = sum + (x / i);
			} else {
				sum = sum - (x / i);
			}
		}
		System.out.println("Sum = " + sum);
	}

	public void SumSeries() {
		int sum = 0;
		for (int i = 1; i <= 20; i++) {
			int product = 1;
			for (int j = 1; j <= i; j++) {
				product = product * j;
			}
			sum = sum + product;
		}
		System.out.println("Sum = " + sum);
	}
}

Question 8:
Write a program to accept a number and check and display whether it is a Niven number of not. [15]
(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.

Ans.

import java.util.Scanner;

public class NivenNumber {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.print("Enter a number: ");
		int number = scanner.nextInt();

		int sumOfDigits = 0;
		int copyOfNum = number;
		while (number > 0) {
			int remainder = number % 10;
			number = number / 10;
			sumOfDigits = sumOfDigits + remainder;
		}

		if (copyOfNum % sumOfDigits == 0) {
			System.out.println("Niven number");
		} else {
			System.out.println("Not a niven number");
		}

	}
}

Sample output 1

Enter a number: 126
Niven number

Sample output 2

Enter a number: 34
Not a niven number

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!” [15]
Seven wonders – CHICHEN ITZA, CHRIST THE RDEEEMER, 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!

Ans.

import java.util.Scanner;

public class SevenWonders {
	public static void main(String[] args) {
		String[] sevenWonders = { "CHICHEN ITZA", "CHRIST THE RDEEEMER", "TAJMAHAL", "GREAT WALL OF CHINA",
				"MACHU PICCHU", "PETRA", "COLOSSEUM" };
		String[] locations = { "MEXICO", "BRAZIL", "INDIA", "CHINA", "PERU", "JORDAN", "ITALY" };

		Scanner scanner = new Scanner(System.in);
		System.out.print("Enter country: ");
		String country = scanner.next();

		// Search country in the array using linear search
		int index = -1;
		for (int i = 0; i < locations.length; i++) {
			if (locations[i].equals(country)) {
				index = i;
			}
		}

		if (index != -1) {
			System.out.println(locations[index] + " - " + sevenWonders[index]);
		} else {
			System.out.println("Sorry Not Found!");
		}

	}
}

Sample output 1

Enter country: INDIA
INDIA - TAJMAHAL

Sample output 2

Enter country: USA
Sorry Not Found!

One thought on “ICSE Class 10 Computer Applications ( Java ) 2016 Solved Question Paper

Leave a Reply

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


*

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>