0% found this document useful (0 votes)
13 views20 pages

Computer 2023

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)
13 views20 pages

Computer 2023

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/ 20

COMPUTER APPLICATIONS

SECTION A (40 Marks)


(Attempt all questions from this Section.)

Question 1
Choose the correct answers to the questions from the given options. [20]
(Do not copy the questions, write the correct answers only.)
(i) A mechanism where one class acquires the properties of another class:
(a) Polymorphism
(b) Inheritance
(c) Encapsulation
(d) Abstraction
(ii) Identify the type of operator &&:

(a) ternary
(b) unary
(c) logical
(d) relational
(iii) The Scanner class method used to accept words with space:
(a) next()
(b) nextLine()
(c) Next()
(d) nextString()
(iv) The keyword used to call package in the program:
(a) extends
(b) export
(c) import
(d) package
(v) What value will Math.sqrt (Math.ceil (15.3)) return?
(a) 16.0

1
(b) 16
(c) 4.0
(d) 5.0
(vi) The absence of which statement leads to fall through situation in switch case
statement?
(a) continue
(b) break
(c) return
(d) System.exit(0)
(vii) State the type of loop in the given program segment:
for (int i = 5; i ! = 0; i - = 2)
System.out.println(i);
(a) finite
(b) infinite
(c) null
(d) fixed
(viii) Write a method prototype name check() which takes an integer argument and
returns a char:
(a) char check()
(b) void check (int x)
(c) check (int x)
(d) char check (int x)
(ix) The number of values that a method can return is:
(a) 1
(b) 2
(c) 3
(d) 4
(x) Predict the output of the following code snippet: String P = "20", Q ="22";
int a = Integer.parseInt(P);
int b = Integer.valueOf(Q);
System.out.println(a+""+b);
(a) 20

2
(b) 20 22
(c) 2220
(d) 22
(xi) The String class method to join two strings is:
(a) concat(String)
(b) <string>.joint(string)
(c) concat(char)
(d) Concat()
(xii) The output of the function "COMPOSITION".substring(3, 6):
(a) POSI
(b) POS
(c) MPO
(d) MPOS
(xiii) int x = (int) 32.8; is an example of __________ typecasting.
(a) implicit
(b) automatic
(c) explicit
(d) coercion
(xiv) The code obtained after compilation is known as:
(a) source code
(b) object code
(c) machine code
(d) java byte code
(xv) Missing a semicolon in a statement is what type of error?
(a) Logical
(b) Syntax
(c) Runtime
(d) No error
(xvi) Consider the following program segment and select the output of the same
when n = 10 :
switch(n)
{case 10 : System.out.println(n*2);

3
case 4 : System.out.println(n*4); break;
default : System.out.println(n);
}
(a) 20
40
(b) 10
4
(c) 20, 40
(d) 10
10
(xvii) A method which does not modify the value of variables is termed as:
(a) Impure method
(b) Pure method
(c) Primitive method
(d) User defined method
(xviii) When an object of a Wrapper class is converted to its corresponding primitive
data type, it is called as ___________.
(a) Boxing
(b) Explicit type conversion
(c) Unboxing
(d) Implicit type conversion
(xix) The number of bits occupied by the value ‘a’ are:
(a) 1 bit
(b) 2 bits
(c) 4 bits
(d) 16 bits
(xx) Method which is a part of a class rather than an instance of the class is termed
as:
(a) Static method
(b) Non static method
(c) Wrapper class
(d) String method

4
(xvi) Few candidates chose the incorrect
option (c) instead of the correct one
(a) Suggestions for teachers
(xvii) Instead of the correct option (b), − Teach the difference between syntax error,
many candidates chose the runtime error and logical error with proper
incorrect option (a) or (d). examples in the computer lab.
(xviii) Most of the candidates chose either − Explain to the students in detail, the
the option (b) or (d) instead of the meaning of auto boxing and unboxing with
correct option (c). suitable programs in the computer lab.
(xix) Many candidates chose the − Ensure that the students understand the
incorrect option (a) or option (b). difference between implicit and explicit
(xx) Most of the candidates chose the conversion.
correct option (a). However, some − Teach the students the number of bits /
candidates chose the incorrect bytes occupied by each primitive data
options (b) or option (d). type.
− Make the use of static variables and
instance variables to explain this concept
properly.

MARKING SCHEME
Question 1
(i) (b) Inheritance

(ii) (c) logical

(iii) (b) nextLine()

(iv) (c) import

(v) (c) 4.0

(vi) (b) break

(vii) (b) infinite

(viii) (d) char check (int x)

(ix) (a) 1

(x) (b) 20 22

(xi) (a) concat(String)

(xii) (b) POS

(xiii) (c) explicit

6
(xiv) (d) java byte code

(xv) (b) Syntax

(xvi) 20
(a)
40

(xvii) (b) pure method

(xviii) (c) unboxing

(xix) (d) 16 bits

(xx) (a) static method

Question 2
(i) Write the Java expression for (𝑎𝑎 + 𝑏𝑏)𝑥𝑥 . [2]
(ii) Evaluate the expression when the value of x = 4: [2]
x * = - - x + x++ + x
(iii) Convert the following do…while loop to for loop: [2]
int x=10;
do
{x– –;
System.out.print(x);
}while (x>=1);
(iv) Give the output of the following Character class methods: [2]
(a) Character.toUpperCase ('a')
(b) Character.isLetterOrDigit('#')
(v) Rewrite the following code using the if-else statement: [2]
int m= 400;
double ch = (m>300) ? (m / 10.0) * 2: (m / 20.0) - 2;
(vi) Give the output of the following program segment: [2]
int n = 4279; int d;
while(n>0)
{d=n%10;
System.out.println(d);

7
n=n/100;
}
(vii) Give the output of the following String class methods: [2]
(a) "COMMENCEMENT" . lastIndexOf('M')
(b) "devote" . compareTo("DEVOTE")
(viii) Consider the given array and answer the questions given below: [2]
int x[ ]={4,7,9,66,72,0,16};
(a) What is the length of the array?
(b) What is the value in x[4]?
(ix) Name the following: [2]
(a) What is an instance of the class called?
(b) The method which has same name as that of the class name.
(x) Write the value of n after execution: [2]
char ch ='d';
int n = ch + 5;

Comments of Examiners
(i) Many candidates did not use any Suggestions for teachers
mathematical method. A few − Explain each mathematical method with
candidates used Math.sqrt instead of the number of arguments required.
Math.pow (a + b, x) − Explain how to apply BODMAS rule for
(ii) Most of the candidates did not use
evaluating expressions.
the BODMAS rule properly. Many
− Lay stress on each operator precedence
candidates did not take the initial
and operator associativity in detail.
value of x for calculation.
− Teach in detail, the syntax of each loop
(iii) Many candidates did not:
with suitable programs in the computer
- Write for loop.
lab.
- Initialize the value of x with 10.
− Explain each character class method in
- Write the iteration statement.
detail with suitable programs in the
(iv) (a) Few candidates wrote ‘a’
computer lab.
(b) Few candidates wrote ‘true’
− Teach the students how to convert
(v) The common errors made by most of
ternary operator into if .. else statement
the candidates were:
- Not having written int m = 400. using suitable programs in the computer
- Not defining variable ch. lab.
- Copying the statement as it is − Give adequate practice to the students on
without using if statement. digit extraction while updating ‘n’ with
- Not writing the else statement. various powers of 10 as students are
mostly familiar with updating ‘n’ by
division by 10.

8
(vi) Many candidates overlooked the
updating of ‘n’ by 100 and were
unable to do the correct digit Suggestions for teachers
extraction. Some candidates did − Tell the students that index number starts
outputs on the same line. from 0.
(vii) Many candidates considered first − Ensure that the students understand the
index number as 1 and gave 9 as the difference between equals() and
answer. compareTo() method.
(viii) (a) A few candidates calculated sum − Teach the students how to find the length
of all the elements. of an array and how to access each
(b) Some candidates considered the element by its index number.
first index number as 1 and wrote 66 − Ensure that the students are clear about
as the answer. the concept that index number in Arrays
(ix) (a) Most of the candidates gave starts from 0.
‘method’ as the answer. − The concept of object-oriented
(b) Majority of the answer scripts programming needs to be discussed in
had static method as the answer. detail.
(x) Most of the candidates were unable − The concept of constructor, its use and
to recollect the corresponding its application should be taught
Unicode value of the character. thoroughly with suitable programs in the
Some candidates gave the answer in computer lab.
char datatype. − Adequate practice should be given to the
students in questions where characters
corresponding Unicode is required.
− Emphasis should be laid on the concept
of implicit type conversion.

MARKING SCHEME
Question 2
(i) Math.pow (a + b, x)

(ii) x = 40
x= x*(--x + x++ +x)
x=4* (3+3+4)
(iii) for(int x = 10; x > = 1; x --)
{System.out.print(x);}
]
(iv) (a) A
(b) false
(v) int m = 400; double ch;
if (m > 300)
ch = (m / 10.0) * 2;

9
else
ch = (m / 20.0) * 2;
(vi) 9
2
(vii) (a) 8
(b) 32
(viii) (a) 7
(b) 72
(ix) (a) object
(b) constructor
(x) n = 105

SECTION B (60 Marks)


(Answer any four questions from this Section.)

Question 3
Design a class with the following specifications: [15]
Class name: Student
Member variables: name – name of student
age – age of student
mks –marks obtained
stream – stream allocated
(Declare the variables using appropriate data types)
Member methods:
void accept() – Accept name, age and marks using methods of Scanner class.
void allocation() – Allocate the stream as per following criteria:
mks stream
> = 300 Science and Computer
> = 200 and < 300 Commerce and Computer
> = 75 and 200 Arts and Animation
< 75 Try Again
void print() – Display student name, age, mks and stream allocated.
Call all the above methods in main method using an object.

10
Comments of Examiners
The common errors made by most of the Suggestions for teachers
candidates were: − Lay stress on writing the same class
- Did not write the same class name as name as it is given in the question.
mentioned in the question. − Explain to the students to declare
member variables with the appropriate
- Did not declare the member variables or data type.
declaring it inside the accept () method. − Explain the importance of writing the
- Not having written the same member same method names as given in the
question.
method names as mentioned in the
− Solve programs in the computer lab to
question.
show how various operators are used in
- Not having written the syntax of the program.
relational operators properly. − Explain the occurrence of syntax errors
/ compilation errors in case of writing
- Not having created an object of the class wrong syntax for the operators.
and not calling member methods. − Solve programs in the computer lab to
- Missing double quotation marks in explain an object of the class with
string message. proper syntax is created and how to call
the member methods using object name.
− Lay emphasis on the concept that
double quotation is must for messages.

MARKING SCHEME
Question 3
import java.util.*;

class Student

String name;int age; int mks; String stream;

void accept()

Scanner sc=new Scanner(System.in);

System.out.println("enter name, age ,mon_no,mks");

name=sc.next();

age=sc.nextInt();

mks=sc.nextInt();

11
void allocation ()

if(mks>=300)

stream="science and computer “;

else if(mks>=200&&mks<300)

stream="commerce and computer";

else if(mks>=75&&mks<200)

stream="arts";

else

stream="Try again";

void print()

System.out.println(name+" "+age+" "+mks+" "+stream);

public static void main(String args[])

Student ob=new Student();

ob.accept();

ob.allocation();

ob.print();

(Variable description not required , if the same variables are used )

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

Comments of Examiners
Majority of the candidates declared the Suggestions for teachers
integer array instead of character array. − Teach the students to check the data type
Several candidates did not take the character given in the question and declare the array
input properly. They wrote next( ) or accordingly.
nextLine( ) − Explain how to take array input
Some candidates did not write the swapping depending on the data type.
statements properly. − Solve adequate number of programs in
A few candidates missed out writing the computer lab to explain the students
statements to print the sorted array. how to take integer input, decimal input,
character input and string input using
scanner class in an array.
− Lay emphasis on the order in which
swapping statements are written along
with the importance of each statement
and the effect of each statement with
regards to the position of element in an
array.
− Explain to students that without printing
the sorted array, it is possible to know
whether the array is sorted properly or
not.
− Ensure that students write statements to
print the sorted array.

MARKING SCHEME
Question 4
import java.util.*;
class Bubble{
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
System.out.println("enter characters");
char a[ ]=new char[10];
for(int i=0;i<a.length;i++)
{

13
a[i]=sc.next().charAt(0);
}
System.out.println("original array");
for(int i=0;i<a.length;i++)
System.out.println(a[i]);

for(int j=0;j<a.length;j++)
{
for(int i=0 ; i<a.length-1;i++) or for(int i=0 ; i<a.length-1-j;i++)
{
if((int)a[i]>(int)a[i+1])
{
char temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}}}
System.out.println("sorted array");
for(int i=0;i<a.length;i++)
System.out.println(a[i]);
} } (Variable description )

Question 5
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.

14
Comments of Examiners
Most of the candidates did not use the Suggestions for teachers
method overloading concept in the
− Explain the concept of method
program. Many candidates did not use the
overloading by solving suitable
same method name as given in the question.
Some candidates did not use the nested programs.
loop concept to print the given pattern. A − Ensure that the students understand the
few candidates were unable to extract the importance and use of method
digits properly. overloading in a program.
− Emphasize on giving the same method
name as given in the question and also
giving the same method name in the
program.
− Solve number of programs in the
computer lab to explain to the students
how to print the given pattern using
nested loop.
− Explain that only writing printing
statements without using nested loop is
not acceptable.
− Solve number of programs in the
computer lab to explain to the students
how to extract each digit of the number
using while loop with proper syntax.
− Ensure that students know how to write
proper condition, use remainder
operator to extract a digit and use
division operator to reduce the number.

MARKING SCHEME
Question 5
class overload
{
public static void print( )
{
for(int i=1;i<=5;i++)
{
for(int j=1;j<=4;j++)
{
System.out.print(i);
}
System.out.println();

15
} }

public static void print(int n)


{
int s1=0; int s2=0;
while(n>0)
{
int rem=n%10;
if(rem%2==0)
s1+=rem;
else
s2+=rem;
n/=10;
}
if(s1==s2)
System.out.println("Lead number");
else
System.out.println("not Lead number");
}
public static void main(String args[])
{
print( );
print(3669);
}
} (Variable description )

Question 6
Define a class to accept a String and print the number of digits, alphabets and special [15]
characters in the string.
Example: S = “KAPILDEV@83”
Output: Number of digits – 2
Number of Alphabets – 8
Number of Special characters – 1

16
Comments of Examiners
The common errors made by many Suggestions for teachers
candidates were:
− Solve number of programs in the
- Not having extracted characters in the
computer lab to explain to students the
program.
- Not having used the concept of use, syntax and importance of each string
Character class methods properly method.
- Not having used if condition properly − Solve number of programs in the
to check the range of characters and computer lab to explain the students how
digits to use each character class method in a
- Having used the alternate logic and string program.
made errors such as: − Explain the method of checking for range
• Printing inside the loop of digits and characters in a string
For example: if(ch>=48 && program.
ch<=57) − Ensure that the students understand that
d=d+1;
printing must be done outside the loop,
• System.out.println(“Number of
digits=”+d); otherwise the printing will be done as
many times the loop will execute.

MARKING SCHEME
Question 6
import java.util.*;
class check_string{
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
System.out.println("enter string");
String s=sc.next();
int c=0,d=0,sp=0;
for(int i=0;i<s.length();i++)
{ char ch=s.charAt(i);
if(Character.isLetter(ch))
c++;
else if(Character.isDigit(ch))
d++;
else if(!(Character.isLetterOrDigit(ch)))
sp++;
}
System.out.println("number of digits "+d);
System.out.println("number of Alphabets "+c);

17
System.out.println("number of special characters "+sp);
}}
(Variable description )
Alternate logic:
1)if(ch>='0' && ch<='9')
c++;
else if((ch>= 'A' && ch<='Z') || (ch>='a' && ch<='z') )
d++;
else
sp++;
2) char ch=s.charAt(i);
if(ch>=48 && ch<=57)
c++;
else if((ch>= 65 && ch<=90) || (ch>=97 && ch<=122) )
d++;
else
sp++;

Question 7
Define a class to accept values into an array of double data type of size 20. Accept a [15]
double value from user and search in the array using linear search method. If value is
found display message “Found” with its position where it is present in the array.
Otherwise display message “not found”.

18
Comments of Examiners
The common errors made by most candidates Suggestions for teachers
were:
− Emphasize the importance of checking
- Used int data type instead of double data
the data type given in the question and
type
- Took size as 10 instead of 20. declaring the array accordingly.
- Not taking an input of the number to be − Tell the students the importance of
searched. reading the question properly and
- Not using the break keyword when the declaring the array with the size as
flag variable is used in the loop. given in the question.
- Ignoring the output message “not found” − Solve programs in the computer lab to
explain to the students the importance
Some candidates made an error in the use of of taking input of the number to be
System.exit(0). A few candidates did Binary searched in an array.
search instead of Linear search. − Explain to the students that without
input of number, searching is not
possible in an array.
− Importance of indicator in linear search
must be explained.
− Distinction between linear search and
binary search must be explained.
− Train students with the correct
algorithm of linear search method
− Teach the concept of System.exit(0).

MARKING SCHEME
Question 7
import java.util.*;
class Linear{
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
System.out.println("enter numbers");
double a[ ]=new double[20];
for(int i=0;i<a.length;i++)
{
a[i]=sc.nextDouble();
}
System.out.println("enter search element");
double search=sc.nextDouble();
for(int i=0;i<a.length;i++)
{
if(a[i]==search)
{

19
System.out.println("element found"+(i + 1)); OR (i)
System.exit(0);
}
}
System.out.println("not found");
}}
(Variable description )

Consider Alternate logic :


boolean flag =false;----->1
for(int i=0;i<a.length;i++) //
{
if(a[i]==search)//
{
flag =true;
System.out.println("element found"+(i + 1)); //
break;
}
}
if(flag== false)
System.out.println("not found"); //

Question 8
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

20
Comments of Examiners
Majority of the candidates lost marks in the Suggestions for teachers
identification of 2-digit number. Many − Teach the concept of checking the 2-digit
candidates were able to do the single digit number.
number checking properly but assumed that − Explain the logical operator concept.
the remaining numbers were 2-digit − Ensure that the students understand the
number. Some candidates made an error in
difference between the value display
the use of logical operator. Instead of &&
inside the loop and outside the loop.
operator candidates used || operator. A few
candidates displayed the value inside the
loop.

MARKING SCHEME
Question 8
import java.util.*;
class Que8
{
public static void main (String args[ ])
{
Scanner sc=new Scanner(System.in);
int a[ ]= new int[10]; [ Array size -10]
int s1=0; int s2=0;int i;
System.out.println("enter elements");
for(i=0;i<a.length;i++)
a[i]=sc.nextInt();
for(i=0;i<a.length;i++)
{
if(a[i]>0&&a[i]<=9)
s1+=a[i];
else if(a[i]>=10&&a[i]<=99)
s2+=a[i];
}
System.out.println("sum of single digit nos"+s1);
System.out.println("sum of double digit no"+s2);
}}

(Variable description )

Alternate logic to be accepted

21

You might also like