ICSE Computer Applications 2008

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 on 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 [ ].

SECTION A (40 Marks)
Attempt all questions.

Question 1 [10]
(a) Mention any two attributes required for class declaration.
Access specifier and class name.
(b) State the difference between token and identifier.
A token is the building block of a Java program.
An identifier is a variable that is used to store values in our Java program.

(c) Explain instance variable. Give an example.
An instance variable is one that becomes a separate copy for each object of a given class.
Example:

class Student{
    int roll;
}
In the above example, roll is an instance variable.
(d) What is inheritance and how is it useful in Java?
Inheritance is an object-oriented principle in which we can derive a child class from a parent class. It is useful because it helps in code reuse.
(e) Explain any two types of access specifiers.
The public access specifier allows a class member to be accessed from anywhere.
The private access specifier allows a class member to be accessed only from within the class in which it is defined.

Question 2 [10]
(a) What is meant by an infinite loop? Give an example.
An infinite loop is one that never terminates.
Example:

while(true){
    System.out.println("Hello");
}
(b) State the difference between == operator and equals() method.
The == is a relational operator that lets us check if two values are same or not.
The equals() method is a member of the String class that checks if two String values have identical content or not.

(c) Differentiate between actual parameter and formal parameter.
The parameter passed during method call are known as actual parameters.
The parameters passed during method definition are known as formal parameters.

(d) What is the use of exception handling in Java?
Exception handling is used to deal with the runtime errors that may occur in our Java program.
(e) Differentiate between base and derived class.
The base class is the parent class whereas the derived class is the child class.

Question 3
(a) Explain the function of each of the following with an example: [4]
(i) break;
The break keyword is used to terminate a loop or a switch case.
Example:

for(int i = 1; i <= 10; i++){
    if(i % 3 == 0)
        break;
    System.out.println(i);
}
(ii) continue
The continue keyword is used to skip the current iteration of a loop and move to the next iteration.
Example:

for(int i = 1; i <= 10; i++){
    if(i % 3 == 0)
        continue;
    System.out.println(i);
}
(b) Convert the following segment into equivalent for loop: [2]

{
    int i, l = 0;
    while(i <= 20)
        System.out.print(i + " ");
    l++;
}
{
    int i, l = 0;
    for(; i <= 20;){
        System.out.print(i + " ");
        l++;
    }
}

(c) If a = 5, b = 9, calculate the value of a += a++ - ++b + a; [2]
a = a + (a++ - ++b + a)
a = 5 + (5 - 10 + 6)
a = 5 + 1
a = 6

(d) Give the output of the following expressions: [2]
(i) If x = -9.99, calculate Math.abs(x);
9.99
(ii) If x = 9.0, calculate Math.sqrt(x);
3.0
(e) If String x = "Computer";
String y = "Applications";
What do the following functions return? [4]
(i) System.out.println(x.substring(1, 5));
ompu
(ii) System.out.println(x.indexOf(x.charAt(4)));
4
(iii) System.out.println(y + x.substring(5));
Applicationster
(iv) System.out.println(x.equals(y));
false
(f) If array[] = {1, 9, 8, 5, 2}; [2]
(i) What is array.length()?
5
(ii) What is array[2]?
8
(g) What does the following mean? [2]
Employee staff = new Employee();
An object named 'staff' is being created of class 'Employee'.
(h) Write a Java statement to input/read the following from the user using the keyboard: [2]
(i) Character
char ch = in.readLine().charAt(0);
(ii) String
String s = in.readLine();

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 [15]
Define a class Employee having the following description:
Data members/instance variables:
int pan - to store the personal account number
String name - to store name
double taxIncome - to store annual taxable income
double tax - to store tax that is calculated
Member functions:
input() - store the pan number, name, taxable income
calc() - calculate tax for an employee
display() - output details of an employee
Write a program to compute the tax according to the given conditions and display the output as per given format:

Total Annual Taxable IncomeTax Rate
Up to Rs. 1,00,000No tax
From 1,00,001 to 1,50,00010% of the income tax exceeding Rs. 1,00,000
From 1,50,001 to 2,50,000Rs. 5000 + 20% of the income exceeding Rs. 1,50,000
Above Rs. 2,50,000Rs. 25,000 + 30% of the income exceeding Rs. 2,50,000
Output:
Pan NumberNameTax-incomeTax
----
----
----
----
import java.util.Scanner;
class Employee{
    int pan;
    String name;
    double taxIncome;
    double tax;
    public void input(){
        Scanner in = new Scanner(System.in);
        System.out.print("PAN Number: ");
        pan = Integer.parseInt(in.nextLine());
        System.out.print("Name: ");
        name = in.nextLine();
        System.out.print("Taxable income: ");
        taxIncome = Integer.parseInt(in.nextLine());
    }
    public void calc(){
        if(taxIncome <= 100000)
            tax = 0.0;
        else if(taxIncome <= 150000)
            tax = 0.1 * (taxIncome - 100000);
        else if(taxIncome <= 250000)
            tax = 5000 + 0.2 * (taxIncome - 150000);
        else
            tax = 25000 + 0.3 * (taxIncome - 250000);
    }
    public void display(){
        System.out.println("PAN\tName\tIncome\tTax");
        System.out.println(pan + "\t" + name + "\t" + taxIncome + "\t" + tax);
    }
    public static void main(String args[]){
        Employee obj = new Employee();
        obj.input();
        obj.calc();
        obj.display();
    }
}
Question 5 [15]
Write a program to input a string and print out the text with the uppercase and lowercase letters reversed, but all other characters should remain the same as before:
Example:
INPUT: WelComE TO School
OUTPUT: wELcOMe to sCHOOL
import java.util.Scanner;
class Reverse{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        System.out.print("Enter the string: ");
        String s = in.nextLine();
        String t = "";
        for(int i = 0; i < s.length(); i++){
            char ch = s.charAt(i);
            if(Character.isUpperCase(ch))
                t += Character.toLowerCase(ch);
            else
                t += Character.toUpperCase(ch);
        }
        System.out.println(t);
    }
}

Question 6 [15]
Define a class and store the given city names in a single dimensional array. Sort these names in alphabetical order using the Bubble Sort technique only.
INPUT: Delhi, Bangalore, Agra, Mumbai, Calcutta
OUTPUT: Agra, Bangalore, Calcutta, Delhi, Mumbai
class Bubble{
    public static void main(String args[]){
        String a[] = {"Delhi", "Bangalore", "Agra", "Mumbai", "Calcutta"};
        for(int i = 0; i < a.length; i++){
            for(int j = 0; j < a.length - 1 - i; j++){
                if(a[j].compareTo(a[j + 1]) > 0){
                    String 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.print(a[i] + " ");
        System.out.println();
    }
}

Question 7 [15]
Write a menu-driven class to accept a number from the user and check whether it is a Palindrome or a Perfect number.
(a) Palindrome number - a number is a Palindrome which when read in reverse order is same as read in the right order. Example: 11, 101, 151 etc.
(b) Perfect number - a number is called Perfect if it is equal to the sum of its factors other than the number itself. Example: 6 = 1 + 2 + 3
import java.util.Scanner;
class Menu{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        System.out.println("1. Palindrome number");
        System.out.println("2. Perfect number");
        System.out.print("Enter your choice: ");
        int choice = Integer.parseInt(in.nextLine());
        switch(choice){
            case 1:
            System.out.print("Enter the number: ");
            int n = Integer.parseInt(in.nextLine());
            int rev = 0;
            for(int i = n; i != 0; i /= 10)
                rev = rev * 10 + i % 10;
            if(n == rev)
                System.out.println("Palindrome number!");
            else
                System.out.println("Not a Palindrome number.");
            break;
            case 2:
            int sum = 0;
            System.out.print("Enter the number: ");
            n = Integer.parseInt(in.nextLine());
            for(int i = 1; i <= n / 2; i++){
                if(n % i == 0)
                    sum += i;
            }
            if(n == sum)
                System.out.println("Perfect number!");
            else
                System.out.println("Not a Perfect number.");
            break;
            default:
            System.out.println("Invalid choice!");
        }
    }
}

Question 8 [15]
Write a class with the name Volume using function overloading that computes the volume of a cube, a sphere and a cuboid.
Formula:
volume of a cube = s * s * s
volume of a sphere = 4 / 3 * π * r * r * r (where π = 3.14 or 22 / 7)
volume of a cuboid = l * b * h
class Volume{
    public static double volume(double s){
        return Math.pow(s, 3);
    }
    public static double volume(double pi, double r){
        return 4.0 / 3 * pi * Math.pow(r, 3);
    }
    public static double volume(double l, double b, double h){
        return l * b * h;
    }
}

Question 9 [15]
Write a program to calculate and print the sum of each of the following series:
(a) Sum (S) = 2 - 4 + 6 - 8 + ... - 20
(b) Sum (S) = x / 2 + x / 5 + x / 8 + x / 11 + ... + x / 20
(Value of x to be input by the user)
import java.util.Scanner;
class Series{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        int s1 = 0;
        double s2 = 0.0;
        for(int i = 2; i <= 20; i += 2){
            if(i % 4 == 0)
                s1 -= i;
            else
                s1 += i;
        }
        System.out.println("Series 1 sum: " + s1);
        System.out.print("x = ");
        double x = Double.parseDouble(in.nextLine());
        for(int i = 2; i <= 20; i += 3)
            s2 += x / i;
        System.out.println("Series 2 sum: " + s2);
    }
}

Comments

Popular posts from this blog

Encrypt Program ISC Specimen 2023 Theory

No Repeat Program ISC Computer Science 2022 Semester 2 Theory

Bank Inheritance Program ISC Specimen 2023 Theory