Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Youtube
Hide Buttons
Menu

We are apologize for the inconvenience but you need to download
more modern browser in order to be able to browse our page

Download Safari
Download Safari
Download Chrome
Download Chrome
Download Firefox
Download Firefox
Download IE 10+
Download IE 10+

First model-Computer Question Paper and Answer key Dec 2014

Don Bosco Senior Secondary School, Vaduthala
First Model Examination , December 2014
[Class: X Marks: 100]
COMPUTER APPLICATION
Attempt all questions from Section A and any four questions from Section B
Answers to this paper must be written on the paper provided separately.
You will not be allowed to write during the first 15 minutes.
This time is to be spent in reading the question paper.
The time given at the head of this Paper is the time allowed for writing the answers.
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[ ].

Section A(40 Marks)
Attempt all questions
Question 1
a) Name the following: . [2]
i. A package that is invoked by default.
ii. A keyword ,to use the classes defined in a package.
b) Define fall through with one example. [2]
c) Write a java statement to create an object dg1 of class Digital. [2]
d) State the total size in bytes of the arrays f[3] of float data type and ch[4] of char [2]
data type.
e) What is the use of the keyword this? Give example. [2]

Question 2

a) What is an infinite loop? Write an infinite loop statement. [2]
b) Name the type of error(syntax, runtime or logical error) in each case given below: [2]
i. Missing semicolon.
ii. Division by a variable that contains a value of zero.
iii. Multiplication operator used when the operation should be division.
c) State the purpose and return data type of the following string functions. [2]
i. indexOf( )
ii. compareTo( )
d) Differentiate between throw and throws. [2]
e) What are user defined packages? [2]
Question 3
a) Assign a variable and the syntax to find the square root of 144. [2]
b) Write a java statement for the following purposes. [2]
i. Declare and create an array NUM of 100 integers.
ii. Declare and initialize an array to store the months of the year.
c) What is the final value of c when the iteration process given below executes? [2]
int c = 0;
for( int i = 1 ; i < = 3; i + +) for( int j = 1; j < = 5; j + = 2) c + +;


d) Write the output of the following segment of program:- [2]
if (a > b || a! = b )
c = ++a + –b;
System.out.println(c + “\t” + a + “\t” + b);
i. Assume a = 5 and b = 2
ii. Assume a = 0 and b = 0



e) Rewrite the following program segment using ternary operator instead of [2] if – else statements.
int y;
if ( x > 0 )
y = 1;
else if(x == 0)
y = 0;
else
y =- 1;



f) Write the corresponding java expression for the mathematical expression given [2]
below:
z =x8 + – xy + tan x


g) Write the two ways in which you can assign a text string “ TOGETHER” to a [2]
string variable , say, str.
h) Find the errors and make corrections in the following parts of java code. [2]
char a[ ] = {1,2,3,4};
for ( int i = 1 ; i < = 4; i++) { if(a[i] = ‘a’) System.out.println(a[i]);

}

i) State the values stored in the variables s1 and s2 . [2]
String str1 = “output”;
String str2 = “good manners”;
String s1 = str2.substring(5).replace(‘n’ , ’t’);
int s2 = str1.lastIndexOf(‘t’);
j) What will be the output of the following program segment? [2] .
String name[ ] = {“Board” , “Examination” };
System.out.println( name[0].length( ));
System.out.println( name.length);

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 such that the logic of the program is
clearly depicted.
Flow-Charts and Algorithms are not required.

Question 4
Define a class Hotel that has the following details:-
Data members:
String name – name of person
int noOfDays – no: of days stayed
int roomNo – room number allotted
String checkInDate – check – in date
String checkOutDate – check – out date
double billAmt – checkout bill amount
Member Methods:
Hotel( ) – non-parameterized constructor
void input ( ) – to input name of person, number of days stayed, room number
allotted, check-in date, check-out date.
void compute ( ) – calculate checkout bill amount as per the special rates for stay
depending upon number of days:
No: of Days Rate
First 3 days Rs. 350/- per day
For next 3 days Rs. 300/- per day
For next 3 days Rs. 275/- per day
Any day beyond 9 days Rs. 225/- per day


void display ( ) – displays output in the following format
HOTEL CLARK’S
NAME :
CHECK-IN DATE :
CHECK-OUT DATE:
NUMBER OF DAYS:
AMOUNT TO BE PAID: [15]

Question 5
Create a class Prime with the following members:
Data members : int n , m
Member Methods:
void input ( ) – to input the numbers n and m
boolean isPrime( int x ) – to check if x is prime or not. If yes return true else return false
void twinPrime( ) – to generate all twinprime numbers between n and m
(assuming m > n)
Write the main( ) function also.
[A twin prime is a prime number that differs from another prime number by two. Except
for the pair (2, 3), this is the smallest possible difference between two primes. Some
examples of twin prime pairs are (3, 5), (5, 7), (11, 13), (17, 19), (29, 31), (41, 43), …
(821, 823), etc. Sometimes the term twin prime is used for a pair of twin primes; an
alternative name for this is prime twin.] [15]
Question 6
Write a program to input the following list of numbers in two single dimensional
named arr1 and arr2.
arr1 = 2,4,3,9,7,10,1,11,5,6
arr2 = 5,6,10,9,4,3,2,4,8,9
Generate output in the following form:
arr1 arr2 arr3(arr12 + arr22)
2 5 29
4 6 52
– – –
– – –
– – –
– – –
Write a program to input 10 integer elements in an array and sort them in descending order using the bubble sort technique. [15]
Question 7
Write a program to perform the following operations:
i. Create a function int sumOfDigits( int x ) which will calculate and return the sum of even digits of a number x.
ii. Create a function int frequency( int x, int y) which return the number of times digit y appears in number x. [15]
Question 8
Define a class called MyString with the following description:
Data member:
String s stores the input string
Member methods:
MyString( ) to initialize the instance variables.
void input( ) to input the string s.
void replaceChar( int c ) to replace the character at index c by ‘*’.
void convert ( ) to convert uppercase characters to lower case and vice versa.[15]
Question 9
Using a switch statement ,write a menu driven program to calculate the maturity amount
Of a Bank Deposit.
The user is given the following options:
Term Deposit
Recurring Deposit
For option 1. Accept principal(P), rate of interest (r ) and time period in years(n).
Calculate and output the maturity amount (A) receivable using the formula
A = P[1 + r/100]n
For option 2. Accept the Monthly Installment(P) , rate of interest (r ) and time period in
Months(n).Calculate and output the maturity amount (A) receivable using the formula
For an incorrect option, an appropriate error message should be displayed. [15]

ANSWER KEY

Section A(40 Marks)

Question 1
a) Name the following:
i. java.lang
ii. import
b) Fall of control to next case below the matching case, in the absence of break,this is called fall through.
Eg:- int a=1;
switch(a)
{ case 1:System.out.print(“ A”);
case 2:System.out.print(“ Fall through”);
break;
case 3:System.out,print(“ Sorry”);
}
o/p: A Fall through
c) Digital dg1= new Digital( );
d) The total size of the arrays f[3] = 3 * 4 =12 bytes
The total size of the arrays ch[4] = 4 * 2 =8 bytes
e) ’this’ keyword is used to point towards the current calling object.
Eg: public class Sample
{ int a=10;
void input()
{
int a=20;
System.out.println(a);
System.out.println( this.a);
}
}
o/p: 20
10


Question 2
a) Infinite loop is loop that does not terminate, when the test expression is missing.
for(int i=0; ;i++);
b)
i. Syntax error.
ii. Runtime error.
iii. Logical error.
c)
i. indexOf( ) – int indexOf(char a) – It returns the index value of the first occurrence of the character specified in the paranthesis. Return type is int.
ii. compareTo( ) – It is used to compare two strings.Return type is int. When the two strings are equal ,it returns 0.
d) throw – it is used to force an exception.
A=i/op;
if(op==0)
throw newArithemetic exception ()
throws-It is to inform that an error has occurred and is specified with
the function prototype.
public void input() throws IO Exception
e) User defined packages are those which are specified by the programmer to relate many classes as a bundle.
Eg: package P1;
class A
{
}
class B
{
} // Now both the classes belong to package P1.
To use this package, import P1.*;

Question 3
a) double a=Mth.sqrt(144);
b)
i. int NUM[]=new int[100];
ii. String months[]={“jan”,”feb”,”mar”,”april”,”may”,”june”,”july”,”aug”,”sep”,”oct”,”nov”,”dec”};
c) final value of c when the iteration process given below executes:-
int c = 0;
for( int i = 1 ; i < = 3; i + +) for( int j = 1; j < = 5; j + = 2) c + +; final value of c = 9(Each time the inner loop executes completely, c is incremented by 3.The outer loop works 3 times,thus c=9 ) d) i. 7 6 1 ii. 0 0 0 e) int y = (x>0)? 1 : ((x==0)?0: -1 );
f) float z =Math.pow(x,8) * Math.sqrt(a+(b*b))-(x*y)+Math.tan(x);
g) 1. String str = “TOGETHER”;
2. char arr[] = {‘ T’,’O’,’G’,’E’,’T’,’H’,’E’,’R’};
String str = new String(arr);
h)
char a[ ] = {1,2,3,4};// integer variables stored in character array
for ( int i = 1 ; i < = 4; i++) // i=0; i<4(out of bound) { if(a[i] = ‘a’) // asssingment operator used in place of relational // operator System.out.println(a[i]); } i) s1= matters s2= 5 j) String name[ ] = {“Board” , “Examination” }; System.out.println( name[0].length( ));// output – 5 System.out.println( name.length);// output -2

SECTION B (60 Marks)
Question 4
import java.io.*;
import java.util.*;
public class Hotel
{
int noOfDays,roomNo;
String name,checkInDate,checkOutDate;
double billAmt;
Hotel()
{
noOfDays=0;
billAmt=0.0;
name=” “;
roomNo=0;
checkInDate=” “;
checkOutDate=” “;
}
void input()
{
Scanner inp= new Scanner(System.in);
System.out.println(” Enter the name “);
name=inp.next();
System.out.println(” Enter the number of days”);
noOfDays=inp.nextInt();
System.out.println(” Enter the room number “);
roomNo=inp.nextInt();
System.out.println(” Enter the check-in date “);
checkInDate=inp.next();
System.out.println(” Enter the check-out date”);
checkOutDate=inp.next();
}
void compute()
{
if(noOfDays<=3) billAmt=noOfDays*350.0; else if(noOfDays<=6) billAmt=3*350.0+(noOfDays-3)*300.0; else if(noOfDays<=9) billAmt=3*350.0+3*300.0+(noOfDays-6)*275.0; else billAmt=3*350.0+3*300.0+3*275.0+(noOfDays-9)*225.0; } void display() { System.out.println(” HOTEL CLARK’S “); System.out.println(“NAME:”+name); System.out.println(“CHECK-IN DATE:”+checkInDate); System.out.println(“CHECK – OUTDATE:”+checkOutDate); System.out.println(“NUMBER OF DAYS:”+noOfDays); System.out.println(“AMOUNT TO BE PAID:”+billAmt); } public static void main(String args[]) { Hotel ob = new Hotel(); ob. input(); ob.compute(); ob.display(); } }

Variable Description
Variable name Data Type Description
name String to store name of person
noOfDays int to store no: of days stayed
roomNo int to store room number allotted
checkInDate String to store check – in date
checkOutDate String to store check – out date
billAmt double to store checkout bill amount

Question 5
import java.io.*;
import java.util.*;
public class Prime
{int n,m;
void input()
{ Scanner inp= new Scanner(System.in);
System.out.println(” Enter the numbers n and m “);
n=inp.nextInt();
m = inp.nextInt();
}
boolean isPrime (int x)
{
boolean flag =true;
for(int i= 2;i <=x/2; i++) if( x % i ==0) { flag =false; break; } return flag; } void twinPrime( ) { String primeno=””; int lastprime=n; int j=0; Scanner in=new Scanner(System.in); for(int i=n;i

Variable Description
Variable name                                 int                       Data Type                                int                       Description
n                                int                       int                                int                       to store the lower limit
m                                int                       int                                int                       to store the upper limit
x                                int                       int                                int                       to store the digit to check prime or not
flag                                int                       bollean                                int                       to store the status true or false
lastprime                               int                       int                               int                       to store the last prime number
i,j                                int                       int                                int                       loop variable

Question 6
i.
import java.io.*;
import java.util.*;
public class Array
{
public static void main(String args[])
{
int arr1[]={2,4,3,9,7,10,1,11,5,6};
int arr2[]={5,6,10,9,4,3,2,4,8,9};
int arr3[] = new int[10];
System.out.println(“arr1 \tarr2 \t arr3 “);
for(int i=0;i< 10;i++) { arr3[i] = arr1[i] * arr1[i] + arr2[i] * arr2[i]; System.out.println( arr1[i] + “\t” + arr2[i] + “\t” + arr3[i]); } } }

Variable Description
Variable name Data Type Description
arr1[] int to store 10 no.s in the array arr1
arr2[] int to store 10 no.s in the array arr2
arr3[] int to store the result in the array arr3
i int loop variable
import java.io.*;
import java.util.*;
public class Bubble
{
public static void main(String args[])
{
Scanner inp=new Scanner(System.in);
int A[]=new int[10];
System.out.println(” Enter 10 no.s : “);
for(int i=0;i<10;i++) A[i]=inp.nextInt(); int i,j,tmp; for(i=0;i<10;i++) { for(j=0;j<10-i-1;j++) { if(A[j] < A[j+1]) { tmp=A[j]; A[j]=A[j+1]; A[j+1]=tmp; } } } System.out.println(” Sorted array “); for(i=0;i<10;i++) System.out.println(A[i]); } }

Variable Description
Variable name Data Type Description
A[] int to store 10 no.s in the array A
tmp int to store a temporary number
i,j int loop variable

Question 7,
import java.io.*;
import java.util.*;
public class Calculate
{
int sumOfDigits(int x)
{
int tmp=x;
int sum=0;
while(x>0)
{
int dig=x%10;
if(dig%2==0)
{
sum=sum+dig;
}
x=x/10;
}
return sum;
}
int frequency(int x, int y)
{
int c=0;
while(x>0)
{
int dig=x%10;
if(dig==y)
{
c++;
}
x=x/10;
}
return c;
}
public static void main(String args[])
{
Scanner inp=new Scanner(System.in);
Calculate ob=new Calculate();
System.out.println(“Enter a number”);
int m=inp .nextInt();
int n=ob.sumOfDigits(m);
System.out.println(“sum of even nos=”+n);
System.out.println(” Enter a number and a digit”);
int a=inp.nextInt();
int b=inp.nextInt();
int z=ob.frequency(a,b);
System.out.println(“Frequency = “+z);
}
}

Variable Description
Variable name Data Type Description
x int to store the number
tmp int to store temporary number
dig int to store a digit from a number
sum int to store sum of the even digits
x,y int to find frequency of y in number x
c int to store the count


Question 8
import java.io.*;
import java.util.*;
public class MyString
{
String s;
MyString()
{
s=””;
}
void input()
{ Scanner inp= new Scanner(System.in);
System.out.println(” enter the string “);
s=inp.next();
}
void replaceChar(int c)
{
StringBuffer sd = new StringBuffer(s);
sd.setCharAt(c,’*’);
System.out.println(sd);
}
void convert()
{
char ch;
int len=s.length();
StringBuffer s1 = new StringBuffer(s);
for(int i=0;i

Variable Description
Variable name – Data Type – Description
s – String – to store the input string
sd – StringBuffer – to store the answer string
s1 – stringBuffer – to store the answer string
ch – char – to store a character
c – int – to store the index value

Question 9
import java.io.*;
import java .util.*;
public class Amount
{
Scanner inp=new Scanner(System.in);
int ch;
int P,r,n;
double A;
void term()
{ System.out.println(“Enter Principal amount”);
P=inp.nextInt();
System.out.println(“Enter rate of interest”);
r=inp.nextInt();
System.out.println(“Enter time period”);
n=inp.nextInt();
A=P*(Math.pow((1+r/100),n));
System.out.println(” Maturity amount =”+A);
}
void recc()
{System.out.println(“Enter monthly installment “);
P=inp.nextInt();
System.out.println(“Enter rate of interest”);
r=inp.nextInt();
System.out.println(“Enter time period”);
n=inp.nextInt();
A=P*n+(P* (n*(n+1))/2 * r/100 * 1/12);
System.out.println(” Maturity amount =”+A);
}
public static void main(String args[])
{Amount a1 = new Amount( );
System.out.println(” 1.Term Deposit “);
System.out.println(” 2.Reccuring Deposit “);
System.out.println(” Enter your choice”);
ch=inp.nextInt();
switch(ch)
{case 1:a1.term();
break;
case 2:a1.recc();
break;
default:System.out.println(” Sorry!!Incorrect choice”);
}
}
}

Variable Description
Variable name Data Type -Description
P – int to store principal amount
r-int -to store rate of interest
n-int -to store time period
A-double-to store the maturity amount
ch-int-to store the choice