ICSE Computer Applications 2013

COMPUTER APPLICATIONS
(Theory)
(Two hours)
Answers to this paper must be written on the paper provided separately.
You will not be allowed to write during the first 15 minutes.
This time is to be spent in reading the question paper.
The time given at the head of this paper is the time allowed for writing the answers.
This paper is divided into two sections.
Attempt all questions from Section A and only four questions from Section B.
The intended marks for questions or parts of questions are given in brackets [ ].

SECTION A (40 Marks)
Attempt all questions.

Question 1
(a) What is meant by precedence of operators?
Operator precedence means the sequence in which different operators are evaluated when used together in an expression.

(b) What is a literal?
A literal is a constant value which doesn’t change during program execution.

(c) State the Java concept that is implemented through:
(i) a super class and a subclass
Inheritance
(ii) the act of representing essential features without including background details
Data Abstraction

(d) Give a difference between a constructor and a method.
A constructor has no return type. Not even void. A method always has a return type.

(e) What are the types of casting shown by the following examples?
(i) double x = 15.2;
int y = (int)x;
Explicit type casting
(ii) int x = 12;
long y = x;
Implicit type casting

Question 2
(a) Name any two wrapper classes.
Integer class and Double class.

(b) What is the difference between a break statement and a continue statement when they occur in a loop?
The break keyword is used to exit from a loop, whereas the continue keyword is used to skip to the next iteration of the loop.

(c) Write statements to show how finding the length of a character array char[] arr differs from finding the length of a String object str.
int len = arr.length;
int size = str.length();

(d) Name the Java keyword that:
(i) indicates that a method has no return type
void keyword
(ii) stores the address of the currently-calling object
this keyword

(e) What is an exception?
An exception is a run-time error. Example: Divide by zero error.

Question 3
(a) Write a Java statement to create an object mp4 of class digital.
digital mp4 = new digital();

(b) State the values stored in the variables str1 and str2:
String s1 = “good”;
String s2 = “world matters”;
String str1 = s2.substring(5).replace(‘t’, ‘n’);
String str2 = s1.concat(str1);
str1 = ” manners”
str2 = “good manners”

(c) What does a class encapsulate?
A class encapsulates properties and behavior.

(d) Rewrite the following program segment using if else statement:
comm = (sale > 150000)? sale * 5 / 100 : 0;
if(sale > 150000)
    comm = sale * 5 / 100;
else
    comm = 0;

(e) How many times will the following loop execute? What value will be returned?
int x = 2, y = 50;
do{
    ++x;
    y -= x++;
}while(x <= 10);
return y;
The loop executes 5 times.
15 is returned.

(f) What is the data type that the following library functions return?
(i) isWhitespace(char ch)
boolean data type
(ii) Math.random()
double data type

(g) Write a Java expression for:
Mathematical Expression ICSE 2013 Computer Applications
u * t + 1.0 / 2 * f * t * t

(h) If int n[] = {1, 2, 3, 5, 7, 9, 13, 16} what are the values of x and y?
x = Math.pow(n[4], n[2]);
x = 343.0
y = Math.sqrt(n[5] + n[7]);
y = 5.0

(i) What is the final value of ctr when the iteration process given below, executes?
int ctr = 0;
for(int i = 1; i <= 5; i++)
    for(int j = 1; j <= 5; j += 2)
        ++ctr;
The final value of ctr will be 15.

(j) Name the methods of Scanner class that:
(i) is used to input an integer data from the standard input stream
nextInt() method
(ii) is used to input a String data from the standard input stream
nextLine() method

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/mnemonic codes such that the logic of the program is clearly depicted.
Flowcharts and algorithms are not required.

Question 4
Define a class named FruitJuice with the following description:
Instance variables/data members:
int productCode – stores the product code number
String flavour – stores the flavour of the juice (Example: orange, apple, etc.)
String packType – stores the type of packaging (Example: tetra-pack, PET bottle, etc.)
int packSize – stores package size (Example: 200 ml, 400 ml, etc.)
int productPrice – stores the price of the product
Member methods:
FruitJuice() – default constructor to initialize integer data members to 0 and String data members to “”.
void input() – to input and store the product code, pack type, pack size and product price
void discount() – to reduce the price by 10
void display() – to display the product code, flavour, pack type, pack size and product price

import java.util.Scanner;
class FruitJuice{
    int productCode;
    String flavour;
    String packType;
    int packSize;
    int productPrice;
    public FruitJuice(){
        productCode = 0;
        flavour = "";
        packType = "";
        packSize = 0;
        productPrice = 0;
    }
    public void input(){
        Scanner in = new Scanner(System.in);
        System.out.print("Product code: ");
        productCode = Integer.parseInt(in.nextLine());
        System.out.print("Flavour: ");
        flavour = in.nextLine();
        System.out.print("Pack type: ");
        packType = in.nextLine();
        System.out.print("Pack size: ");
        packSize = Integer.parseInt(in.nextLine());
        System.out.print("Product price: ");
        productPrice = Integer.parseInt(in.nextLine());
    }
    public void discount(){
        productPrice -= 10;
    }
    public void display(){
        System.out.println("Product code: " + productCode);
        System.out.println("Flavour: " + flavour);
        System.out.println("Pack type: " + packType);
        System.out.println("Pack size: " + packSize);
        System.out.println("Product price: " + productPrice);
    }
    public static void main(String[] args) {
        FruitJuice obj = new FruitJuice();
        obj.input();
        obj.discount();
        obj.display();
    }
}

Question 5
The International Standard Book Number (ISBN) is a unique numeric book identifier which is printed on every book. The ISBN is based upon a 10-digit code. The ISBN is legal if: 1 × digit1 + 2 × digit2 + 3 × digit3 + 4 × digit4 + 5 × digit5 + 6 × digit6 + 7 × digit7 + 8 × digit8 + 9 × digit9 + 10 × digit10 is divisible by 11.
Example: For an ISBN 1401601499
Sum = 1 × 1 + 2 × 4 + 3 × 0 + 4 × 1 + 5 × 6 + 6 × 0 + 7 × 1 + 8 × 4 + 9 × 9 + 10 × 9 = 253 which is divisible by 11.
Write a program to:
(i) Input the ISBN code as a 10-digit integer.
(ii) If the ISBN is not a 10-digit integer, output the message, “Illegal ISBN” and terminate the program.
(iii) If the number is 10-digit, extract the digits of the number and compute the sum as explained above.
If the sum is divisible by 11, output the message, “Legal ISBN”. If the sum is not divisible by 11, output the message, “Illegal ISBN”.

import java.util.Scanner;
class ISBN{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        System.out.print("Enter ISBN Number: ");
        long isbn = Long.parseLong(in.nextLine());
        int count = 0;
        for(long i = isbn; i != 0; i /= 10)
            count++;
        if(count != 10){
            System.out.println("Illegal ISBN");
            return;
        }
        int sum = 0;
        for(int i = 10; i >= 1; i--){
            int d = (int)(isbn % 10);
            sum += d * i;
            isbn /= 10;
        }
        if(sum % 11 == 0)
            System.out.println("Legal ISBN");
        else
            System.out.println("Illegal ISBN");
    }
}

Question 6
Write a program that encodes a word into Piglatin. To translate word into a Piglatin word, convert the word into uppercase and then place the first vowel of the original word as the start of the new word along with the remaining alphabets. The alphabets present before the vowel being shifted towards the end followed by “AY”.
Sample Input 1: London
Output: ONDONLAY
Sample Input 2: Olympics
Output: OLYMPICSAY

import java.util.Scanner;
class Piglatin{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        System.out.print("Enter the word: ");
        String w = in.next().toUpperCase();
        int i;
        for(i = 0; i < w.length(); i++){
            char ch = w.charAt(i);
            if("AEIOU".indexOf(ch) >= 0)
                break;
        }
        String p = w.substring(i) + w.substring(0, i) + "AY";
        System.out.println(p);
    }
}

Question 7
Write a program to input 10 integer elements in an array and sort them in descending order using bubble sort technique.

import java.util.Scanner;
class Bubble{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int a[] = new int[10];
        System.out.println("Enter 10 integers:");
        for(int i = 0; i < a.length; i++)
            a[i] = Integer.parseInt(in.nextLine());
        for(int i = 0; i < a.length; i++){
            for(int j = 0; j < a.length - 1 - i; j++){
                if(a[j] < a[j + 1]){
                    int temp = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = temp;
                }
            }
        }
        System.out.println("Descending order:");
        for(int i = 0; i < a.length; i++)
            System.out.print(a[i] + " ");
        System.out.println();
    }
}

Question 8
Design a class to overload a function series() as follows:
(i) double series(double n) with one double argument and returns the sum of the series:
ICSE Computer Applications 2013 Series 1
(ii) double series(double a, double n) with two double arguments and returns the sum of the series:
ICSE Computer Applications 2013 Series 2

class Overload{
    public static double series(double n){
        double sum = 0.0;
        for(int i = 1; i <= n; i++)
            sum += 1.0 / i;
        return sum;
    }
    public static double series(double a, double n){
        double sum = 0.0;
        int num = 1;
        for(int i = 1; i <= n; i++){
            sum += num / Math.pow(a, num + 1);
            num += 3;
        }
        return sum;
    }
    public static void main(String[] args) {
        double x = series(5);
        System.out.println("Sum 1 = " + x);
        double y = series(4, 5);
        System.out.println("Sum 2 = " + y);
    }
}

Question 9
Using the switch statement, write a menu-driven program:
(i) To check and display whether a number input by the user is a composite number or not. A number is said to be composite, if it has one or more than one factor excluding 1 and the number itself.
Example: 4, 6, 8, 9, …
(ii) To find the smallest digit of an integer that is input:
Sample Input: 6524
Sample Output: Smallest digit is 2
For an incorrect choice, an appropriate error message should be displayed.

import java.util.Scanner;
class Menu{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("1. Composite number");
        System.out.println("2. Smallest digit");
        System.out.print("Enter your choice: ");
        int choice = Integer.parseInt(in.nextLine());
        switch(choice){
        case 1:
            System.out.print("Number to be checked: ");
            int n = Integer.parseInt(in.nextLine());
            boolean flag = false;
            for(int i = 2; i <= n / 2; i++){
                if(n % 2 == 0){
                    flag = true;
                    break;
                }
            }
            if(flag)
                System.out.println("Composite number");
            else
                System.out.println("Not a Composite number");
            break;
        case 2:
            System.out.print("Enter the number: ");
            n = Integer.parseInt(in.nextLine());
            int d = n % 10;
            for(int i = n; i != 0; i /= 10){
                if(d > i % 10)
                    d = i % 10;
            }
            System.out.println("Smallest digit: " + d);
            break;
        default:
            System.out.println("Invalid choice!");
        }
    }
}

Leave a Reply

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