ICSE Computer Solved -2014

ICSE Question Paper – 2014 (Solved)
Computer ApplicationsClass X
SECTION A (40 Marks)Answer all questions from this Section
Question 1.
(a) Which of the following are valid comments?  [2]
       (i)       /* comment */
       (ii)      /*comment
       (iii)     //comment
       (iv)     */ comment */
Ans. (i) /* comment */ and  (iii) //comment
(b) What is meant by a package? Name any two Java Application Programming Interface packages. [2]
Ans. A package is a namespace that organizes a set of related classes and interfaces. Conceptually you can think of packages as being similar to different folders on your computer.
Two Java Application Programming Interface packages are : java.io and java.util
(c) Name the primitive data type in Java that is:
       (i)         a 64-bit integer and is used when you need a range of values wider than those provided by int.
       (ii)        a single 16-bit Unicode character whose default value is ‘u0000’  [2]
Ans. (i) long
        (ii) char
(d) State one difference between floating point literals float and double.  [2]
Ans. float is a single-precision 32-bit floating point literal whereas, double is a double-precision 64-bit floating point literal.
Or,
float can handle about 7 decimal places whereas a double can handle about 16 decimal places.
(e) Find the errors in the given program segment and re-write the statements correctly to assign values to an integer array. [2]
       int a = new int( 5 );
       for( int i=0; i<=5; i++ )  a[i]=i;
Ans. Statement 1 has two errors: the [] is required as “int[] a” or “int a[]“. Also, the 5 should be inside [ ] bracket instead of ( ).
Statement 2 has one error. The condition check should not include the = sign, since the element index should go from 0 to 4 only.
Correct code:                        int a[ ] = new int[ 5 ];
                        for( int i=0; i < 5; i++ )  a[i] = i;
Question 2.
(a) Operators with higher precedence are evaluated before operators with relatively lower precedence. Arrange the operators given below in order of higher precedence to lower precedence. [2]
(i) &&             (ii) %          (iii) >=        (iv) ++
Ans. (iv) ++ , (ii) % , (iii) >= , (i) &&
(b) Identify the statements listed below as assignment, increment, method invocation or object creation statements. [2]
       (i)         System.out.println(“Java”);
       (ii)        costPrice = 457.50;
       (iii)       Car hybrid = new Car();
       (iv)       petrolPrice++;
Ans.     (i)        System.out.println(“Java”); ——- method invocation statement.
            (ii)        costPrice = 457.50; ——- assignment statement.
            (iii)       Car hybrid = new Car(); ——- objet creation statement
            (iv)       petrolPrice++;  ——- increment statement
(c) Give two differences between switch statement and if-else statement. [2]
Ans. (i) if-else can compare conditions for all primitive data types whereas, switch can only compare integers and characters.
(ii) all kinds of relations (= =, <= etc.) can be checked using if-else whereas only equality relation can be checked using switch.
Or,
(iii) In switch case, the control directly goes to the matching case without checking any other cases, whereas, in if-else, all the conditions are checked and then the control goes to the matching condition.
(d) What is an infinite loop? Write an infinite loop statement. [2]
Ans. An infinite loop is a loop which loops endlessly (i.e. executes forever) either due to the loop having no terminating condition or having a condition which is always satisfied.
Examples:
while( true )                                // terminating condition is always satisfied
{
System.out.println(“Infinite”);
}
Or
for( ;; )                                              // terminating condition is missing
{
System.out.println(“Infinite”);
}
(e) What is a constructor? When is it invoked? [2]
Ans. A constructor is a member function with the same name as that of a class and has no return type, not even void. It is invoked whenever an object is created using the new reserved word.
Question 3.
(a) List the variables from those given below that are composite data types. [2]
(i)   static int x;                                               (iv) boolean b;(ii)  arr[i]=10;                                                 (v)  private char chr;(iii) obj.display();                                           (vi) String str;
Ans. (ii) arr[], (iii) obj (vi) str
(b) State the output of the following program segment: [2]
       String str1 = “great”;  String str2 = “minds”;       System.out.println(strl.substring(0,2).concat(str2.substring(l)));       System.out.println((“WH” + (strl.substring(2).toUpperCase()))); 
Ans. strl.substring(0,2) gives “gr” and str2.substring(l) gives “inds”.
So, strl.substring(0,2).concat(str2.substring(l)) gives “grinds”
strl.substring(2).toUpperCase() gives “EAT”
So, “WH” + (strl.substring(2).toUpperCase()) gives “WHEAT”
Hence the output of the given program segment will be:
grinds
WHEAT
(c) What are the final values stored in variables x and y below? [2]
       double a = – 6.35;       double b = 14.74;       double x = Math.abs(Math.ceil(a));       double y = Math.rint(Math.max(a,b));
Ans. x = 6.0 and y = 15.0
[Working: Math.ceil(- 6.35) will give – 6.0 and Math.abs(- 6.0) will give 6.0
Math.max(- 6.35, 14.74 ) will give 14.74 and Math.rint(14.74) will give 15.0]
(d) Rewrite the following program segment using the if-else statements instead of the ternary operator. [2]
       String grade = (mark>=90) ? “A” : (mark>=80) ? “B” : “C”;
Ans. 
if( marks >= 90 ) {
grade = “A”;
} else if( marks >= 80 ) {
grade = “B”;
} else {
grade = “C”;
}
(e) Give output of the following method: [2]
       public static void main(String[] args) {       int a = 5;       a++;       System.out.println(a);       a – = (a – –) – (- – a);       System.out.println(a);  }  
Ans. 6
        4
(f) What is the data type returned by the library functions: [2]
       (i)    compareTo()       (ii)   equals()
Ans. (i) int
        (ii) boolean
(g) State the value of characteristic and mantissa when the following code is executed. [2]
       String s = “4.3756”;       int n = s.indexOf(‘.’);
       
int characteristic = Integer.parseInt(s.substring(0,n));
       
int mantissa = Integer.valueOf(s.substring(n+1));
Ans. value of characteristic = 4
        value of mantissa = 3756
(h) Study the method and answer the given questions. [2]
       public void sampleMethod()       {           for( int i=0; i<3; i++ )                               {           for( int j=0; j<2; j++)                                                 { int number = (int)(Math.random() * 10);                                                    System.out.println(number);     } } }
       (i)         How many times does the loop execute?       (ii)        What is the range of possible values stored in the variable number?
Ans. (i) The outer loop executes 3 times (for i = 0, 1, 2) and for every execution of the outer loop, the inner loop executes 2 times (for j = 0, 1). Hence, the total number of times the statements in the loop executes = 3 * 2 = 6
         (ii) The range of possible values stored in the variable number is from 0 – 9
[Note: Math.random() generates random decimal point numbers between 0 and 1 like 0.4, 0.1, 0.9 etc. Math.random() * 10 gives you these decimal numbers multiplied with 10, so, you get decimal point numbers between 0 and 10 (10 is exclusive). So, the (int)(Math.random() * 10) will give you random integer numbers from 0-9.]
(i) Consider the following class: [2]
       public class myClass   {       public static int x = 3, y = 4;       public int a = 2, b = 3;  }
       (i)         Name the variables for which each object of the class will have its own distinct copy.       (ii)        Name the variables that are common to all objects of the class.
Ans. (i)         ‘a’ and ‘b’ since these are non-static (instance variables)
        (ii)        ‘x’ and ‘y’ since these are static variables.
(j) What will be the output when the following code segments are executed? [2]
(i)    String s = “1001”;
       int x = Integer.valueOf(s);
       double y = Double.valueOf(s);
       System.out.println(“x=” +x);
       System.out.println(“y=” +y);
(ii)        System.out.println(“The King said “Begin at the beginning!” to me.”);
Ans. (i) x=1001
             y=1001.0
        (ii) The King said “Begin at the beginning!” to me. [ Note: ” is an escape character and prints ” ]

Question 4.
Define a class named movieMagic with the following description:
Instance variables/data members:
int year            –           to store the year of release of a movie
String title       –           to store the title of the movie.
float rating      –           to store the popularity rating of the movie.
(minimum rating = 0.0 and maximum rating = 5.0)
Member Methods:
(i)         movieMagic()              Default constructor to initialize numeric data members to 0 and String data member to “”.
(ii)        void accept()               To input and store year, title and rating.
(iii)       void display()              To display the title of a movie and a message based on the rating as per the table below.
RatingMessage to be displayed
0.0 to 2.0Flop
2.1 to 3.4Semi-hit
3.5 to 4.5Hit
4.6 to 5.0Super Hit

Write a main method to create an object of the class and call the above member methods.
import java.util.*;
class movieMagic 
    {
     int year; //initialising the variables here
     String title;
     double rating;

movieMagic() //default constructor as per question
    {
     year = 0;
     rating = 0.0; 
     title = "";
    }

void accept() //to input 
    {
    Scanner in = new Scanner (System.in);
     System.out.print("Enter the title of the movie : ");
     title = in.nextLine();
     System.out.print("Enter the year of its release : ");
     year = in.nextInt();
     System.out.print("Enter the movie rating : ");
     rating = in.nextDouble();
    }

void display()//displaying the results
    {
     System.out.println("The title of the movie is : "+title);
     if( rating >= 0.0 && rating <= 2.0 )
     
      System.out.println("The movie was a Flop");
       if( rating >= 2.1 && rating <= 3.4 ) 
      System.out.println("The movie was a Semi-hit");
       if( rating >= 3.5 && rating <= 4.5 ) 
      System.out.println("The movie was a Hit");
       if( rating >= 4.6 && rating <= 5.0 )  
      System.out.println("The movie was a Super Hit");
       if(rating>5)
      System.out.println("Enter a valid movie rating in between 0.0 and 5.0");
   
    }
  
     public static void main(String args[]) 
    {
     movieMagic ob = new movieMagic(); // creating object of the class movieMagic
     ob.accept();
     ob.display();
    }
    }
Question 5.
A special two-digit number is such that when the sum of its digits is added to the product of its digits, the result is equal to the original two-digit number.
Example:         Consider the number 59.
Sum of digits = 5 + 9 = 14
Product of its digits = 5 x 9 = 45
Sum of the sum of digits and product of digits= 14 + 45 = 59
Write a program to accept a two-digit number. Add the sum of its digits to the product of its digits. If the value is equal to the number input, output the message “Special 2-digit number” otherwise, output the message “Not a Special 2-digit number”.
Click the link for the result 
Question 6.
Write a program to assign a full path and file name as given below. Using library functions, extract and output the file path, file name and file extension separately as shown.
Input               C:UsersadminPicturesflower.jpg
Output             Path:    C:UsersadminPictures
File name:        flower
Extension:       jpg

 import java.util.*;
          public class FileName 
    public static void main(String[] args)
 {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter file name and path: ");
       String input = in.nextLine();
        int LastBack = input.lastIndexOf('\\');
        int Dot = input.lastIndexOf('.');
        String outputPath = input.substring(0, LastBack + 1);
        String fileName = input.substring(LastBack + 1,Dot);
        String extension = input.substring(Dot + 1);
        System.out.println("Path: " + outputPath);
        System.out.println("File Name: " + fileName);
      System.out.println("Extension: " + extension);
    }

}
Question -7

(i)
 class overload
double area(double a, double,b,double,c)
{
    s= (a+b+c)/2;
    area=Math.sqrt(s(s-a)*(s-b)*)(s-c))
}

(ii)
class overload

     double area(inta ,int b,int hieght)
    {
        area=1/2*hieght*(a+b);
    }
  (iii)
  class overload
   double area(double diagonal1,double diagonal2)
   {
       area=1/2*(diagonal1*diagonal2)
    }
Question-8
Marks [15]
Using the switch statement, write a menu driven program to calculate the maturity amount of a Bank Deposit.
The user is given the following options:
  1. Term Deposit
  2. Recurring Deposit
For option (i) accept principal(P), rate of interest(r) and time period in years(n). Calculateand output the maturity amount(A) receivable using the formula
A =��maturity amount
For option (ii) accept Monthly Installment (P), rate ofinterest(r) and time period in months(n). Calculate and output the maturity amount(A) receivable using the formula
A =�maturity amount
For an incorrect option, an appropriate error message should be displayed.
Ans.

Comments

Popular posts from this blog

Practice questions for English grammar

Physics 2017 Solved Paper Physics

Computer applications icse board exam paper solved 2017