0% found this document useful (0 votes)
39 views22 pages

MS MockTest Group1 Gr10

Uploaded by

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

MS MockTest Group1 Gr10

Uploaded by

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

Mock Test

2023-24

Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins

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 or parts of questions are given in brackets[].
The time given at the head of this Paper is the time allowed for writing the answers
____________________________________________________________________________________
SECTION A (40 Marks)
Attempt all questions

Question 1(i)
What will be the output of the following code?
int size = 2;
if (size < 0)
System.out.println("Small");
else if (size == 0)
System.out.println("Medium");
else
System.out.println("Large");

a) Small
b) Large
c) Medium
d) Runtime error

Answer
Large
Reason — Since size > 0, hence the conditions of if and else if are false. Thus, the
else block will be executed and "Large" will be printed on the screen.

Question 1(ii)
Which of the following statements involves a fall through?

a) if-else
b) for loop
c) if-else-if
d) switch

Answer
switch
Mock Test
2023-24

Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins

Reason — Omitting break statement leads to program execution continuing into the
next case and onwards till a break statement is encountered or end of switch is
reached.

Question 1(iii)
Which of the following statement is true for logical errors?

a) The compiler does not detect these errors.


b) There is no indication of error when the program is executed.
c) The program may produce correct results for some input data and wrong
results for other input data.
d) All of the above

Answer
All of the above
Reason — The compiler does not detect logical errors and there is no indication of
error when the program is executed. The program may produce correct results for
some input data and wrong results for other input data.

Question 1(iv)
Object oriented programming mainly uses

a) top down approach


b) top down and bottom up approach
c) bottom up approach
d) None of the above

Answer
bottom up approach
Reason — Object Oriented Programming follows bottom-up approach because in
OOP we first identify the smallest parts of the program i.e. the objects. We then
combine these objects to develop the complete program.

Question 1(v)
Mock Test
2023-24

Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins

In which technique are the values of actual parameters copied to the formal
parameters?

a) Call by reference
b) Call by value
c) Call by argument
d) Call by method

Answer
Call by value
Reason — In call by value, the actual parameters are copied to formal parameters.
Any changes to formal parameters are not reflected onto the actual parameters.

Question 1(vi)
Which package would you import for the Scanner class?

a) java.util.*;
b) java.awt.*;
c) java.io.*;
d) java.lang.*;

Answer
java.util.*;
Reason — Scanner class is a part of java.util package.

Question 1(vii)
Give the output of Math.abs(x); when x = -9.99.

a) -9.99
b) 9.99
c) 0.99
d) None of these

Answer
9.99
Mock Test
2023-24

Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins

Reason — Math.abs() returns the absolute value of its argument. Its return type is
same as the type of its argument. Thus, Math.abs(-9.99) returns 9.99.

Question 1(viii)
A/An ............... is an abstract description of a set of objects.

a) abstraction
b) encapsulation
c) polymorphism
d) class

Answer
class
Reason — A class is an abstract description of a set of objects.

Question 1(ix)
This variable can be accessed by calling with the class name.

a) Instance
b) Local
c) Class
d) None of these

Answer
Class
Reason — Class variable can be accessed by calling with the class name.

Question 1(x)
The main objective of passing arguments to functions is

a) message passing
b) parameter passing
c) variable passing
d) argument passing
Mock Test
2023-24

Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins

Answer
message passing
Reason — The main objective of passing arguments to functions is message
passing.

Question 1(xi)
If int arr [] = {3, 5, 7, 9}; what is the value of arr.length?

a) 3
b) 5
c) 4
d) Cannot be determined

Answer
4
Reason — length property stores the number of elements in an array. Thus, the
value of arr.length is 4 as there are 4 elements in the array.

Question 1(xii)
A binary search

a) can be used with sorted arrays only.


b) can be used with unsorted arrays only.
c) can be used with both sorted and unsorted arrays.
d) cannot be used with arrays.

Answer
can be used with sorted arrays only.
Reason — A binary search can be used with sorted arrays only.

Question 1(xiii)
Corresponding wrapper class of float data type is

a) FLOAT
Mock Test
2023-24

Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins

b) float
c) Float
d) Floating

Answer
Float
Reason — Corresponding wrapper class of float data type is Float.

Question 1(xiv)
What will be the output of the following code?
System.out.println("Lucknow".substring (0, 4));

a) Lucknow
b) Luckn
c) Luck
d) luck

Answer
Luck
Reason — The substring() method returns a substring beginning from the
startindex and extending to the character at index endIndex - 1. Since a string index
begins at 0, the character at startindex (0) is 'L' and the character at the endIndex
(4-1 = 3) is 'k'. Thus, "Luck" is extracted and printed on the screen.

Question 1(xv)
This access specifier is the most open access level.

a) Public
b) Protected
c) Private
d) Default

Answer
Public
Mock Test
2023-24

Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins

Reason — A data member or member method declared as public is accessible


inside as well as outside of the class in which it is declared.

Question 1(xvi)
The method to determine whether the specified char value is in uppercase or not.

a) toUpperCase(char)
b) toLowerCase(char)
c) isLowerCase(char)
d) isUpperCase(char)

Answer
isUpperCase(char)
Reason — isUpperCase() is used to check if the character given as its argument is
in upper case or not. It returns true if the argument is in uppercase, else returns
false.

Question 1(xvii)
Assertion (A) Method should be called explicitly either with object reference or
class reference.
Reason (R) Method can be any user defined name.

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 and Reason (R) is not a correct
explanation of Assertion (A).
c) Assertion (A) is true and Reason (R) is false.
d) Assertion (A) is false and Reason (R) is true.

Answer
Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct
explanation of Assertion (A).
Reason — Assertion (A) is true as a method should be called explicitly either with
object reference or class reference. Reason (R) is also true as a method can be
any user defined name, except a keyword. Reason (R) is not the correct
explanation of Assertion (A).
Mock Test
2023-24

Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins

Question 1(xviii)
Read the following text and choose the correct answer:
Public access specifier allows a class to expose its member variables and member
functions to other functions and objects. Any public member can be accessed from
outside the class.
Which of these access specifier must be used for class so that it can be inherited
by another subclass?

a) public
b) private
c) protected
d) none of the mentioned

Answer
public
Reason — According to the given context, public access specifier can be used for
class so that it can be inherited by another subclass.

Question 1(xix)
Assertion (A) The return statement causes program control to transfer back to the
caller of the method.
Reason (R) The return statement immediately terminates the method in which it is
executed.

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 and Reason (R) is not a correct
explanation of Assertion (A).
c) Assertion (A) is true and Reason (R) is false.
d) Assertion (A) is false and Reason (R) is true

Answer
Both Assertion (A) and Reason (R) are true and Reason (R) is a correct
explanation of Assertion (A).
Mock Test
2023-24

Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins

Reason — Assertion (A) is true as the return statement causes program control to
transfer back to the caller of the method. Reason (R) is also true as the return
statement immediately terminates the method in which it is executed and the
control transfers back to the caller method. Thus, Reason (R) correctly explains
Assertion (A).

Question 1(xx)
Correct statement to declare an integer array of 10 elements.

a) int[ ] arr = new int[10];


b) int arr;
c) int arr (10);
d) int ( ) arr = new int (10);

Answer
int[ ] arr = new int[10];
Reason — The correct syntax to declare an array is as follows:
datatype[ ] array_name = new datatype[size];
The statement int[ ] arr = new int[10]; follows the correct syntax of array declaration.

Question 2(i)
Write the values of c and d after execution of following code.
Mock Test
2023-24

Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins

int a = 1;
int b = 2;
int c;
int d;
c = ++b;
d = a++;
c++;
Answer
After the execution of the code, c = 4 and d = 1.
Explanation

Statement Remarks

c = ++b; Prefix operator first increments and then uses the value. Thus, c = 3, b = 3

d = a++; Postfix operator first uses and then increments the value. Thus, d = 1, a = 2

c=c+1
c++; =3+1
=4

Question 2(ii)
Observe the following code and write how many times will the loop execute?
a = 5;
b = 2;
while(b != 0)
{
r = a % b;
a = b;
b = r;
}
System.out.println(" " + a);
Answer
The loop will execute 2 times.
Explanation
Mock Test
2023-24

Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins

Iteration r a b Remark

5 2 Initial values

1 1 2 1 r=5%2=1

r=2%1=0
2 0 1 0
Loop terminates as b = 0

Question 2(iii)
Write the values that will be assigned to x, y and t after executing the following code.
String s1, s2, x, y;
int t;
s1 = "classxii";
s2 = "cbseboard";
x = s1.substring(5, 8);
y = s2.concat(s1);
t = y.length();
System.out.println("x=" + x);
System.out.println("y=" + y);
System.out.println("t=" + t);
Answer
Output
x=xii
y=cbseboardclassxii
t=17
Explanation
The substring() method returns a substring beginning from the startindex and extending to the character at
index endIndex - 1. Here, startindex is 5 and end index is 7 (8 - 1). Since the string starts from index 0, the
extracted substring is "xii". Thus x = xii.
The concat() method adds one string (s1) at the end of another string (s2). Thus, "classxii" is added to the end
of "cbseboard". Hence, y = "cbseboardclassxii.
The length() method returns the total number of characters in a string. Thus, t = 17.
Question 2(iv)
Write the values that will be stored in variables num and sum after execution of the following code.
int sum = 0, num = -2;
Mock Test
2023-24

Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins

do
{
sum = sum + num;
num++;
} while (num < 1);
Answer
After the execution of the given code, num = 1 and sum = -3
Explanation

Iteration sum num Remarks

0 -2 Initial values

1 -2 -1 sum = 0 + (-2) = -2

2 -3 0 sum = -2 + (-1) = -3

sum = -3 + 0 = -3
3 -3 1
Loop terminates

Question 2(v)
The following code has some error(s). Rewrite the correct code and underlining all the corrections made.
integer counter = 0;
i = 10; num;
for (num = i; num >= 1; num--);
{
If i % num = 0
{
counter = counter + 1;
}
}
Answer
The correct code is as follows:
int counter = 0; //Correction 1
int i = 10, num; //Correction 2
for (num = i; num >= 1; num--) //Correction 3
Mock Test
2023-24

Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins

{
if( i % num == 0) //Correction 4
{
counter = counter + 1;
}
}
Explanation

Correction Statement Error

Correction integer counter


The datatype should be int
1 = 0;

variable declaration cannot be done without a data type. The syntax for
Correction
i = 10; num; variable declaration is datatype variablename = value/expression;.
2
Multiple variables should be separated by comma not semicolon.

for (num = i; If a semicolon is written at the end of the for loop, the block of the loop
Correction
num >= 1; num- will not be executed. Thus, no semicolon should be written after for
3
-); loop.

If should be written in lower case and the condition should be written


Correction
If i % num = 0 within brackets. Equality operator (==) should be used instead of
4
assignment operator (=).

Question 2(vi)
Rewrite the following program segment using while instead of for loop.
int f = 1, i;
for(i = 1; i <= 5 ; i++)
{
f *= i;
System.out.println(f);
}
Answer
int f = 1; i = 1;
while(i <= 5) {
f *= i;
System.out.println(f);
Mock Test
2023-24

Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins

i++;
}
Question 2(vii)
State the method that
(a) converts a string to a primitive float data type.
(b) determines if the specified character is an uppercase character.
Answer
(a) Float.parseFloat()
(b) Character.isUpperCase()
Question 2(viii)
Write the Java statement for the following mathematical expression:
a=0.02−3y3x+ya=x+y0.02−3y3
Answer
a = (0.02 - 3 * Math.pow(y, 3)) / (x + y);
Question 2(ix)
Give the output of the following expression, when a = 6.
a += ++a + a++ + a-- + a-- + --a + ++a
Answer
The output will be 46.
Explanation
a += ++a + a++ + a-- + a-- + --a + ++a [a = 6]
a = a + (++a + a++ + a-- + a-- + --a + ++a) [a = 6]
a = 6 + (7 + a++ + a-- + a-- + --a + ++a) [a = 7]
a = 6 + (7 + 7 + a-- + a-- + --a + ++a) [a = 8]
a = 6 + (7 + 7 + 8 + a-- + --a + ++a) [a = 7]
a = 6 + (7 + 7 + 8 + 7 + --a + ++a) [a = 6]
a = 6 + (7 + 7 + 8 + 7 + 5 + ++a) [a = 5]
a = 6 + (7 + 7 + 8 + 7 + 5 + 6) [a = 6]
a = 6 + 40
a = 46
Question 2(x)
Predict the output of the following.
(a) Math.pow(2.5, 2) + Math.ceil(5)
(b) Math.round(2.9) + Math.log(1)
Answer
Mock Test
2023-24

Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins

(a) 11.25
(b) 3.0
Explanation
(a) Math.pow(x, y) method returns the value of x raised to the power of y. Math.ceil() method returns the
smallest double value that is greater than or equal to the argument and is equal to a mathematical integer.
Thus, the given expression is evaluated as follows:
Math.pow(2.5, 2) + Math.ceil(5)
⇒ 6.25 + 5.0
⇒ 11.25
(b) Math.round() method rounds off its argument to the nearest mathematical integer and returns its value as an
int or long type. Math.log() method returns the natural logarithm of its argument. Thus, the given expression is
evaluated as follows:
Math.round(2.9) + Math.log(1)
⇒ 3 + 0.0
⇒ 3.0

SECTION B (60 Marks)


Attempt any four questions from this Section.
The answers in this Section should consist of the Programs in either Blue J environment or any
program environment with Java as the base.
Each program should be written using Variable descriptions/Mnemonic Codes
so that the logic of the program is clearly depicted.
Flow-Charts and Algorithms are not required.

Question 3 [15]

Design a class name ShowRoom with the following description:

Instance variables / Data members:


String name — To store the name of the customer
long mobno — To store the mobile number of the customer
double cost — To store the cost of the items purchased
double dis — To store the discount amount
double amount — To store the amount to be paid after discount

Member methods:
ShowRoom() — default constructor to initialize data members
Mock Test
2023-24

Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins

void input() — To input customer name, mobile number, cost


void calculate() — To calculate discount on the cost of purchased items, based on following criteria

Cost Discount (in percentage)

Less than or equal to ₹10000 5%

More than ₹10000 and less than or equal to ₹20000 10%

More than ₹20000 and less than or equal to ₹35000 15%

More than ₹35000 20%

void display() — To display customer name, mobile number, amount to be paid after discount.

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

Answer

import java.util.Scanner;

public class ShowRoom


{
private String name;
private long mobno;
private double cost;
private double dis;
private double amount;

public ShowRoom()
{
name = "";
mobno = 0;
cost = 0.0;
dis = 0.0;
amount = 0.0;
}

public void input() {


Scanner in = new Scanner(System.in);
System.out.print("Enter customer name: ");
name = in.nextLine();
System.out.print("Enter customer mobile no: ");
mobno = in.nextLong();
System.out.print("Enter cost: ");
cost = in.nextDouble();
}
Mock Test
2023-24

Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins

public void calculate() {


int disPercent = 0;
if (cost <= 10000)
disPercent = 5;
else if (cost <= 20000)
disPercent = 10;
else if (cost <= 35000)
disPercent = 15;
else
disPercent = 20;

dis = cost * disPercent / 100.0;


amount = cost - dis;
}

public void display() {


System.out.println("Customer Name: " + name);
System.out.println("Mobile Number: " + mobno);
System.out.println("Amout after discount: " + amount);
}

public static void main(String args[]) {


ShowRoom obj = new ShowRoom();
obj.input();
obj.calculate();
obj.display();
}
}

Question 4 [15]

Define a class to accept a String and print the number of digits, alphabets and special characters in the string.

Example:
S = "KAPILDEV@83"
Output:
Number of digits – 2
Number of Alphabets – 8
Number of Special characters – 1

import java.util.Scanner;

public class Count


{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
Mock Test
2023-24

Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins

System.out.println("Enter a string:");
String str = in.nextLine();

int len = str.length();

int ac = 0;
int sc = 0;
int dc = 0;
char ch;

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


ch = str.charAt(i);
if (Character.isLetter(ch))
ac++;
else if (Character.isDigit(ch))
dc++;
else if (!Character.isWhitespace(ch))
sc++;
}

System.out.println("No. of Digits = " + dc);


System.out.println("No. of Alphabets = " + ac);
System.out.println("No. of Special Characters = " + sc);

}
}

Question 5 [15]

Define a class to accept 10 characters from a user. Using bubble sort technique arrange them in ascending
order. Display the sorted array and original array.

import java.util.Scanner;

public class CharBubbleSort


{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
char ch[] = new char[10];
System.out.println("Enter 10 characters:");
for (int i = 0; i < ch.length; i++) {
ch[i] = in.nextLine().charAt(0);
}

System.out.println("Original Array");
for (int i = 0; i < ch.length; i++) {
Mock Test
2023-24

Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins

System.out.print(ch[i] + " ");


}

//Bubble Sort
for (int i = 0; i < ch.length - 1; i++) {
for (int j = 0; j < ch.length - 1 - i; j++) {
if (ch[j] > (ch[j + 1])) {
char t = ch[j];
ch[j] = ch[j + 1];
ch[j + 1] = t;
}
}
}

System.out.println("\nSorted Array");
for (int i = 0; i < ch.length; i++) {
System.out.print(ch[i] + " ");
}
}
}

Question 6 [15]

Define a class to overload the function print as follows:

void print() - to print the following format

1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
5 5 5 5
void print(int n) - To check whether the number is a lead number. A lead number is the one whose sum of even
digits are equal to sum of odd digits.

e.g. 3669
odd digits sum = 3 + 9 = 12
even digits sum = 6 + 6 = 12
3669 is a lead number.

import java.util.Scanner;

public class MethodOverload


{
public void print()
{
for(int i = 1; i <= 5; i++)
{
Mock Test
2023-24

Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins

for(int j = 1; j <= 4; j++)


{
System.out.print(i + " ");
}
System.out.println();
}
}

public void print(int n)


{
int d = 0;
int evenSum = 0;
int oddSum = 0;
while( n != 0)
{
d = n % 10;
if (d % 2 == 0)
evenSum += d;
else
oddSum += d;
n = n / 10;
}

if(evenSum == oddSum)
System.out.println("Lead number");
else
System.out.println("Not a lead number");
}

public static void main(String args[])


{
MethodOverload obj = new MethodOverload();
Scanner in = new Scanner(System.in);

System.out.println("Pattern: ");
obj.print();

System.out.print("Enter a number: ");


int num = in.nextInt();
obj.print(num);
}
}

Question 7 [15]

A tech number has even number of digits. If the number is split in two equal halves, then the square of sum of
these halves is equal to the number itself. Write a program to generate and print all four digits tech numbers.
Mock Test
2023-24

Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins

Example:

Consider the number 3025

Square of sum of the halves of 3025 = (30 + 25) 2


= (55)2
= 3025 is a tech number.

Answer

public class TechNumbers


{
public static void main(String args[]) {
for (int i = 1000; i <= 9999; i++) {
int secondHalf = i % 100;
int firstHalf = i / 100;
int sum = firstHalf + secondHalf;
if (i == sum * sum)
System.out.println(i);
}
}
}

Question 8 [15]

Define a class to accept values in integer array of size 10. Find sum of one digit number and sum of two digit
numbers entered. Display them separately.

Example:
Input: a[ ] = {2, 12, 4, 9, 18, 25, 3, 32, 20, 1}
Output:
Sum of one digit numbers : 2 + 4 + 9 + 3 + 1 = 19
Sum of two digit numbers : 12 + 18 + 25 + 32 + 20 = 107

import java.util.Scanner;

public class DigitSum


{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int oneSum = 0, twoSum = 0, d = 0;
int arr[] = new int[10];
System.out.println("Enter 10 numbers");
int l = arr.length;

for (int i = 0; i < l; i++)


{
Mock Test
2023-24

Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins

arr[i] = in.nextInt();
}

for (int i = 0; i < l; i++)


{
if(arr[i] >= 0 && arr[i] < 10 )
oneSum += arr[i];
else if(arr[i] >= 10 && arr[i] < 100 )
twoSum += arr[i];
}

System.out.println("Sum of 1 digit numbers = "+ oneSum);


System.out.println("Sum of 2 digit numbers = "+ twoSum);

}
}

Note: Pattern for the documentation comment and variable description table as given below
is to be followed for questions 3 to 8: -
Sample: Documentation comment
/**
*A program to input a set of 20 letters
*Convert each letter into upper case
*and find and display the number of vowels and number of consonants present in the set of given letters
* @author (ABC)
* @version (Java_BlueJ)
*/

Sample: Variable description table

Variable Description Table


S.No Variable Data Purpose Scope of variable
Name Type
1 pan double To store the value of pan number input by the Instance variable
user (Global)
2 c int Loop counter variable Local variable

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy