Trending ▼   ResFinder  

ICSE 2014 solved : Computer Applications

16 pages, 4 questions, 0 questions with responses, 0 total responses,    0    0
Manasa Preethi
Sikkim manipal university, Bangalore
Master of Science Information Technology
+Fave Message
 Home > manumansi >

Formatting page ...

ICSE 2014 This is the ICSE 14th March 2014 Paper, and will be completed shortly. It is Work In Progress (WIP). Q1. (a) Which of the following are valid comments? (i) (ii) (iii) (iv) */ comment */ /* comment /* // */ comment comment [2 marks] A1. (a) (i) and (iii) are valid comments. The style of (i) is used for multi-line comments as well. The style of (iii) is used for single line comments only. In (ii), the ending */ is missing. In (iv) the start needs to be /* and not */ Q1. (b) What is meant by a package? Name any two Java Application Programming Interface packages. [2 marks] A1. (b) A package is a name given to a collection of classes. It is a mechanism for organizing classes and preventing name conflicts between classes. Java packages are stored as compressed JAR files; this also allows for faster downloading of class files as a group. Examples of Java API packages are: java.lang, java.util, java.io, etc. Q1. (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 marks] A1. (c) (i) long (ii) char Q1. (d) State one difference between the floating point literals float and double. [2 marks] A1. (d) The float data type is 4 bytes (32 bits) in size, and the double data type is 8 bytes (64 bits) in size. A more detailed answer, though not required, is: Q1. (e) Find the errors in the given program segment and rewrite the statements correctly to assign values to an integer array. [2 marks] int a = new int(5); for(int i=0;i<=5;i++) a[i]=i; A1. (e) int[] a = new int[5]; for(int i=0;i<5;i++) a[i]=i; Statement 1 has two errors: the [] is required as int[] a or int a[] . Also, the new int[5] uses square brackets. Statement 2 has one error. The condition check should not include the = sign, since the element index should go from 0 to 4 only. Q2. (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. (i) && (ii) % (iii) >= (iv) ++ [2 marks] A2. (a) ++, %, >=, && Q2. (b) Identify the statements listed below as assignment, increment, method invocation or object creation statements. (i) (ii) (iii) (iv) [2 marks] A2. (i) (ii) (iii) (iv) Increment Car costPrice hybrid = = System.out.println( Java ); 457.50; new Car(); petrolPrice++; (b) invocation Assignment creation Method Object Q2. (c) Give two differences between the switch statement and the if-else statement. [2 marks] A2. (c) The differences are: SWITCH IF .. ELSE Conditions must evaluate to a boolean Conditions are checked as case statements (int, char, etc.) value only. If no break statement is used, subsequent condition blocks may also One condition block gets executed at a get executed. This is the fall-through behaviour of switch case maximum. statements. Syntactically, the default clause is used for the final catch-all The else clause (without if) if used for condition, if needed. the final catch-all condition, if needed. Q2. (d) What is an infinite loop? Write an infinite loop statement. [2 marks] A2. (d) An infinite loop is a loop that executes forever, and has no reachable exit condition. It iterates through the loop body repeatedly. Inside the loop body, normally, an exit condition is present. Example 1: while(true) // infinite loop { System.out.println("Printing forever!"); } Example 2: for(;;) { System.out.println("Printing forever!"); } Q2. (e) What is a constructor? When is it invoked? [2 marks] A2. (e) A constructor is the code that is executed when an object of a class is being created. It is normally used to initialize the state of the instance variables of the object being created. A constructor is written like a method with no return value, and has the same name as the name of the class. A constructor is invoked whenever an object is created using the new reserved word. Example: Car c = new Car("Indica"); class Car { String model; // instance variable Car(String model) // constructor { this.model = model; } } Q3. (a) 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; [2 marks] A3. (a) Anything that is not a primitive data type is a composite data type. Hence the variables arr, obj, and str are composite data types. Note: Remember, String and arrays of primitives are also composite, since arrays are objects. Q3. (b) 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()))); [2 marks] A3. (b) (i) grinds (ii) WHEAT Q3. (c) 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)); [2 marks] A3. (c) The variable x will contain 6.0. This is because ceiling makes -6.35 as -6.0. Then, abs() converts this into +6.0. The variable y will contain 15.0. This is because the maximum of a and b is 14.74. And then rint() converts this into 15.0. Q3. (d) Rewrite the following program segment using if-else statements instead of the ternary operator. String grade=(mark>=90)?"A":(mark>=80)?"B":"C"; [2 marks] A3. (d) if(mark >= 90) grade = "A"; else if(mark >= 80) grade = "B"; else grade = "C"; Q3. (e) Give the 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); } [2 marks] A3. (e) 6 4 Explanation: The first output is simple, since a has got incremented earlier from 5 to 6. The second output needs some explanation. Remember that a-=something is the same as a=a-something. What this means is that the existing value of a, before the statement starts, which is 6 will be used. But, it will come into play after the RHS has completely been evaluated. The RHS is (a ) ( a) = (6 ) ( a) = 6 ( a) [but a is now 5, due to a ] = 6 ( 5) = 6 4 = 2. To this, we apply a-=2 = a = a-2 (using the ORIGINAL value of a, which is 6) = 6 2 = 4. Q3. (f) What is the data type returned by the library functions? (i) compareTo() (ii) equals() [2 marks] A3. (f) (i) int (ii) boolean Q3. (g) 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)); [2 marks] A3. (g) The value of characteristic is 4. The value of mantissa is 3756. Q3. (h) 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? [2 marks] A3. (h) (i) The inner loop executes 6 times. (ii) The range of possible values stored in the variable number is integers from 0 till 9, both included. Q3. (i) 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. [2 marks] A3. (i) (i) a, b (ii) x, y Q3. (j) What is 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."); [2 marks] A3. (j) (i) x=1001 y=1001.0 (ii) The king said "Begin at the beginning!" to me. Q4. 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 members to . (ii) void accept() To input and store year, title and rating (iii) void display() To display the title of the 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 methods. [15 marks] A4. import java.util.*; class movieMagic { // Instance variables int year; String title; float rating; // Constructor public movieMagic() { this.year = 0; this.title = ""; this.rating = 0.0F; } // Other member methods public void accept() { Scanner sc = new Scanner(System.in); System.out.print("Enter the year of the movie : "); this.year = Integer.parseInt(sc.nextLine()); System.out.print("Enter the title of the movie : "); this.title = sc.nextLine(); System.out.print("Enter the rating of the movie: "); this.rating = Float.parseFloat(sc.nextLine()); // check and ensure minimum value is 0.0 if(this.rating < 0.0F) { this.rating = 0.0F; } // check and ensure maximum value is 5.0 if(this.rating > 5.0F) { this.rating = 5.0F; } } // display public void display() { String message = ""; if(rating <= 2.0F) message = "Flop"; else if(rating <= 3.4F) message = "Semi-hit"; else if(rating <= 4.5F) message = "Hit"; else message = "Super Hit"; System.out.println(this.title + " [" + this.year + "] is a " + message); } public static void main(String[] args) { movieMagic movie = new movieMagic(); movie.accept(); movie.display(); } } Output:

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

 

  Print intermediate debugging step

Show debugging info


 

 

© 2010 - 2025 ResPaper. Terms of ServiceContact Us Advertise with us

 

manumansi chat