ICSE Computer Applications Year 2014

Section A (40 Marks)

Attempt all questions.

Question 1

(a) Which of the following are valid comments?
(i) /*comment */
(ii) /*comment
(iii) //comment
(iv) */comment*/


(b) What is meant by a package? Name any two Java Application Programming Interface package.

Packages are means of defining modules in Java and are used to group logically related classes together. They help in avoiding name conflicts. Two examples are java.io and java.util.

(c) Name the primitive data type in Java that is:
(i) a 64-bit integer and is used when you need a range of values wider than those provided by int.
(ii) a single 16-bit Unicode character whose default value is ‘\u0000’.

(d) State one difference between floating point literals float and double.

The float literal occupies 32 bits whereas the double literal occupies 64 bits.

(e) Find the errors in the given program segment and re-write the statements correctly to assign values to an integer array.

int a = new int(5);
for(int i = 0; i <= 5; i++) a[i] = i;
int a[] = new int[5];
for(int i = 0; i < 5; i++)
    a[i] = i;

Question 2

(a) Operators with higher precedence are evaluated before operators with relatively lower precedence. Arrange the operators given below in order of higher precedence to lower precedence.
(i) &&
(ii) %
(iii) >=
(iv) ++

++, %, >=, &&

(b) Identify the statements listed below as assignment, increment, method invocation or object creation statements.
(i) System.out.println(“Java”); Method invocation
(ii) costPrice = 457.50; Assignment
(iii) Car hybrid = new Car(); Object creation
(iv) petrolPrice++; Increment

(c) Give two differences between switch statement and if-else statement.

(i) The switch statement tests for one variable, whereas the if-else statement tests for multiple variables.
(ii) The switch statement only tests for equality, whereas the if-else statement can test for any type of condition.

(d) What is an infinite loop? Write an infinite loop statement.

An infinite loop is one that keeps on executing repeatedly because its terminating condition is either missing or is never reached.


(e) What is a constructor? When is it invoked?

A constructor is a member function with the same name as its class. It is used to initialize the objects of the class with legal initial values.
It is invoked at the time of object creation.

Question 3

(a) List the variables from those given below that are composite data types.
(i) static int x;
(ii) arr[i] = 10; (Composite)
(iii) obj.display(); (Composite)
(iv) boolean b;
(v) private char chr;
(vi) String str; (Composite)

(b) State the output of the following program segment:

String str1 = "great"; String str2 = "minds";
System.out.println(str1.substring(0, 2).concat(str2.substring(1)));
System.out.println(("WH" + (str1.substring(2).toUpperCase())));

(c) What are the final values stored in variables x and y below?

double a = -6.35;
double b = 14.74;
double x = Math.abs(Math.ceil(a));
double y = Math.rint(Math.max(a, b));

x = 6.0
y = 15.0

(d) Rewrite the following program segment using the if-else statements instead of the ternary operator.

String grade = (marks >= 90)? "A" : (marks >= 80)? "B" : "C";
String grade = "";
if(marks >= 90)
    grade = "A";
else if(marks >= 80)
    grade = "B";
    grade = "C";

(e) Give the output of the following method:

public static void main(String[] args){
    int a = 5;
    a -= (a--) - (--a);


(f) What is the data type returned by the library functions:
(i) compareTo()
(ii) equals()

(g) State the value of characteristic and mantissa when the following code is executed:

String s = "4.3756";
int n = s.indexOf('.');
int characteristic = Integer.parseInt(s.substring(0, n));
int mantissa = Integer.valueOf(s.substring(n + 1));

characteristic = 4
manissa = 3756

(h) Study the method and answer the given questions:

public void sampleMethod(){
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 2; j++){
            int number = (int)(Math.random() * 10);

(i) How many times does the loop execute?
6 times.
(ii) What is the range of possible values stored in the variable number?
The range is 0 to 9.

(i) Consider the following class:

public class myClass{
    public static int x = 3, y = 4;
    public int a = 2, b = 3;

(i) Name the variables for which each object of the class will have its own distinct copy.
a and b.
(ii) Name the variables that are common to all objects of the class.
x and y.

(j) What will be the output when the following code segments are executed?

String s = "1001";
int x = Integer.valueOf(s);
double y = Double.valueOf(s);
System.out.println("x = " + x);
System.out.println("y = " + y);

x = 1001
y = 1001.0

System.out.println("The King said\"Begin at the beginning!\" to me.");
The King said "Begin at the beginning!" to me.

Section B (60 Marks)

Attempt any four questions from this section.

Question 3

Define a class named MovieMagic with the following description:

Instance variables/data members:
int year: to store the year of release of a movie.
String title: to store the title of the movie.
float rating: to store the popularity rating of the movie (minimum rating = 0.0 and maximum rating = 5.0)
Member Methods:
MovieMagic(): default constructor to initialize numeric data members to 0 and String data member to “”.
void accept(): to input and store year, title and rating.
void display(): to display the title of a movie and a message based on the rating as per the table below:

RatingMessage to be displayed
0.0 to 2.0Flop
2.1 to 3.4Semi-hit
3.5 to 4.5Hit
4.6 to 5.0Super Hit

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

import java.io.*;
class MovieMagic{
    private int year;
    private String title;
    float rating;
    public MovieMagic(){
        year = 0;
        rating = 0.0F;
        title = "";
    public void accept()throws IOException{
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(in);
        System.out.print("Title: ");
        title = br.readLine();
        System.out.print("Year: ");
        year = Integer.parseInt(br.readLine());
        System.out.print("Rating: ");
        rating = Float.parseFloat(br.readLine());
    public void display(){
        System.out.println("Movie title: " + title);
        if(rating <= 2.0)
        else if(rating <= 3.4)
        else if(rating <= 4.5)
            System.out.println("Super hit");
    public static void main(String args[])
    throws IOException{
        MovieMagic obj = new MovieMagic();

Question 5

A special two-digit number is such that when the sum of its digits is added to the product of its digits, the result is equal to the original two-digit number.
Consider the number 59.
Sum of digits = 5 + 9 = 14.
Product of its digits = 5 × 9 = 45.
Sum of the sum of digits and product of digits = 14 + 45 = 59.

Write a program to accept a two-digit number. Add the sum of its digits to the product of its digits. If the value is equal to the number input, output the message “Special 2-digit number” otherwise, output the message “Not a special 2-digit number”.

import java.io.*;
class SpecialTwoDigit{
    public static void main(String args[])
    throws IOException{
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(in);
        System.out.print("Enter a two-digit number: ");
        int n = Integer.parseInt(br.readLine());
        if(n < 10 || n > 99){
            System.out.println("Invalid input.");
        int d1 = n / 10;
        int d2 = n % 10;
        int sum = d1 + d2;
        int product = d1 * d2;
        int total = sum + product;
        if(n == total)
            System.out.println("Special 2-digit number");
            System.out.println("Not a special 2-digit number");

Question 6

Write a program to assign a full path and file name as given below. Using library functions, extract and output the file path, file name and file extension separately as shown.
INPUT: C:\Users\admin\Pictures\flower.jpg
Path: C:\Users\admin\Pictures\
File name: flower
Extension: jpg

class Path{
    public static void main(String args[]){
        String fp = "C:\\Users\\admin\\Pictures\\flower.jpg";
        int last = fp.lastIndexOf('\\');
        int dot = fp.lastIndexOf('.');
        String p = fp.substring(0, last + 1);
        String f = fp.substring(last + 1, dot);
        String ext = fp.substring(dot + 1);
        System.out.println("Path: " + p);
        System.out.println("File name: " + f);
        System.out.println("Extension: " + ext);

Question 7

Design a class to overload a function area() as follows:
(i) double area(double a, double b, double c) with three double arguments, returns the area of a scalene triangle using the formula:
area = √(s(s – a)(s – b)(s – c))
where s = (a + b + c) / 2.
(ii) double area(int a, int b, int height) with three integer arguments, returns the area of a trapezium using the formula:
area = 1/2 × height × (a + b)
(iii) double area(double diagonal1, double diagonal2) with two double arguments, returns the area of a rhombus using the formula:
area = 1/2 × (diagonal1 × diagonal2)

class Overload{
    public double area(double a, double b, double c){
        double s = (a + b + c) / 2;
        double ar = Math.sqrt(s * (s - a) * (s - b) * (s - c));
        return ar;
    public double area(int a, int b, int height){
        double ar = 1.0 / 2 * height * (a + b);
        return ar;
    public double area(double diagonal1, double diagonal2){
        double ar = 1.0 / 2 * (diagonal1 * diagonal2);
        return ar;

Question 8

Using the switch statement, write a menu-driven program to calculate the maturity amount of a bank deposit.
The user is given the following options:
(i) Term Deposit
(ii) Recurring Deposit
For option (i) accept Principal (p), rate of interest (r) and time period in years (n). Calculate and output the maturity amount (a) receivable using the formula a = p[1 + r / 100]n.
For option (ii) accept monthly installment (p), rate of interest (r) and time period in months (n). Calculate and output the maturity amount (a) receivable using the formula a = p * n + p * n(n + 1) / 2 * r / 100 * 1 / 12.
For an incorrect option, an appropriate error message should be displayed.

import java.io.*;
class BankDeposit{
    public static void main(String args[])
    throws IOException{
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(in);
        System.out.println("1. Term Deposit");
        System.out.println("2. Recurring Deposit");
        System.out.print("Enter your choice: ");
        int choice = Integer.parseInt(br.readLine());
            case 1:
            System.out.print("Principal: ");
            double p = Double.parseDouble(br.readLine());
            System.out.print("Rate of interest: ");
            double r = Double.parseDouble(br.readLine());
            System.out.print("Time in years: ");
            double n = Double.parseDouble(br.readLine());
            double a = p * Math.pow(1 + r / 100, n);
            System.out.println("Maturity amount: " + a);
            case 2:
            System.out.print("Monthly installment: ");
            p = Double.parseDouble(br.readLine());
            System.out.print("Rate of interest: ");
            r = Double.parseDouble(br.readLine());
            System.out.print("Time in months: ");
            n = Double.parseDouble(br.readLine());
            a = p * n + p * (n * (n + 1) / 2) * (r / 100) * (1.0 / 12);
            System.out.println("Maturity amount: " + a);
            System.out.println("Invalid input");

Question 9

Write a program to accept the year of graduation from school as an integer value from the user. Using the binary search technique on the sorted array of integers given below, output the message “Record exists” if the value input is located in the array. If not, output the message “Record does not exist”.
{1982, 1987, 1993, 1996, 1999, 2003, 2006, 2007, 2009, 2010}

import java.io.*;
class Record{
    public static void main(String args[])
    throws IOException{
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(in);
        System.out.print("Year of graduation: ");
        int a[] = {1982, 1987, 1993, 1996, 1999, 2003, 2006, 2007, 2009, 2010};
        int y = Integer.parseInt(br.readLine());
        int low = 0;
        int high = a.length - 1;
        int mid = (low + high) / 2;
        while(low <= high){
            if(y == a[mid])
            else if(y < a[mid])
                high = mid - 1;
                low = mid + 1;
            mid = (low + high) / 2;
        if(low > high)
            System.out.println("Record does not exist");
            System.out.println("Record exists");

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.