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

Computer 2018

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)
5 views

Computer 2018

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

QUALITATIVE ANALYSIS

SECTION A (40 Marks)


Attempt all questions

Question 1
(a) Define abstraction. [2]

(b) Differentiate between searching and sorting. [2]

(c) Write a difference between the functions isUpperCase( ) and toUpperCase( ). [2]

(d) How are private members of a class different from public members? [2]

(e) Classify the following as primitive or non-primitive datatypes: [2]


(i) char
(ii) arrays
(iii) int
(iv) classes

10
MARKING SCHEME
Question 1
(a) abstraction: the act of representing essential features and hide unnecessary or background
details is called abstraction.
(b) Searching Sorting
To find an element in an array is To arrange the elements in an order
called searching. is called sorting.

(c) isUpperCase toUpperCase

CHECKS whether a given character CONVERTS the character to its


is an uppercase letter or not upper case
Output of this function is boolean Output of this function is character.
(d) public members can be accessed from any other class.
private members can only be accessed within the declared class.
(e) char – primitive array – non-primitive int – primitive class – non primitive

Question 2
(a) (i) int res = 'A'; [2]

What is the value of res?

(ii) Name the package that contains wrapper classes.

(b) State the difference between while and do while loop. [2]

(c) System.out.print("BEST "); [2]

System.out.println("OF LUCK");

Choose the correct option for the output of the above statements

(i) BEST OF LUCK

(ii) BEST

OF LUCK

(d) Write the prototype of a function check which takes an integer as an argument and [2]
returns a character.

12
(e) Write the return data type of the following function. [2]

(i) endsWith()

(ii) log()

Comments of Examiners
(a) (i) Majority of the candidates wrote the answer as ‘A’ Suggestions for teachers
or “A” or A. Candidates were unable to
understand the implicit conversion. - Explain type of conversions, explicit
and implicit, with examples especially
(ii) Most of the candidates were able to answer this
character type to integer type and
question. However, some candidates wrote io or ASCII code and vice-versa.
util as the answer while a few candidates wrote the - Ensure that all concepts of the lesson
answer Lang or in capital letters LANG. on wrapper classes are clear to the
(b) Most of the candidates were able to answer this students.
question. However, some candidates interchanged - Explain the concept of while and
teach this concept with output printing
the answers.
questions.
(c) Majority of the candidates were unable to select the - Clarify the working of println()
correct option for the output of the given statements method explicitly.
as either they seemed to be unclear of the working of - Give practice to the students in the
computer lab, of print() and println()
the println() method or did not read all the options methods, with ample examples.
carefully. - Explain to the students the purpose of
(d) Several candidates could not write the prototype of prototype and every segment of the
the function given in the question. prototype clearly
− Ensure that the students have
(e) (i) Many candidates, instead of writing Boolean, understood the data types of the
wrote return type as String. parameters
(ii) Many candidates wrote return type as float or − While teaching in-built functions,
integer. Some candidates mentioned data types ensure that return data type of each
function, whether mathematical or
with the first letter in uppercase.
character or string, has been
explained, with examples, to th
students
− Explain the difference between the
data types and the wrapper classes
with examples.

13
MARKING SCHEME
Question 2
(a) (i) 65
(ii) lang
(b)
while loop do while loop
Entry controlled loop Exit controlled loop
If condition is false in the beginning Loop will execute at least once even
loop never executes, if the condition is false.
minimum repetition is 0 minimum repetition is 1

(c) (i) BEST OF LUCK


(d) char check (int n)

(e) (i) boolean


(ii) double

Question 3
(a) Write a Java expression for the following: [2]

√3𝑥𝑥 + 𝑥𝑥 2
𝑎𝑎 + 𝑏𝑏
(b) What is the value of y after evaluating the expression given below? [2]
y+= ++y + y-- + -- y; when int y=8
(c) Give the output of the following: [2]

(i) Math.floor (-4.7)

(ii) Math.ceil(3.4) + Math.pow(2, 3)

(d) Write two characteristics of a constructor. [2]


(e) Write the output for the following: [2]
System.out.println("Incredible"+"\n"+"world");
(f) Convert the following if else if construct into switch case [2]
if( var==1)
System.out.println("good");

14
else if(var==2)
System.out.println("better");
else if(var==3)
System.out.println("best");
else
System.out.println("invalid");

(g) Give the output of the following string functions: [2]

(i) "ACHIEVEMENT".replace('E', 'A')

(ii) "DEDICATE".compareTo("DEVOTE")
(h) Consider the following String array and give the output [2]

String arr[]= {"DELHI", "CHENNAI", "MUMBAI", "LUCKNOW", "JAIPUR"};

System.out.println(arr[0].length()> arr[3].length());

System.out.print(arr[4].substring(0,3));

(i) Rewrite the following using ternary operator: [2]


if (bill >10000)
discount = bill * 10.0/100;
else
discount = bill * 5.0/100;

(j) Give the output of the following program segment and also mention how many times [2]
the loop is executed:
int i;
for ( i = 5 ; i > 10; i ++ )
System.out.println( i );
System.out.println( i * 4 );

15
(g) (i) Majority of the candidates were able to answer this
question. However, in a few answer scripts only the - Give adequate practice in conversion
first occurrence of E was converted. of if to switch and vice-versa.
(ii) Majority of the candidates were unclear about the - Discuss with the students, examples
working of compareTo() function. Several candidates of various problems with the
were unable to calculate ASCII difference. In a few appropriate conditional statements.
answer scripts, the answer calculated was either 18 or - Explain String functions with
-1. Some candidates wrote any random negative value examples.
as the answer. - Theoretically and through practical
(h) Some candidates, instead of writing false as the answer, sessions, explain the execution of the
wrote 5>6. Some candidates were unclear whether the compareTo() function, so that the
students understand the difference
position of second argument was included in the output or
between equals() and compareTo()
not. Some candidates extracted the character at third index functions.
also. - Explain the importance of ASCII
(i) The common errors made by majority of the candidates values of the letters (both uppercase
were: and lowercase) to evaluate the output
(i) if(bill>10000)? bill*10.0/100: bill*5.0/100. value.
(ii) The assignment part of the statement was not being - Clarify to the students how relational
written. operators works in output statement
(iii) ‘discount =’ - not being written. and results as true or false.
(j) Majority of the candidates were unable to identify the final - Practically show to the students how
limit of the loop. Some candidates wrote error in the to extract the number of characters in
substring function.
condition of the loop.
- Interpret clearly the purpose and the
working of the second argument in
substring() function.
- Explain to the students that ‘?’
represents if and: represents else.
- Make the students practice
conversion from if- else to ternary and
ternary to if- else in the class.
- Explain all the variations of for loop.
- Teach loops with different initial and
final values and their output after
execution.

MARKING SCHEME
Question 3
(a) 𝑀𝑀𝑀𝑀𝑀𝑀ℎ. 𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠(3 ∗ 𝑥𝑥 + 𝑥𝑥 ∗ 𝑥𝑥)/(𝑎𝑎 + 𝑏𝑏) OR
Math.sqrt(3*x+Math.pow(x,2))/(a+b);
(b) 33
(c) i. -5.0
ii. 12.0

17
(d) (i) Constructors have the same name as that of the class they belong to.
(ii) Constructors are executed when an object is created.
(e) Incredible

world
(f) switch(var)
{
case 1: System.out.println("good");
break;
case 2: System.out.println("better");
break;
case 3: System.out.println("best");
break;
default: System.out.println("invalid");
}

(g) (i) ACHIAVAMANT


(ii) -18
(h) (i) false
(ii) JAI
(i) discount = bill>1000? bill*10.0/100: bill *5.0/100;
(j) Output: 20 Loop is not executed even once

SECTION B (60 Marks)


Attempt any four questions from this Section

Question 4
Design a class RailwayTicket with following description: [15]

Instance variables/data members :

String name : To store the name of the customer

String coach : To store the type of coach customer wants to travel

long mobno : To store customer’s mobile number

18
int amt : To store basic amount of ticket

int totalamt : To store the amount to be paid after updating


the original amount

Member methods :

void accept () – To take input for name, coach, mobile


number and amount.

void update () – To update the amount as


per the coach selected

(extra amount to be added in the amount as follows)

Type of Coaches Amount


First_AC 700
Second_AC 500
Third_AC 250
sleeper None
void display () – To display all details of a
customer such as name, coach, total amount and mobile number.

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

Comments of Examiners
Numerous types of errors were committed in this question by
many candidates, namely:
- Used a different class name other than the one given in
Suggestions for teachers
the question. - Train students to write programs
- Variable declaration was done at many places i.e. involving multiple functions.
immediately after class and also inside accept() - Explain the difference between global
- Function names and variable names were different from and local variables and how to use
the ones asked in the question. them in different functions in a
program.
- The ‘totalamt’ which was to be calculated was accepted
- How to create an object and invoke the
from the user. function using the object needs to be
- Update() function. explained thoroughly and practised
- Syntax error while writing input statement e.g. nextInt() properly.
- which letter to be written in capital.
- While comparing types of coaches, words were not
written within double quotes.
- Calculation of extra amount.
- Syntax errors in the object creation and function call statement.

19
MARKING SCHEME
Question 4
import java.util.*;
class RailwayTicket
{
String name, coach;
long mobno;
int amt ,totalamt;
void accept()
{
Scanner sc = new Scanner(System.in);
System.out.println("enter name , coach and mobile no and amount");
name=sc.next();
coach=sc.next();
mobno=sc.nextLong();
amt=sc.nextInt(); }
void update()
{
if(coach. equalsIgnoreCase ("First_AC"))
totalamt=amt+700;
else if(coach. equalsIgnoreCase ("Second_AC")) STEPS
class name
totalamt=amt+500; Variable declaration
else if(coach. equalsIgnoreCase ("Third_AC")) void accept ()
totalamt=amt+250; Four inputs
else
totalamt=amt; void update()
} Four conditions and calculations
void display() {
System.out.println("name is :"+name); void display ()
System.out.println("mobile no is :"+mobno); Output (totalamt compulsory)
System.out.println("coach is :"+ coach); Object creation with one function call
System.out.println("total amount is :"+totalamt); } Variable description/Mnemonic codes
public static void main (String arg[])
{
RailwayTicket ob =new RailwayTicket();
ob.accept();
ob.update();
ob.display(); }}
20
Question 5 [15]
Write a program to input a number and check and print whether it is a Pronic number or not. (Pronic
number is the number which is the product of two consecutive integers)

Examples: 12 = 3 × 4

20 = 4 × 5

42 = 6 × 7

Comments of Examiners
Many candidates answered this question correctly. Some Suggestions for teachers
common errors observed were: − Train students about the use of for
- Output in most cases was written inside the loop and loop.
the break and flag statements were not written. − Give sufficient practice on
- “Not a pronic number” was not printed, problems to print an appropriate
- In the if condition, instead of (i*((i+1)==num), output message.
(i*i+1==num) was written. − Explain Operator precedence and
- In the if statement, instead of the relational operator importance of use of parenthesis in
proper place.
(==), assignment operator (=) was used.
− The effect of not putting
- Mentioning that else statement inside the loop results
parenthesis should be shown on the
in printing both the statements “Pronic Number” and computer.
also “Not a pronic number”. − Teach students the use of break
statement to come out of the loop.
− Advice the students to read the
questions carefully.

21
MARKING SCHEME
Question 5
import java.util.*; STEPS
class pronic { Input
public static void main(String arg[]) flag initialisation
{ for loop
Scanner sc = new Scanner(System.in);
System.out.println("enter the number"); if condition
int num=sc.nextInt();
int flag=0; flag=1
for(int i=0;i<num;i++) Jump statement break
{ if else and displaying message
if( i*(i+1)==num) Variable description/Mnemonic codes
{
flag=1;
break;
}
}
if(flag==1)
System.out.println("Pronic number");
else
System.out.println("Not a pronic number");
}
}
Alternate method
class Q5
{
public void pronic (int n)
{
int s=(int)Math.sqrt(n);
if(s*(s+1)==n)
System.out.println(n +" is a pronic number");
else
System.out.println(n+" is not a pronic number ");
}
}
Variable description

22
[15]
Question 6
Write a program in Java to accept a string in lower case and change the first letter of every
word to upper case. Display the new string.

Sample input: we are in cyber world

Sample output: We Are In Cyber World

Comments of Examiners
Majority of the candidates were unable to answer this
question correctly. Some of the commonly made Suggestions for teachers
mistakes were: − Illustrate to the students that in the
- Not taking care of the index of charAt() or String, since position starts with 0,
substring() function. so condition should be either i<
- Incorrect initial and final values of the for loop- s.length() or i<=s.length()-1.
forr(int i=1; i<=l;i++). − Explain practically to the students
- Accessing first character after space was done how to access character after space.
by writing (ch+1). − Give adequate number of exercises
- Converting the first character after space was on String and Character functions to
done as: avoid confusion with the students
ch.toUpperCase() or (ch+1).toUpperCase() when they use it in the program.
- Displaying output without space between the
words.
- Getting an incorrect output as only the first character
was converted and displayed.

MARKING SCHEME
Question 6
import java.util.*;
class ques6 {
public static void main(String args[]) {
Scanner obj= new Scanner(System.in);
String s="";
System.out.println(" enter a string");
String sen=obj.nextLine();
sen=' ' +sen;
int l= sen.length();
for(int x= 0; x<l; x++) {
char ch= sen.charAt(x);
if (ch==' ') {

23
int i= sen.charAt(x+1);
i=i-32;
s= s+ ' '+ (char)i;
x++; }
else s=s+ch;}
System.out.print(s);
}}

Alternate Method
// To change the first letter of each word to uppercase
import java.util.*;
class Q6_Title_Case
{
public static void main(String args[])
{
Scanner sc= new Scanner(System.in);
String sent,x="";
char k , p ;
int len, i;
System.out.print("Enter a sentence");
sent= sc.nextLine();
sent= sent.toLowerCase();
sent= " " + sent;
len = sent.length();
for(i=0;i<len-1;i++)
{ STEPS
k=sent.charAt(i);
Input
p=sent.charAt(i+1);
if(k==' ' && p!=' ') Declaration of variable
p=Character.toUpperCase(p);
x=x+p; Finding length
}
System.out.println("The new string is "+ x);
} Logic
} Output
Alternate Method Variable description/Mnemonic codes
class change
{
void change( String s)
{
int l=s.length(),p,i;
String str="";
s=s.toLowerCase();
s=s+" ";
for(i=0;i<l;i++)
{
24
p=s.indexOf(" ",i);
str=s.substring(i,p);
System.out.print(Character.toUpperCase(str.charAt(0))+str.substring(1)+" ");
i=p;
}}}

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

(i) double volume (double R) – with radius (R) as an argument, returns the volume of sphere
using the formula.

V = 4/3 × 22/7 × R3

(ii) double volume (double H, double R) – with height(H) and radius(R) as the arguments,
returns the volume of a cylinder using the formula.

V = 22/7 × R2 × H

(iii) double volume (double L, double B, double H) – with length(L), breadth(B) and
Height(H) as the arguments, returns the volume of a cuboid using the formula.

V=L×B×H

25
MARKING SCHEME
Question 7
import java .io.*;
public class mensuration
{ STEPS
double volume(double R) 3 Functions with correct argument
{ Formulas in all the 3 functions
double V= 4.0/3* 22.0/7*Math.pow(R,3); return statements in all the 3 functions
return(V); Variable description/Mnemonic codes
}
double volume( double H,double R)
{
double V= 22.0/7 * Math.pow(R,2) *H;
return(V);
}
double volume( double L, double B , double H)
{
double V = L*B*H;
return( V);
}
}

Question 8 [15]
Write a menu driven program to display the pattern as per user’s choice.
Pattern 1 Pattern 2
ABCDE B
ABCD LL
ABC UUU
AB EEEE
A
For an incorrect option, an appropriate error message should be displayed.

27
Comments of Examiners
Majority of the candidates attempted well barring a few
exceptions who showed following lapses:
- Menu was not displayed.
Suggestions for teachers
- Input for choice was not taken. − Give sufficient practice for writing
- Pattern printing was done using multiple print menu – driven programs.
statements. − programs on pattern printing and
- Nested loop logic was not used, series calculation which require
- To start with new line,println( ) was missing,. nested looping.
- ASCII value was used to print ABCDE but was not − Teach problems involving
converted properly. (Loop value started with 65 and conversion of character to its
ASCII value and vice-versa.
was checked for <= 69, but conversion to character
− Give adequate practice of nested
was incorrect).
for loop, show the working and
- Two separate classes were written instead of one. effect on the output when
- In the statements, switch and default. first character condition is changed. i.e. instead of
s and d were in capital letters. < when > sign is used.
− Allow students to do lot of
programs with String and nested
for and show output on the
computer when println() is
missing.
− Provide adequate practice to the
students on Syntax of switch case.
− Lay stress on keywords, which
have to be written in small case.

MARKING SCHEME
Question 8
import java .util.*; STEPS
class series Displaying menu, input choice,
{ switch
public static void main(String arg[]) Initialising/ input string in case 1
{ for loop with length of string
Scanner sc = new Scanner(System.in); Display and substring function
System.out.println("1.Series1 2.series2"); Initialising string in case 2/Input
System.out.println("enter the choice"); Outer for loop
int choice=sc.nextInt(); Inner for loop
switch(choice) Extraction , and display
{ println()
case 1:String s="ABCDE"; Default
for(int i=s.length();i>0;i––) Variable description/Mnemonic
{ codes

28
System.out.println(s.substring(0,i));
}
break;
case 2 :String s1="BLUE";
for(int i=0;i<s1.length();i++)
{
for(int j=0;j<=i;j++)
{ System.out.print(s1.charAt(i)); }
System.out.println();
}
break;
default :System.out.println("invalid choice");
} }
}

Question 9 [15]
Write a program to accept name and total marks of N number of students in two single subscript array
name[ ] and totalmarks[ ].
Calculate and print:
(i) The average of the total marks obtained by N number of students.
[average = (sum of total marks of all the students)/N]
(ii) Deviation of each student’s total marks with the average.
[deviation = total marks of a student – average]

Comments of Examiners
Most of the candidates wrote the program correctly.
However, a few could not attempt it correctly due to Suggestions for teachers
following miscues: - Allow plentiful practice on Array
- Value of N (size of the array) was taken after arrays, creation with different data types.
name and total marks were created - Give sufficient practice of using
- While accepting the values into the array, the index array concept, accepting the values
number was missing. Instead of name[i], candidates into the array, and printing the
wrote name[]= sc.next(). values from the array.
- All operations i.e. input, calculating an average and - Clarify the concept of array index.
deviation was done in one Loop. - Teach using arrays, not only
- The average of the total marks obtained by N number searching and sorting techniques
of students was calculated inside for loop. but other general programs like,
billing for many customers, pay
- Deviation of each student’s total marks with average
slips for many employees etc.
marks was not Displayed, rather it was printed outside
for loop.

29
MARKING SCHEME
Question 9
import java .io.*;
import java.util.*;
class ques9
{
public static void main(String aa[])
{
Scanner obj = new Scanner(System.in);
int n;
System.out.println("enter number of students");
n= obj.nextInt(); STEPS
String name[] = new String[n]; Accepting n, total=0.0
double marks[] = new double[n]; Declaring two array
double ave, total=0.0; Loop
for(int x=0; x<n; x++) Accepting value in array
{ total=total + marks
System.out.println(" enter name and totalmarks"); ave = total/n
name[x]= obj.nextLine(); Output headings, loop for output
marks[x]= obj.nextDouble(); Output with calculation deviation
total=total+ marks[x]; Variable description/Mnemonic codes

}
ave= total/n;
System.out.println("Name " + " " + " Deviation");
for(int x= 0; x<n;x++)
System.out.println( (marks[x]–ave));
}
}

30

You might also like