ICSE Computer Applications 2019

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 any four questions from Section B.
The intended marks for questions or parts of questions are given in brackets [ ].
This paper is divided into two sections.
Attempt all questions from Section A and any four questions from Section B.
The intended marks for questions or parts of questions are given in brackets [ ].

SECTION A
Attempt all questions.

Question 1
(a) Name any two basic principles of object-oriented programming.
Inheritance, Polymorphism

(b) Write a difference between unary and binary operator.
Unary operators act on one operand, whereas binary operators act on two operands.

(c) Name the keyword which:
(i) indicates that a method has no return type.
void keyword
(ii) makes the variable as a class variable.
static keyword

(d) Write the memory capacity (storage size) of short and float data type in bytes.
short = 2 bytes
float = 4 bytes

(e) Identify and name the following tokens:
(i) public
Keyword
(ii) ‘a’
Literal
(iii) ==
Operator
(iv) { }
Separator

Question 2
(a) Differentiate between if else if and switch-case statements.
if else is is capable of performing all kinds of comparisons, but switch case can only perform comparisons for equality.

(b) Give the output of the following code:
String p = “20”, q = “19”;
int a = Integer.parseInt(p);
int b = Integer.parseInt(q);
System.out.println(a + “” + b);
2019

(c) What are the various types of errors in Java?
Syntax error (Compile-time error)
Runtime error (Exception)
Logical error

(d) State the data type and value of res after the following is executed:
char ch = ‘9’;
res = Character.isDigit(ch);
res = true
Data type = boolean

(e) What is the difference between the linear search and the binary search technique?
Linear search can be applied on both sorted as well as unsorted lists, whereas binary search can only be applied on sorted lists.

Question 3
(a) Write a Java expression for the following:
|x2 + 2xy|
Math.abs(x * x + 2 * x * y)

(b) Write the return data type of the following functions:
(i) startsWith()
boolean data type
(ii) random()
double data type

(c) If the value of basic = 1500, what will be the value of tax after the following statement is executed?
tax = basic > 1200? 200 : 100;
tax = 200

(d) Give the output of the following code and mention how many times the loop will execute:
int i;
for(i = 5; i >= 1; i–){
if(i % 2 == 1)
continue;
System.out.print(i + ” “);
}
Output:
4 2
The loop will execute 5 times.

(e) State a difference between call by value and call by reference.
In call by value, the changes made to the formal parameters do not reflect on the actual arguments. But in call by reference, changes made in formal parameters are reflected on the actual arguments.

(f) Give the output of the following:
Math.sqrt(Math.max(9, 16))
4.0

(g) Write the output for the following:
String s1 = “phoenix”;
String s2 = “island”;
System.out.println(s1.substring(0).concat(s2.substring(2)));
System.out.println(s2.toUpperCase());
phoenixland
ISLAND

(h) Evaluate the following expression if the value of x = 2, y = 3 and z = 1.
v = x + –z + y++ + y;
v = 2 + 0 + 3 + 4
v = 9

(i) String x[] = {“Artificial intelligence”, “IOT”, “Machine learning”, “Big data”};
Give the output of the following statements:
(i) System.out.println(x[3]);
Big data
(ii) System.out.println(x.length);
4

(j) What is meant by a package? Give one example.
A package is a collection of related classes and interfaces. Example: java.util package.

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

Question 4
Design a class ShowRoom with the following description:
Instance variables/data members:
String name – to store the name of the customer
long mobNo – to store the mobile number of the customer
double cost – to store the cost of the items purchased
double dis – to store the discount amount
double amount – to store the amount to be paid after discount
Member methods:
ShowRoom() – default constructor to initialize data members
void input() – to input customer name, mobile number, cost
void calculate() – to calculate discount on the cost of purchased items, based on the following criteria:

CostDiscount (in percentage)
Less than or equal to ₹ 100005%
More than ₹ 10000 and less than or equal to ₹ 2000010%
More than ₹ 20000 and less than or equal to ₹ 3500015%
More than ₹ 3500020%

void display() – to display customer name, mobile number, amount to be paid after discount
Write a main() method to create an object of the class and call the above member methods.

import java.util.Scanner;
class ShowRoom{
    String name;
    long mobNo;
    double cost;
    double dis;
    double amount;
    public ShowRoom(){
        name = "";
        mobNo = 0L;
        cost = 0.0;
        dis = 0.0;
        amount = 0.0;
    }
    public void input(){
        Scanner in = new Scanner(System.in);
        System.out.print("Name: ");
        name = in.nextLine();
        System.out.print("Mobile number: ");
        mobNo = Long.parseLong(in.nextLine());
        System.out.print("Cost of items: ");
        cost = Double.parseDouble(in.nextLine());
    }
    public void calculate(){
        if(cost <= 10000)
            dis = 5.0;
        else if(cost <= 20000)
            dis = 10.0;
        else if(cost <= 35000)
            dis = 15.0;
        else
            dis = 20.0;
        dis = dis / 100 * cost;
        amount = cost - dis;
    }
    public void display(){
        System.out.println("Name: " + name);
        System.out.println("Mobile number: " + mobNo);
        System.out.println("Amount: " + amount);
    }
    public static void main(String[] args){
        ShowRoom obj = new ShowRoom();
        obj.input();
        obj.calculate();
        obj.display();
    }
}

Question 5
Using the switch-case statement, write a menu-driven program to do the following:
(a) To generate and print letters from A to Z and their Unicode

Letters	Unicode
A	65
B	66
.	.
.	.
.	.
Z	90

(b) Display the following pattern using iteration (looping) statement:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

import java.util.Scanner;
class Menu{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        System.out.println("1. Unicode");
        System.out.println("2. Pattern");
        System.out.print("Enter your choice: ");
        int choice = Integer.parseInt(in.nextLine());
        switch(choice){
        case 1:
            System.out.println("Letters\tUnicode");
            for(char i = 'A'; i <= 'Z'; i++)
                System.out.println(i + "\t" + (int)i);
            break;
        case 2:
            for(int i = 1; i <= 5; i++){
                for(int j = 1; j <= i; j++)
                    System.out.print(j + " ");
                System.out.println();
            }
            break;
        default:
            System.out.println("Invalid choice!");
        }
    }
}

Question 6
Write a program to input 15 integer elements in an array and sort them in ascending order using the 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[15];
        System.out.println("Enter 15 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("Sorted list:");
        for(int i = 0; i < a.length; i++)
            System.out.println(a[i] + " ");
        System.out.println();
    }
}

Question 7
Design a class to overload a function series() as follows:
(a) void series(int x, int n) – to display the sum of the series given below:
x1 + x2 + x3 + … xn terms
(b) void series(int p) – to display the following series:
0, 7, 26, 63, … p terms
(c) void series() – to display the sum of the series given below:
Series Sum ICSE 2019 Question

class Overload{
    public void series(int x, int n){
        double s = 0.0;
        for(int i = 1; i <= n; i++)
            s += Math.pow(x, i);
        System.out.println("Sum = " + s);
    }
    public void series(int p){
        for(int i = 1; i <= p; i++){
            int x = (int)Math.pow(i, 3) - 1;
            System.out.print(x + " ");
        }
        System.out.println();
    }
    public void series(){
        double s = 0.0;
        for(int i = 2; i <= 10; i++)
            s += 1.0 / i;
        System.out.println("Sum = " + s);
    }
}

Question 8
Write a program to input a sentence and convert it into uppercase and count and display the total number of words starting with a letter ‘A’.
Example:
Sample Input: ADVANCEMENT AND APPLICATION OF INFORMATION TECHNOLOGY ARE EVER CHANGING.
Sample Output: Total number of words starting with letter ‘A’ = 4.

import java.util.Scanner;
class Starting{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        System.out.print("Enter the sentence: ");
        String s = in.nextLine().toUpperCase();
        int count = 0;
        for(int i = 0; i < s.length(); i++){
            char ch = s.charAt(i);
            if(i == 0 || s.charAt(i - 1) == ' '){
                if(ch == 'A')
                    count++;
            }
        }
        System.out.println("Words starting with letter 'A' = " + count);
    }
}

Question 9
A tech number has even number of digits. If the number is split in two halves, then the square of sum of these halves is equal to the number itself. Write a program to generate and print all four-digit tech numbers.
Example:
Consider the number 3025
Square of sum of the halves of 3025 = (30 + 25)2
= (55)2
= 3025 is a tech number.

class Tech{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        for(int i = 1000; i <= 9999; i++){
            int a = i / 100;
            int b = i % 100;
            int s = (a + b) * (a + b);
            if(i == s)
                System.out.print(i + " ");
        }
    }
}