Questions – Exam Papers – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  


Shop
siteicon
Exam Paper: ICSE2014 (JAVA) siteicon No. of Q.26
SECTION A (40 marks)
Attempt all questions

Which of the following are valid comments?
(i) /* comment */
(ii) /*comment
(iii) //comment
(iv) */ comment */




What is meant by a package? Name any two Java Application Programming Interface packages.




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′




State one difference between floating point literals float and double.




Find the errors in the given program segment and re-write the statements correctly to assign values to an integer array.

int a = new int( 5 );
for( int i=0; i<=5; i++ ) a[i]=i;



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.

(i) &&
(ii) %
(iii) >=
(iv) ++




Identify the statements listed below as assignment, increment, method invocation or object creation statements.

(i) System.out.println(“Java”);
(ii) costPrice = 457.50;
(iii) Car hybrid = new Car();
(iv) petrolPrice++;




Give two differences between switch statement and if-else statement.




What is an infinite loop? Write an infinite loop statement.




What is a constructor? When is it invoked?




List the variables from those given below that are composite data types.
(i) static int x;
(ii) arr[i] = 10;
(iii) obj.display();
(iv) boolean b;
(v) private char chr;
(vi) String str;




State the output of the following program segment:

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())));



What are the final values stored in variables x and y below?

double a = - 6.35;
double b = 14.74;
double x = Math.abs(Math.ceil(a));
double y = Math.rint(Math.max(a,b));



Rewrite the following program segment using the if-else statements instead of the ternary operator.

String grade = (mark >= 90) ? "A" : (mark >= 80) ? "B" : "C";



Give output of the following method:

public static void main(String[] args) {
  int a = 5;
  a++;
  System.out.println(a);
  a -= (a--) - (--a);
  System.out.println(a); }



What is the data type returned by the library functions:
(i) compareTo()
(ii) equals()




State the value of characteristic and mantissa when the following code is executed.

String s = "4.3756";
int n = s.indexOf('.');
int characteristic = Integer.parseInt(s.substring(0,n));
int mantissa = Integer.valueOf(s.substring(n+1));



Study the method and answer the given questions.

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?




Consider the following class:

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.




What will be the output when the following code segments are executed?
(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.”);



SECTION B (60 marks)
Attempt any four questions from this Section

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.

RATING MESSAGE TO BE DISPLAYED
0.0 to 2.0 Flop
2.1 to 3.4 Semi-hit
3.5 to 4.5 Hit
4.6 to 5.0 Super Hit

Write a main method to create an object of the class and call the above member methods.




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 twodigit 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”.




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:\Users\admin\Pictures\flower.jpg
Output Path: C:\Users\admin\Pictures\
File name: flower
Extension: jpg




Design a class to overload a function area() as follows:
(i) double area(double a. double b, double e) with three double arguments, returns the
area of a scalene triangle using the formula:

where

(ii) double area(int a, int b, int height) with three integer arguments, returns the area of a trapezium using the formula:

(iii) double area(double diagonal1, double diagonal2) with two double arguments, returns
the area of a rhombus using the formula:




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:
(i) Term Deposit
(ii) Recurring Deposit
For option (i) accept principal(P), rare of ¡interest(r) and time period in years(n). Calculate and output the maturity amount(A) receivable
using the formula

For option (ii) accept Monthly Installment (P), rate of interest(r) and time period in months (n). Calculate and output the maturity amount(A) receivable using the formula

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