[go: up one dir, main page]

0% found this document useful (0 votes)
207 views10 pages

X Practice Paper

The document provides instructions for a computer application class exam. It is divided into two sections - Section A and Section B. Section A contains 20 multiple choice questions that must be attempted. Section B contains 4 questions where students must write Java programs to answer the questions. The document provides details on the expected length, content, and marks for each question. It also notes the exam is 7 pages long and reading time is 15 minutes while writing time is 2 hours.

Uploaded by

hargunnkaur31802
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
207 views10 pages

X Practice Paper

The document provides instructions for a computer application class exam. It is divided into two sections - Section A and Section B. Section A contains 20 multiple choice questions that must be attempted. Section B contains 4 questions where students must write Java programs to answer the questions. The document provides details on the expected length, content, and marks for each question. It also notes the exam is 7 pages long and reading time is 15 minutes while writing time is 2 hours.

Uploaded by

hargunnkaur31802
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

CLASS: X COMPUTER APPLICATION

Time: Reading time 15 minutes & Writing time 2 hours Marks: 100
Attempt all questions.
This paper is divided into two sections.
Attempt all questions from Section A and any four questions from Section B.
The intended marks for questions are given in brackets [ ].
This Paper consists of 7 pages.
ANSWER KEY
SECTION A
[Attempt all questions from this section]

Question 1 [20]
Choose the correct answers to the questions from the given options and write answers only.

i) Name the feature of Java depicted in the above picture:


a. Encapsulation
b. Inheritance
c. Polymorphism
d. Abstraction

ii) What is the purpose of the below function :


Double.toString()
a. Converts a string type to a double
b. Converts a string type to a double wrapper object
c. Converts a double data type to a string
d. Converts any object to a double

iii) Java uses the term _____ to describe a collection of related classes:
a. library
b. package
c. folder
d. inheritance

iv) Which among the following is NOT a visibility mode used in the class?
a. private
b. protected
c. public
d. static

v) Which among the following is correct usage?


a. int array[-25]
b. float array[25]
c. float array[-25]
d. None of these

vi) Element arr[10] is which element of the array?


a. 10
b. 11
c. 9
d. 8

vii) The value returned by Integer.parseInt(“-321”) is :-


a. -321
b. 321.0
c. 321
d. “321”

viii) A constructor is used when an object is :-


a. destroyed
b. assigned a value
c. abstracted
d. created

ix) A member variable declared with no access specifier has visibility only in the :-
a. class and subclass only
b. class and package only
c. class, package and subclass only
d. class only

x) The access specifier that gives most accessibility is___and the least accessibility is__: -
a. public and protected
b. default and private
c. public and private
d. private and protected

xi) The output of Math.sqrt(x); when x=9.0 is:


a. 3
b. 3.0
c. 3.00
d. 81.0

xii) If String str1=”great”; and String str2=”minds”; then what will be the output of
System.out.println(str1.substring(0,2).concat(str2.substring(1)));
a. gri
b. griminds
c. grem
d. grinds

xiii) which among the following is a valid statement to declare a double 2D array named arr of 3 rows
and 4 columns?
a. Double arr[] []= new double[3][4];
b. Double arr[] []= new arr[3][4];
c. Double arr[] []= new Double arr [3][4];
d. double arr[] []= new double[3][4];

xiv) If int n []={1,2,3,5,7,9,13,16}; what will be the value of x when x=Math.sqrt(n[5]+n[7]); ?


a. 16
b. 25
c. 5
d. 4

xv) The return type of equals() method is ?


a. int
b. char
c. boolean
d. void

xvi) Which of the following is an invalid integer?


a. 2222
b. 22222
c. 222
d. 222 22

xvii) The corresponding wrapper class of boolean data type is?


a. BOOLEAN
b. Boolean
c. boolean
d. BooLean

xviii) Read the following text and choose correct answer:

In Java there is a member method of a class with no return type not even void is used to initialise the
instance variables. This member method can be default, parameterised or non-parameterised. Execution
of this method is must when the object of a class is created.

Which among the following method/s is described above?


a. User Defined methods
b. Wrapper classes methods
c. A protected method
d. Constructor

xix) Assertion(A): Object-oriented programming promotes the concept of data encapsulation.


Reason(R): Data encapsulation in OOP ensures that data is kept private and can only be
accessed through predefined methods.

a. Both Assertion (A) and Reason(R) are true and reason(R) is a correct explanation of
Assertion(A).
b. Both Assertion (A) and Reason(R) are true but reason(R) is not a correct explanation of Assertion(A).
c. Both Assertion (A) is true and Reason(R) is false.
d. Both Assertion (A) is false and Reason(R) is true.

xx) Assertion(A): Object-oriented programming emphasizes the concepts of inheritance and


polymorphism.
Reason(R): Inheritance allows one class to inherit properties and behaviours from another,
while polymorphism enables objects of different classes to be treated as objects of
a common superclass.

a. Both Assertion (A) and Reason(R) are true and reason(R) is a correct explanation of
Assertion(A).
b. Both Assertion (A) and Reason(R) are true but reason(R) is not a correct explanation of Assertion(A).
c. Both Assertion (A) is true and Reason(R) is false.
d. Both Assertion (A) is false and Reason(R) is true.

Question 2

(i) Write Java expression for √ 3 x+ √ x 2 ÷ a+ b [2]


answer-Math.sqrt*(3*x+Math.sqrt(x,2))/(a+b);
(ii) If x=5; find the value of y=x+ (++x * x++);
[2]
Answer- 5+(6*6)= 5+36=41
_
(iii) How many times will the following loop execute? What value will be returned? [2]
int x=5; int y=50;
while(x<=y)
{
y=y/x;
System.out.println(y);
} Answer- 10 2 loop will execute 2 times.

(iv) Rohan has written the following program but there is an error while he tries to execute the code.
[2]
Name the error. How the program can be modified to get the correct answer?
class Example {
public static void main(String args[]) {
int a = 40, b = 60;
int Sum = a + b;
System.out.println( "Sum of variables is + sum); } } Sum and inverted comma missing compile
time error or syntax error

(v) The following program should print the largest of given three numbers. [2]
However, the code has errors. Fix the code so that it compiles and runs correctly.
int a = 2, b = 8, c = 6;
if (a > b | | a > c) // &&
System.out.println( a + " is the largest Number");
else if (b > a && b > c)
System.out.println(b + " is the smallest Number"); largest
else
System.out.println( c + " is the largest Number");

(vi) Predict the output of the program: [2]


String A=”26”, B=”100”;
String D=A+B+”200”;
int x = Integer.parseInt(A);
int y = Integer.parseInt(B); int d= x + y;
System.out.println(“Result 1 = “ + D); 26100200
System.out.println(“Result 2 = “ + d); 126

(vii) If int x[]={4,3,7,8,9,10}; what are the values of p and q? [2]


i) p=x.length
ii) q=x[2]+x[5]*x[1] Answer- 6, 7+10*3= 37
(viii) If String s=”Today is Test”;
What do the following functions return ?
i) System.out.println(s.indexOf(‘T’));
ii) System.out.println(s.substring(0,7)+ “ “ +”Holiday”);
Answer- 0 Today i Holiday

(ix) Write two point difference between static and non-static variables. [2]
Answer- Static variables are preceded by static keyword while non static variables are not.
They are called class variables and non static are called instance variables.
(x) Briefly define two ways of invoking functions. . [2]
Answer- 1) call by value- passing parameters to a method by value. 2) reference of actual parameter is
passed to the formal parameters.

SECTION B
(Answer any four questions from this section)
The answer in this section should consist of the programs in either BlueJ environment or
any program environment with Java as the base.
Each program should be written using variable description/ mnemonic codes so that the logic
of the program is clearly depicted.
Flow charts and algorithms are not required.

Question 3 [15]
Define a class called movieMagic with the following description:
Instance variable/Data member :
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=5.0)
Member Methods :
Void accept() – To input and store year, title and rating
void display() – To display the title of a movie and a message based on the rating as per the table given
below:-

Rating Message to be displayed


0.0 to 2.0 Flop
2.1 to 3.4 Semi-hit
3.4 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.
Answer;-
import java.util.Scanner;

public class movieMagic


{
private int year;
private String title;
private float rating;
public movieMagic() {
year = 0;
title = "";
rating = 0.0f;
}

public void accept() {


Scanner in = new Scanner(System.in);
System.out.print("Enter Title of Movie: ");
title = in.nextLine();
System.out.print("Enter Year of Movie: ");
year = in.nextInt();
System.out.print("Enter Rating of Movie: ");
rating = in.nextFloat();
}

public void display() {


String message = "Invalid Rating";
if (rating <= 2.0f)
message = "Flop";
else if (rating <= 3.4f)
message = "Semi-Hit";
else if (rating <= 4.4f)
message = "Hit";
else if (rating <= 5.0f)
message = "Super-Hit";

System.out.println(title);
System.out.println(message);
}

public static void main(String args[]) {


movieMagic obj = new movieMagic();
obj.accept();
obj.display();
}
}

Question 4 [15]
Write a program to accept a word and convert it into lowercase if it is in uppercase, and display the new
word by replacing only the vowels with the character following it.
Sample I/P- computer
O/P- cpmpvtfr
Answer-
import java.util.Scanner;
public class VowelReplace
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter a word: ");
String str = in.nextLine();
str = str.toLowerCase();
String newStr = "";
int len = str.length();

for (int i = 0; i < len; i++) {


char ch = str.charAt(i);

if (str.charAt(i) == 'a' || str.charAt(i) == 'e' || str.charAt(i) == 'i' || str.charAt(i) == 'o' ||


str.charAt(i) == 'u') {
char nextChar = (char)(ch + 1);
newStr = newStr + nextChar; } else {
newStr = newStr + ch;}} System.out.println(newStr); }}

Question 5 [15]
Write a program to fill 10 variables in a 1D array named list. Perform bubble sort and display the original
as well as sorted array in ascending order.
Sample Input- 65,47,40,9,37,72,45,17
Sample Output- 9,17,37,40,45,47,65,72
Answer:-
for(int i=0;i<len-1;i++)
{
for(int j=0;j<len-i-1;j++)
{ if(list[j] >list [j+1])
Int temp= list[j];
list[j]= list[j+1];
list[j+1]=temp; }}
Question 6 [15]
Design a class to overload a function as follows:
i) void compare(int ,int )- To compare two integer values and print the greater of the two integers.
ii) void compare( char,char)- To compare the numeric value of two characters with higher numeric
value.
iii) Void compare(String,String)- To compare the length of the two strings and print the longer of the
two.
Answer:-
public void compare(int a, int b) {

if (a > b) {
System.out.println(a);}

else {
System.out.println(b); }

public void compare(char a, char b) {


int x = (int)a;
int y = (int)b;

if (x > y) {
System.out.println(a); }

else {
System.out.println(b); }}

public void compare(String a, String b) {


int l1 = a.length();
int l2 = b.length();

if (l1 > l2) {


System.out.println(a); }

else {
System.out.println(b);}
Question 7 [15]
Write a program to accept a number and check and display whether it is a perfect number or not. A
Number is said to be perfect if sum of all it’s factors(excluding the number itself) are equal to the
number.
Example- 496 Sum of Digits- 1+2+4+8+16+31+62+124+248 = 496
Answer-
import java.util.Scanner;
public class PerfectNumberExample1 {
public static void main(String args[]) {
long n, sum=0;
Scanner sc=new Scanner(System.in);
System.out.print("Enter the number: ");
n=sc.nextLong(); int i=1;
//executes until the condition becomes false
while(i <= n/2)
{ if(n % i == 0)
{
//calculates the sum of factors
Sum = sum + i; } //end of if
//after each iteration, increments the value of variable i by 1
i++; } //end of while
//compares sum with the number
if(sum==n) { //prints if sum and n are equal
System.out.println(n+" is a perfect number."); } //end of if else
//prints if sum and n are not equal
System.out.println(n+" is not a perfect number."); } }

Question 8 [15]
Write a program to perform binary search on a list of integers given below, to search for an element input
by the user. If it is found display the element along with its position, otherwise display the message
“Search element not found”.
5,7,9,11,15,20,30,45,89,97

You might also like