Ads

ICSE Solved Paper, 2015

ICSE Examination 2015 – 16 (Solution) 

COMPUTER APPLICATION 
Class – X 
SECTION – A (40 MARKS)
Attempt all questions


Question 1:

(a) What are the default values of the primitive data types int and float? [2] 
Ans: The default value of int is 0 and the default value of float is 0.0f.

(b) Name any two OOP’s principles. [2] 
Ans: Abstraction, Encapsulation, Inheritance, Polymorphism. 

(c) What are identifiers? [2] 
Ans: Identifiers are names of variables, classes, packages, methods and packages in a java program.

(d) Identify the literals listed below: 
(i) 0.5
(ii) 'A'
(iii) false
(iv) ''a'' [2] 
Ans: - (i) Floating point literal
(ii) Character literal
(iii) Boolean literal
(iv) String literal

(e) Name the wrapper class of char type and boolean type. [2] 
Ans: The wrapper class of char type is Character and the wrapper type of boolean type is Boolean.


Question 2: 

(a) Evaluate the value of n if the value of p=5, q=19 [2]
int n = (q-p) > (p-q) ? (q-p) : (p-q);
Ans: n = 14

(b) Arrange the following primitive data types in an ascending order of their size: [2] 
(i) char (ii) byte (iii) double (iv) int
Ans: byte = 1 byte

char = 2 bytes 
int = 4 bytes 
double = 8 bytes 

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

(d) Name two types of constructor. [2] 
Ans: Default constructor and parameterized constructor.

(e) What are the values of a and b after the following function is executed, if the values passed are 30 and 50: [2] 
void paws(int a, int b)
{
    a = a + b;
    b = a - b;
    a = a - b;
    System.out.println(a + " , " + b);
}
Ans: 30, 50 


Question 3:
 
(a) State the data type and the value of y after the following is executed : [2] 
char x = '7'; 
y = Character.isLetter(x); 
Ans: Data type of y will be boolean and value will be false. 

(b) What is the function of catch block in exception handling? Where does it appear in a program? [2] 
Ans: catch block catches the specified exception type and handles the same. It appears between try and finally block.

(c) State the output of the following program segment is executed: [2]
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));
Ans: art
         true

(d) The access specifier that gives most accessibility is     and the least accessibility is _____. [2]
Ans: public, private

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

(f) (i)What will the code print? [2] 
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.
Ans: (i) (iv) garbage value 
(ii) this keyword

(g) State the package that contains the class : [2] 
(i) BufferedReader
(ii) Scanner
Ans: (i) java.io
        (ii) java.util

(h) Write the output of the following code segment: [2]
char ch;
int x = 97;
do{
   ch = (char) x;
   System.out.print(ch + " ");
   if (x % 10 == 0)
       break;
   ++x;

    } while (x <= 100);
Ans: a  b  c  d

(i) Write the java expression for[2]




Ans: - (double) (Math.pow(a, 2) + Math.pow(b, 2)) / (2 * a * b)

(j) If int y = 10 then find int z = (++y * (y++ + 5));  [2]
Ans: 176



SECTION – B (60 MARKS) 
Attempt any four questions

Question 4:

Define a class ParkingLot with the following description: [15] 
    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 

    Member methods: 
void input() – To input and store vno 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. 
Ans:
import java.util.*; 

class ParkingLot {

private int vno; private int hours; private double bill;

               public void input() {

Scanner sc = new Scanner(System.in); System.out.print("Enter vehicle number: "); vno = sc.nextInt();

System.out.print("Enter hours: "); hours = sc.nextInt();

}

 

public void calculate() {

bill = 3 + (hours - 1) * 1.50;

}

public void display() {
                    System.out.println("Vehicle number: " + vno); System.out.println("Hours: " + hours); System.out.println("Bill: Rs. " + bill);

}

public static void main() {

ParkingLot ob = new ParkingLot(); ob.input();

ob.calculate(); ob.display();

}

}


Question 5: 

Write two separate programs to generate the following patterns using iteration(loop) statements: [15] 
(a)
* # 
* # * 
* # * # 
* # * # *

(b) To display the following pattern: 
5 4 3 2 1
5 4 3 2
5 4 3
5 4
5
Ans: -
(a)
class Pattern1 {
    public static void main() {
        for (int i = 1; i <= 5; i++) {
            for (int j = 1; j <= i; j++) {
                if (j % n == 1)
                    System.out.print("* ");
                else
                    System.out.print("# ");
            }
            System.out.println();
         }
    }
}

(b)
class Pattern2 {
    public static void main()
    {
        int i, j;
        for(i=1; i<=5; i++)
        {
            for(j=5; j>=i; j--)
                System.out.print(j);
            System.out.println();
        }
    }
            

Question 6:

Write a program in to input and store all 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: [15]
Average marks = total marks / 3

Average Marks

Remarks

85 – 100

EXCELLENT

75 – 84

DISTINCTION

60 – 74

FIRST CLASS

40 – 59

PASS

LESS THAN 40

POOR

Ans:

import java.util.Scanner; public class Marks {

public static void main() {

                   Scanner sc = new Scanner(System.in); 
                   System.out.print("Enter number of students: ");
                   int n = sc.nextInt();
                   
                    int[] rollNumbers = new int[n]; 
                    String[] names = new String[n]; 
                    int[] subject1Marks = new int[n];
                    int[] subject2Marks = new int[n];
                    int[] subject3Marks = new int[n];

                    for (int i = 0; i < n; i++) {
                        System.out.println("Student " + (i + 1)); 
                        System.out.print("Enter roll number: ");    
                        rollNumbers[i] = sc.nextInt(); 
                        System.out.print("Enter name: "); 
                        names[i] = sc.nextLine();
                        System.out.print("Enter marks in subject 1: ");
                      subject1Marks[i] = sc.nextInt(); 
                      System.out.print("Enter marks in subject 2: "); 
                      subject2Marks[i] = sc.nextInt(); 
                      System.out.print("Enter marks in subject 3: "); 
                      subject3Marks[i] = sc.nextInt();

                    }
            for (int i = 0; i < n; i++) {
                System.out.println("Roll number = " + rollNumbers[i] + ", Name= " + names[i]);
                int averageMarks = (subject1Marks[i] + subject2Marks[i] + subject3Marks[i]) / 3;

if (averageMarks >= 85 && averageMarks <= 100) { System.out.println("EXCELLENT");

} else if (averageMarks >= 75 && averageMarks <= 84) { System.out.println("DISTINCTION");

} else if (averageMarks >= 60 && averageMarks <= 74) { System.out.println("FIRST CLASS");

} else if (averageMarks >= 40 && averageMarks <= 59) { System.out.println("PASS");

} else if (averageMarks < 40) {
                                    System.out.println("POOR"); 
                        }
                }
        }
}


Question 7:

Design a class to overload a function Joystring() as follows: [15] 
(i) void Joystring(String s, char ch1, char ch2) with one string 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 value of 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 value of s = "Cloud computing means Internet based computing"
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 value of s1 = "COMMON WEALTH" 
s2 = "GAMES"
Output: COMMON WEALTH GAMES
(use library functions)

Ans:
import java.util.Scanner; 

class StringOperations {

public void Joystring(String s, char ch1, char ch2) { String output = s.replace(ch1, ch2); System.out.println("Output = " + output);

}

public void Joystring(String s) {

int firstIndexOfSpace = s.indexOf(' '); int lastIndexOfSpace = s.lastIndexOf(' ');

System.out.println("First index of space = " + firstIndexOfSpace); System.out.println("Last index of space = " + lastIndexOfSpace);

}

public void Joystring(String s1, String s2) {

String output = s1.concat(" ").concat(s2); System.out.println("Output = " + output);

}

} 


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

Ans:
import java.util.Scanner;

public class SortNames {

public static void main() {

                        Scanner sc = new Scanner(System.in);
                        String[] names = new String[20];
                      System.out.println("Enter 20 names"); 
                            for (int i = 0; i < 20; i++) 
                                names[i] = sc.nextLine();
                            
                            for (int i = 0; i < names.length; i++) {
                                for (int j = 1; j < (names.length - i); j++) {
                                    if (names[j - 1].compareTo(names[j]) > 0) {
                                         String temp = names[j - 1]; 
                                         names[j - 1] = names[j];
                                         names[j] = temp;
                                    }
                                }
                                }

                                System.out.println("Sorted names: "); 
                             for (int i = 0; i < names.length; i++) 
                                    System.out.println(names[i]); 

}

}



Question 9:

Use switch statement, write a menu driven program to: [15]
(i) To find and display all the factors of a number input by the user (including 1 and excluding number itself.)
Example: 
Sample Input: n = 15
Sample 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: 
Sample Input: n = 5
Sample Output: 120

For an incorrect choice, an appropriate error message should be displayed.

Ans: - 
import java.util.*; 
public class Menu
    public static void main() 
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("1. Factors"); 
        System.out.println("2. Factorial"); 
        System.out.print("Enter your choice: ");

        int ch = sc.nextInt();

        switch(ch){
            case 1:
                System.out.print("Enter n: ");
                int n = sc.nextInt();

                for (int i = 1; i < n; i++) {
                if (n % i == 0) 
                    System.out.println(i);
                }
                break;

            case 2:
                 System.out.print("Enter n: ");
                 int n = sc.nextInt();
                int factorial = 1;
                for (int i = 1; i < n; i++)
                     factorial = factorial * i;
                   System.out.println("Factorial: " + factorial);
                    break;

            default:
                System.out.println("Invalid choice");
            }
        }
}

SHARE

Author

Hi, Its me Hafeez. A webdesigner, blogspot developer and UI/UX Designer. I am a certified Themeforest top Author and Front-End Developer. I'am business speaker, marketer, Blogger and Javascript Programmer.

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 Comments:

Post a Comment