0% found this document useful (0 votes)
2 views

Computer 2019

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Computer 2019

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

QUALITATIVE ANALYSIS

SECTION A (40 Marks)


Attempt all questions

Question 1
(a) Name any two basic principles of Object-oriented Programming. [2]

(b) Write a difference between unary and binary operator. [2]

(c) Name the keyword which: [2]


(i) indicates that a method has no return type.
(ii) makes the variable as a class variable.
(d) Write the memory capacity (storage size) of short and float data type in bytes. [2]
(e) Identify and name the following tokens: [2]
(i) public
(ii) 'a'
(iii) ==
(iv) {}

10
MARKING SCHEME
Question 1
(a) Encapsulation, Data Abstraction, Polymorphism, Inheritance. (Any two)

(b) Unary operator Binary operator


It works /Performs on single It works/performs on two
operand or variables. variables or operands.
OR OR
Holds only one operand Holds more than one operand

(c) (i) void


(ii) static

(d) short – 2 bytes


float – 4 bytes
(e) (i) Keyword
(ii) character literal /constants
(iii) operator
(iv) separator/punctuator

Question 2
(a) Differentiate between if else if and switch-case statements. [2]
(b) Give the output of the following code: [2]
String P = "20", Q ="19";
int a = Integer.parseInt(P);
int b = Integer.valueOf(Q);
System.out.println(a+""+b);
(c) What are the various types of errors in Java? [2]
(d) State the data type and value of res after the following is executed: [2]
char ch = '9';
res= Character.isDigit(ch);
(e) What is the difference between the linear search and the binary search technique? [2]

12
Comments of Examiners
(a) Many candidates got confused between bidirectional Suggestions for teachers
and multiple branching statements. Some candidates - Follow the steps while introducing
gave appropriate examples but could not explain in any new construct such as: need of
detail. construct in the program, its basic
(b) Some candidates syntax, working, example.

(i) added and showed the result as 39 - Train students to compare between if
else if and switch-case statements
(ii) wrote 20 & 19 in two different lines. with examples.
(iii) used '- ' in between 20 and 19 - Explain wrapper classes and its
function parse and value of with
(iv) wrote 19 20 various examples to know the
(v) wrote 20 19 within double quotes. working.
(c) Some candidates, instead of writing the name of - Clarify to the students the concept of
different errors i.e syntax, logical and runtime error various types of concatenation in the
mentioned the examples of syntax errors only. print statement with the help of
examples and hands on sessions in
(d) Many candidates were not clear about the difference the laboratory.
between the data type and wrapper classes. Some - Show the working of program and
candidates wrote the data type and result in Uppercase output on the computer and explain
[ Boolean / True]. A few candidates wrote data type as how errors occurs, how they are
primitive with the value as 9. displayed and how to eliminate them
and, the difference between various
(e) Most of the candidates wrote the correct answer.
types of errors.
However, some candidates wrote two full programs
instead of the difference between the linear search and - Instruct the students not to use
the binary search technique. Some candidates wrote uppercase letters when datatype is
the difference between bubble sort and selection sort. asked.
- Explain Library class Character and
its various functions with the help of
examples and show their working on
the computer for the students to
understand output.
- Clarify to the students the difference
between the two methods of
searching with working or examples.

13
MARKING SCHEME
Question 2
(a) if else if switch case
Range of values are checked Only one value is compared
Supports both primitive and composite Supports only integer (byte, short,
data types int, long), char and String

Relational/Logical expressions can be


Only equality can be checked
checked
(Any two valid differences)
(b) 2019

(c) Syntax error


Logical error
Runtime error
(d) (i) boolean
(ii) true
(e)
Linear search Binary search
1. Array need not be sorted Array must be sorted in
ascending/descending order

2. check each item Does not check each item


3. Checks the search value Checks the search value with
with values in the array middle value of the array
from 0th index
4. It checks in a sequential It checks by diving the array
order into two halves

Question 3
(a) Write a Java expression for the following: [2]
2
| x +2xy |
(b) Write the return data type of the following functions: [2]

(i) startsWith( )
(ii) random( )

14
(c) If the value of basic=1500, what will be the value of tax after the following statement [2]
is executed?
tax = basic>1200 ? 200 :100;

(d) Give the output of following code and mention how many times the loop will execute? [2]

int i;
for( i=5 ; i>=1 ;i--)
{
if(i%2 ==1)
continue;
System.out.print( i+ '' '');
}
(e) State a difference between call by value and call by reference. [2]

(f) Give the output of the following: [2]


Math.sqrt(Math.max(9,16))

(g) Write the output for the following: [2]


String s1 = ''phoenix''; String s2 =''island'' ;
System.out.println (s1.substring(0).concat (s2.substring(2) ) );
System.out.println(s2.toUpperCase());

(h) Evaluate the following expression if the value of x=2, y=3 and z=1. [2]
v=x+ --z+ y++ +y

(i) String x[] = {"Artificial intelligence", "IOT", "Machine learning", "Big data"}; [2]
Give the output of the following statements:

(i) System.out.println(x[3]);
(ii) System.out.println(x.length);

(j) What is meant by a package? Give an example. [2]

15
not include important keywords like related classes
etc. in the definition. Some candidates wrote - Explain, with examples, how to find the
collection of classes/ collection of functions/objects, length of the array and array element.
etc. - Advise students to include keywords
while writing the definition of a term.

MARKING SCHEME
Question 3
(a) Math.abs(x*x +2*x*y)
Math.abs(Math.pow(x,2)+ 2*x*y)
(b) (i) boolean
(ii) double
(c) tax = 200

(d) 4 2
five times loop will execute
(e) Call by value Call by reference
It works with primitive data type It works with reference data
type
The original value of variable The original value of variable
remains unchanged changes
Operation is performed on Operation is performed on
duplicate value of variables original values of variables.
It is also called as pure function. It is also called as Impure
function.

(f) 4.0

(g) phoenixland
ISLAND

(h) v=9

(i) (i) Big data


(ii) 4
(j) Package in Java is a mechanism to encapsulate a group of classes, sub packages and interfaces
Example: java.lang
java.util
java.io

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

Question 4
Design a class name ShowRoom with the following description: [15]

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


void input () - To input customer name, mobile number, cost
void calculate () -To calculate discount on the cost of purchased items, based on following
criteria

Discount
Cost
(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.

18
MARKING SCHEME
Question 4
import java.util.*; Steps
class ShowRoom Class name
{
Declaration of Variables
String name;
long mobno; Default constructor
double cost; void input ()
double dis; 3 Inputs
double amount;
4 conditions and calculations
ShowRoom( )
{ amount = cost – dis
name = " "; void display () with Output statements
cost=0; Object creation & function call
mobno=0;
dis = 0.0; Mnemonic code / Variable description
amount=0.0;
}
void input()
{
Scanner sc = new Scanner(System.in);
System.out.println("enter name, mobile no and cost");
name=sc.next();
mobno=sc.nextLong();
cost=sc.nextDouble();
}
void calculate()
{
if(cost <=10000)
{
dis=0.05*cost;
}
else if(cost >10000 && cost <=20000)
{
dis=0.1*cost;
}
else if(cost >20000 && cost <=35000)
{
dis=0.15*cost;
}
else
{
dis=0.2*cost;
}
amount = cost - dis;
}
void display()
{

20
System.out.println("Name is :"+name);
System.out.println("Mobile no is :"+mobno);
System.out.println("Amount :"+ amount);
}
public static void main (String arg[])
{
ShowRoom ob =new ShowRoom();
ob.input();
ob.calculate();
ob.display();
}
}

Question 5
Using the switch-case statement, write a menu driven program to do the following: [15]

(a) To generate and print Letters from A to Z and their Unicode

Letters Unicode

A 65

B 66

. .

. .

. .

Z 90

(b) Display the following pattern using iteration (looping) statement:

1 2

1 2 3

1 2 3 4

1 2 3 4 5

21
Comments of Examiners
(a) Many candidates answered this question correctly. Suggestions for teachers
Some common errors observed were: - Explain clearly the switch case
(i) unable to develop menu driven programs using construct with syntax.
switch case.
(ii) wrote two separate programs instead of one menu - Teach the difference between loop
driven program. and nested loop with examples.
(iii) no knowledge of type conversion. - Explain the importance of break
(iv) did not accept choice in the menu. statement.
(v) Initial and final values of looping statements - Explain how to obtain the ASCII
were incorrect in some answer scripts. code of character.
(vi) Used twenty-six different print statements to
- Demonstrate type conversion on the
display the Unicode characters. computer.
(vii) Missed out break statement.
(viii) In the switch statement, wrote s in capital - Drill objective type exercises based
terminated with a semicolon i.e. Switch (ch);. on the type conversion.

(b) Many students - Teach the concept of pattern printing


with nested loop through a lot of
(i) Wrote pattern without nested for loop. programs.
(ii) Used five printing statements for displaying the - Explain the purpose of outer and
pattern. inner loop in the nested loop as outer
(iii) Used print statement in place of println () loop is for number of lines and inner
statement. loop is for each line considering that
many elements are to be printed.
- Emphasise on < and > sign and its
effect on the output.

MARKING SCHEME
Question 5
import java.util.*;
class menu
{
public static void main (String args[])
{
Scanner obj = new Scanner (System.in);
int choice,x;
System.out.println(" enter 1 for unicode of letters, 2 Pattern");
choice = obj.nextInt();
switch(choice)
{

22
case 1: System.out.println(" Letters "+ “ " + " Unicode");
for (char c='A'; c<='Z'; c++)
{
Steps
x=c;
Menu with Input choice
System.out.println( c +" "+ x);
switch(choice) with {
}
/* OR case1 :

char x; loop

for (int i=65;i<=90;i++) Assignment

{ x=(char)i; Output Statement

System.out.println(x +" "+ i); break

}*/ case 2:

break; outer loop

case 2: inner loop

for (int i=1; i<=5;i++) printing

{ new line

for (int j=1; j<=i; j++ ) Mnemonic code / variable description

{
System.out.print(j+" ");
}
System.out.println();
}
} // End of switch
}// End of main
}// End of class

23
[15]
Question 6
Write a program to input 15 integer elements in an array and sort them in ascending order
using the bubble sort technique.

Comments of Examiners
Suggestions for teachers
Most of the candidates were able to write this program
- Teach correct syntax of the array
correctly. However, some of the common mistakes
creation and where to mention the size
observed were: of the array with various datatypes.
(i) Array was not created properly. - Explain the difference between array
(ii) Array input was written without using a loop. initialization and creation.

(iii) String input been taken. - Demonstrate on the computer that for
array input / output / any operation,
(iv) In sorting part, outer loop was written as - for (int index starts from 0 and ends
i=1;i<=15;i++) inner loop - for(int j=0 ; j<=15 ; <a.length.
j++). - Clarify that each array element is
(v) Swapping was not done correctly a[j] =a[j+1]; accessed using its index /subscript.
a[j+1]=temp; temp was not assigned any value. - Interpret the technique of sorting with
(vi) Syntax of the method to input value into array being examples.
incorrect a[ ] =sc.next() or nextint();. - Spell out the purpose of outer loop
and inner loop in an array.
- Show swapping on the computer.

MARKING SCHEME
Question 6
import java.util.*;
class Bubble
{ public static void main(String[]args)
{
Scanner abc = new Scanner (System.in);
int a[] = new int[15];
System.out.println("Enter elements");
for (int i=0;i<15;i++) // OR i< a.length
{
a[i]=abc.nextInt();
}//end of for

int temp;
for (int i=0;i<a.length-1;i++) // OR i <14
{
for (int j=0;j<(a.length-1)-i;j++) // OR j<14-i
{
24
if(a[j]>a[j+1]) Steps
{
temp=a[j]; Array Declaration
a[j]=a[j+1]; Input
a[j+1] =temp;
}//if Sorting: Outer loop (< a. length-1 or < 14)
}//inner Inner loop (< (a.length-1) –i or <14-i )
}//outer
check
}//main swap
}//end class
int temp
Mnemonic codes / Variable description

Question 7
Design a class to overload a function series () as follows: [15]

(a) void series (int x, int n) – To display the sum of the series given below:

x1 + x2 + x3 + ……………… xn terms

(b) void series (int p) – To display the following series:

0, 7, 26, 63 ……………. p terms

(c) void series ( ) – To display the sum of the series given below:
1 1 1 1
+ + ................
2 3 4 10

25
MARKING SCHEME
Question 7
class Overload Steps
{ Function prototype with 2 parameters
public static void series (int x , int n) Declaration and initialization of double sum
{ for loop
double sum=0.0; Using math function and adding terms
for (int i=1;i<=n;i++) Displaying sum
{ Second function with one parameter

sum=sum+ Math.pow(x,i); Declaration and initialization of double sum

} for loop

System.out.println(sum); Finding term and displaying


Third function with no parameter
}
for loop
public static void series (int p)
Finding sum
{
Displaying
for (int i=1; i<=p; i++)
Mnemonic codes / variable description
System.out.println((i*i*i)-1);
}
public static void series ()
{
double sum=0.0;
for (int i=2; i<=10;i++)
{
sum=sum+(double)1/i;
}
System.out.print("Sum= "+sum);
}//end of function

27
Question 8 [15]
Write a program to input a sentence and convert it into uppercase and count and display the
total number of words starting with a letter 'A'.
Example:

Sample Input: ADVANCEMENT AND APPLICATION OF INFORMATION


TECHNOLOGY ARE EVER CHANGING.

Sample Output: Total number of words starting with letter 'A' = 4.

Comments of Examiners
Majority of the candidates answered this question correctly.
However, in this question variety of logic was used to Suggestions for teachers
write the program. The common errors observed in this
- Explain the concept of string
program were: thoroughly, giving adequate practice
(i) Not added a space before or after the string. to the students in all the string
functions.
(ii) Extracting the part of the string was not done
correctly. - Clarify commonly used string
functions using examples.
(iii) Instead of checking for A, a character was accepted
- Clearly spell out the importance of
and checked for that character.
length ().
(iv) Instead of nextLine(), next() was written. - Lay stress that index of String starts
(v) In the for loop, index started from 1 instead of 0. with 0.
For (int i=1; i<=s.length();i++). - Explain to the students that every
(vi) Counter variable was not initialised to 0. function of String is needed to be
used with String object/variable, e.g.
(vii) The counter variable was initialised inside for s1. length ().
loop. - Illustrate the necessity and
(viii) Output statement was written inside for loop to initialization of the counter variable
display count. through example programs.

(ix) Next character after space was taken as ch+1. - Demonstrate the difference between
the statements s1. charAt(i+1) and
(x) String functions were called/invoked without s1. charAt(ch+1).
String Variable/object.

28
MARKING SCHEME
Question 8
import java.util.*;
class loop Steps
{ Variable declaration and initialization
public static void main (String args[]) Input & convert to uppercase
{ Finding length
Scanner sc=new Scanner (System.in); loop
String str; char ch, ch1; int c=0; Extraction of a characters ( ch & ch1)
System.out.println("Enter a sentence"); Checking for first character & increment counter
str= sc.nextLine(); Checking for rest of the characters & increment counter
str=str.toUpperCase(); Output
int len= str.length(); Variable description / Mnemonic codes
for (int i=0; i<len-1;i++)
{
ch= str.charAt(i);
ch1=str.charAt(i+1);
if (i==0 && ch=='A')
c++;
else if (ch==' ' && ch1=='A')
c++;
}
System.out.println("Number of words started with letter 'A' ="+c);
}
}

Question 9
A tech number has even number of digits. If the number is split in two equal halves, then the [15]
square of sum of these halves is equal to the number itself. Write a program to generate and
print all four digits tech numbers.
Example:
Consider the number 3025
Square of sum of the halves of 3025 = (30+25)2
= (55)2
= 3025 is a tech number.

29
Comments of Examiners
Most of the candidates attempted this question
correctly. However, the common mistakes in this Suggestions for teachers
program were: - Explain extraction of digits from a
(i) Instead of the code for generating all the four number using n %100 and n /100
digits tech number, a number from the user was with an example.
accepted. - Clarify the looping /iterative
(ii) Only the logic for the example given in the construct with lot of examples.
question paper, i.e., 3025 was accepted.
(iii) A four-digit number into two equal halves was not - Give practice to the students in multi
digit-based programs.
split.
(iv) Instead of n%100 and n/100 respectively, n%10 - Instruct the students to read the
and n/10 were used. questions carefully.
(v) Both the halves as per the question were not
summed up.
(vi) Instead of calculating square of the sum, 2 to the
sum was multiplied.
(vii) Instead of printing the required tech number, the message It is a tech number was printed.

MARKING SCHEME
Question 9
class Q9 Steps
{ Declaration of variables
public static void main (String loop
args[])
Finding the first half and second half of the
{
number
int x,i,j,k, n;
Adding the two halves
for (x=1000; x<=9999; x++)
Finding the square
{
Checking the original number with the
i= x%100; square
j= x/100; Displaying the output
n= i+j; Mnemonic codes / Variable description
k=n* n;
if(x== k)
System.out.println(x);
}
}

30

You might also like