Categories
Class 10

ICSE Computer Applications Year 2015

Section A (40 Marks)

Attempt all questions

Question 1

(a) What are the default values of the primitive data type int and float?
Default value of int is 0.
Default value of float is 0.0F.

(b) Name any two OOP principles.
Encapsulation and Abstraction.

(c) What are identifiers?
Identifiers are the fundamental building blocks of a program and are used as the general terminology for the names given to different parts of the program such as variables, objects, classes, functions, arrays, etc.

(d) Identify the literals listed below:
(i) 0.5 – Real Literal
(ii) ‘A’ – Character Literal
(iii) false – Boolean Literal
(iv) “a” – String Literal

(e) Name the wrapper classes of char type and boolean type.
Character is for char.
Boolean is for boolean.

Question 2

(a) Evaluate the value of n if value of p = 5, q = 19.
int n = (q - p) > (p - q)? (q - p) : (p - q);
n = 19 – 5 = 14.

(b) Arrange the following primitive data types in ascending order of their size:
(i) char (ii) byte (iii) double (iv) int
Ascending order: byte, char, int, double

(c) What is the value stored in variable res given below:
double res = Math.pow("345".indexOf('5'), 3);
res = 8.0

(d) Name the two types of constructors.
Parameterized constructors and non-parameterized constructors.

(e) What are the values of a and b after the following function is executed, if the values passed are 30 and 50:

void paws(int a, int b){
    a = a + b;
    b = a - b;
    a = a - b;
    System.out.println(a + ", " + b);
}

OUTPUT:
50, 30

Question 3

(a) State the data type and value of y after the following is executed:
char x = '7';
y = Character.isLetter(x);

Value of y is false.
Data type of y is boolean.

(b) What is the function of catch block in exception handling? Where does it appear in a program?
The catch block traps the exception and handles it. It appears once the try block is closed in the program.

(c) State the output when the following program segment is executed:
String a = "Smartphone", b = "Graphic Art";
String h = a.substring(2, 5);
String k = b.substring(8).toUpperCase();
System.out.println(h);
System.out.println(k.equalsIgnoreCase(h));

OUTPUT:
art
true

(d) The access specifier that gives the most accessibility is ________ and the least accessibility is ________.
public, private

(e) (i) Name the mathematical function which is used to find sine of an angle given in radians.
Math.sin()
(ii) Name a string function which removes the blank spaces provided in the prefix and suffix of a string.
trim()

(f) (i) What will this code print?
int arr[] = new int[5];
System.out.println(arr);

(i) 0 (ii) value stored in arr[0] (iii) 0000 (iv) garbage value
(ii) Name the keyword which is used to resolve the conflict between method parameter and instance variables/fields.
this keyword.

(g) State the package that contains the class:
(i) BufferedReader – java.io package
(ii) Scanner – java.util package

(h) Write the output of the following program code:

char ch;
int x = 97;
do{
    ch = (char)x;
    System.out.print(ch + " ");
    if(x % 10 == 0)
        break;
    ++x;
}while(x <= 100);

OUTPUT:
a b c d

(i) Write the Java expression for:
(a2 + b2) ÷ 2ab
(a * a + b * b) / (2 * a * b)

(j) If int y = 10 then find int z = (++y * (y++ + 5));
z = (11 * (11 + 5))
= 11 * 16
= 176.

Section B (60 Marks)

Attempt any four questions from this section.

Question 4

Define a class called ParkingLot with the following description:
Instance variables/data members:
int vno: to store the vehicle number.
int hours: to store the number of hours the vehicle is parked in the parking lot.
double bill: to store the bill amount.
Methods:
void input(): to input and store the vehicle number and hours.
void calculate(): to compute the parking charge at the rate of Rs. 3 for the first hour or part thereof, and Rs. 1.50 for each additional hour or part thereof.
void display(): to display the detail.
Write a main() method to create an object of the class and call the above methods.

import java.io.*;
class ParkingLot{
    int vno;
    int hours;
    double bill;
    public void input()throws IOException{
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(in);
        System.out.print("Vehicle Number: ");
        vno = Integer.parseInt(br.readLine());
        System.out.print("Hours: ");
        hours = Integer.parseInt(br.readLine());
    }
    public void calculate(){
        if(hours <= 1)
            bill = 3.0;
        else
            bill = 3.0 + 1.5 * (hours - 1);
    }
    public void display(){
        System.out.println("Vehicle Number: " + vno);
        System.out.println("Hours: " + hours);
        System.out.println("Bill: Rs. " + bill);
    }
    public static void main(String args[])
    throws IOException{
        ParkingLot obj = new ParkingLot();
        obj.input();
        obj.calculate();
        obj.display();
    }
}

Question 5

Write two separate programs to generate the following patterns using iteration (loop) statements:
(a)

*
*#
*#*
*#*#
*#*#*
class Pattern1{
    public static void main(String args[]){
        char ch = '*';
        for(int i = 1; i <= 5; i++){
            ch = '*';
            for(int j = 1; j <= i; j++){
                System.out.print(ch);
                if(ch == '*')
                    ch = '#';
                else
                    ch = '*';
            }
            System.out.println();
        }
    }
}

(b)

5 4 3 2 1
5 4 3 2
5 4 3
5 4
5
class Pattern2{
    public static void main(String args[]){
        for(int i = 1; i <= 5; i++){ 
            for(int j = 5; j >= i; j--)
                System.out.print(j + " ");
            System.out.println();
        }
    }
}

Question 6

Write a program to input and store roll numbers, names and marks in 3 subjects of n number of students in five single-dimensional arrays and display the remark based on average marks as given below:
Average marks = Total Marks ÷ 3

Average Marks      Remark
85 - 100           EXCELLENT
75 - 84            DISTINCTION
60 - 74            FIRST CLASS
40 - 59            PASS
Less than 40       POOR

The maximum marks in the subject are 100.

import java.io.*;
class Result{
    public static void main(String args[])
    throws IOException{
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(in);
        System.out.print("Number of students: ");
        int n = Integer.parseInt(br.readLine());
        int roll[] = new int[n];
        String name[] = new String[n];
        int m1[] = new int[n];
        int m2[] = new int[n];
        int m3[] = new int[n];
        int total = 0;
        double avg = 0.0;
        for(int i = 0; i < n; i++){ 
            System.out.print("Roll number: "); 
            roll[i] = Integer.parseInt(br.readLine()); 
            System.out.print("Name: "); 
            name[i] = br.readLine(); 
            System.out.print("Marks 1: "); 
            m1[i] = Integer.parseInt(br.readLine()); 
            System.out.print("Marks 2: "); 
            m2[i] = Integer.parseInt(br.readLine()); 
            System.out.print("Marks 3: "); 
            m3[i] = Integer.parseInt(br.readLine()); 
            total = m1[i] + m2[i] + m3[i]; 
            avg = total / 3.0; 
            if(avg >= 85 && avg <= 100) 
                System.out.println("EXCELLENT"); 
            else if(avg >= 75 && avg < 85) 
                System.out.println("DISTINCTION"); 
            else if(avg >= 60 && avg < 75) 
                System.out.println("FIRST CLASS"); 
            else if(avg >= 40 && avg < 60)
                System.out.println("PASS");
            else
                System.out.println("POOR");
        }
    }
}

Question 7

Design a class to overload a function joyString() as follows:
(i) void joyString(String s, char ch1, char ch2) with one string argument and two character arguments that replaces the character argument ch1 with the character argument ch2 in the given string s and prints the new string.
Example:
INPUT:
s = “TECHNALAGY”
ch1 = ‘A’
ch2 = ‘O’
OUTPUT:
“TECHNOLOGY”
(ii) void joyString(String s) with one string argument that prints the position of the first space and the last space of the given string s.
Example:
INPUT:
s = “Cloud computing means Internet-based computing”
OUTPUT:
First index: 5
Last index: 36
(iii) void joyString(String s1, String s2) with two string arguments that combines the two strings with a space between them and prints the resultant string.
Example:
INPUT:
s1 = “COMMON WEALTH”
s2 = “GAMES”
OUTPUT:
COMMON WEALTH GAMES
(use library functions)

class Overload{
    public static void joyString(String s, char ch1, char ch2){
        s = s.replace(ch1, ch2);
        System.out.println(s);
    }
    public static void joyString(String s){
        int first = s.indexOf(' ');
        int last = s.lastIndexOf(' ');
        System.out.println("First index: " + first);
        System.out.println("Last index: " + last);
    }
    public static void joyString(String s1, String s2){
        String s = s1 + " " + s2;
        System.out.println(s);
    }
}

Question 8

Write a program to input twenty names in an array. Arrange these names in descending order of alphabets, using the bubble sort technique.

import java.io.*;
class Sort{
    public static void main(String args[])
    throws IOException{
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(in);
        String n[] = new String[20];
        System.out.println("Enter 20 names:");
        for(int i = 0; i < 20; i++)
            n[i] = br.readLine();
        for(int i = 0; i < 20; i++){
            for(int j = 0; j < 20 - 1 - i; j++){
                if(n[j].compareToIgnoreCase(n[j + 1]) < 0){
                    String temp = n[j];
                    n[j] = n[j + 1];
                    n[j + 1] = temp;
                }
            }
        }
        System.out.println("\nSorted names:");
        for(int i = 0; i < 20; i++)
            System.out.print(n[i] + "\t");
    }
}

Question 9

Using the switch statement, write a menu-driven program to:
(i) To find and display all the factors of a number input by the user (including 1 and excluding the number itself).
Example:
INPUT:
n = 15
OUTPUT:
1, 3, 5
(ii) To find and display the factorial of a number input by the user. The factorial of a non-negative integer n, denoted by n!, is the product of all integers less than or equal to n.
Example:
INPUT:
n = 5
OUTPUT:
5! = 1 × 2 × 3 × 4 × 5 = 120.
For an incorrect choice, an appropriate error message should be displayed.

import java.io.*;
class MenuDriven{
    public static void main(String args[])
    throws IOException{
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(in);
        System.out.println("1. Factors");
        System.out.println("2. Factorial");
        System.out.print("Enter your choice: ");
        int choice = Integer.parseInt(br.readLine());
        switch(choice){
            case 1:
            System.out.print("Number: ");
            int n = Integer.parseInt(br.readLine());
            for(int i = 1; i < n; i++){
                if(n % i == 0)
                    System.out.print(i + "\t");
            }
            break;
            case 2:
            System.out.print("Number: ");
            n = Integer.parseInt(br.readLine());
            int f = 1;
            for(int i = 1; i <= n; i++)
                f *= i;
            System.out.println(f);
            break;
            default:
            System.out.println("Invalid choice!");
        }
    }
}

Leave a Reply