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

Latest 122

1. The document contains a practice paper for an exam with 50 marks and 10 multiple choice questions. The questions cover topics like classes and objects, loops, methods, and basic Java concepts. 2. The second section contains two programming questions worth 30 marks total. Question 7 asks to write a program to calculate employee salary based on salary brackets and allowances. Question 8 asks to write an overloaded method to calculate sums of series. 3. The last section contains one question worth 20 marks about checking if a number is a perfect square. It provides code with gaps to be filled. The document tests concepts of classes, loops, arrays, methods and conditionals.

Uploaded by

ks.ashwini
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)
111 views

Latest 122

1. The document contains a practice paper for an exam with 50 marks and 10 multiple choice questions. The questions cover topics like classes and objects, loops, methods, and basic Java concepts. 2. The second section contains two programming questions worth 30 marks total. Question 7 asks to write a program to calculate employee salary based on salary brackets and allowances. Question 8 asks to write an overloaded method to calculate sums of series. 3. The last section contains one question worth 20 marks about checking if a number is a perfect square. It provides code with gaps to be filled. The document tests concepts of classes, loops, arrays, methods and conditionals.

Uploaded by

ks.ashwini
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/ 9

Practice paper II

Maximum Marks: 50
Time allowed: One hour (inclusive of reading time)
ALL QUESTIONS ARE COMPULSORY.
The marks intended for questions are given in brackets [ ]

SECTION A (30 Marks)


Question 1 [5x1=5]
Choose the correct option :
a.The relationship between classes and objects is that:
1.Objects can produce classes 2. A class is an instance of an object
3.Objects are blueprints of classes 4.A class can produce multiple objects

b. Compilation of a java program results in :


1. Source code 2. Object code
3. Byte code 4. Assembly language code

c. The java expression for

a2 +b2 x (a+b) 5

axb

1.((Math.sqrt( Math.pow(a+b),2)) * Math . pow(a+b, 5)) / (a*b)


2. (Math.sqrt( a*a + b*b) * Math . pow(a+b, 5)) / (a*b)
3. (Math.sqrt( a x a + b x b) * Math.pow(a+b, 5)) / (a*b)
4. (Math.sqrt( a*a + b*b) * Math . sqrt(a+b, 5)) / (a*b)

d. The keyword used to access the content of another package is :


1.package 2. import
3.final 4. export

e. How many times will the following loop execute ?


int x=2, y=50;
while(x<=10)
{
++x;
y-=x++;
}

1. 4 2. 5 3. 1 4. 3
Question 2 [5x1=5]
Fill in the blanks with the correct option.

a.___________ is a user-defined data type.


1. String
2. double
3. class
4. char

b. Performing a set of statements repeatedly is called ____________.


1.Function call 2. Iteration
3.Conditional statement 4. Terminating a loop

c. import java . util . Scanner;


(i) (ii)
Identify i and ii.
1. i-package, ii-object
2. i.-class, ii-package
3. i.-package, ii-class
4. i.-package, ii-method

d. != is a ___________ operator.
1. Logical 2.Relational
2.Assignment 4.Arithmetic

e.switch-case can be replaced with _____________.


1.while() 2.do-while()
3.for() 4.if-else

Question 3 [5x1=5]
Name the following :

a. A variable, a copy of which every object has.


1.Instance variable 2.Static variable 3.Local variable

b. A double data converted to int data :


1. Data conversion 2. Implicit type conversion 3. Explicit type conversion

c.The function used to round off a number to an integer value :


1.Math.ceil() 2.Math.round() 3.Math.floor()

d.The keyword used to jump out of a loop :


1.default 2.continue 3.break

e.The error type which results in a wrong output :


1.Logical 2. Syntax 3.Run-time
Question 4 [5x1=5]
State true or false.

a.Math.random() returns a value between 0 to 1, both inclusive.


1.true 2.false

b.Scanner class has to be imported to accept values using the next() function.
1.true 2.false
c.The function Integer.parseInt() is used to convert an int value into a String value.
1.true 2.false

d. A binary operator will have two operands.


1.true 2.false

e. default statement is compulsory in switch-case.


1.true 2.false

Question 5 [5x1=5]
Choose the odd one

a)1.break 2.continue 3.new 4.return

b)1.3+4 2. 5*7 3. 8%5 4. 30 > 50

c)1. == 2. >= 3. || 4. <=

d)1.String 2.char 3.int 4.double

e)Math.round() 2.nextInt() 3.nextDouble() 4.next().charAt(0)

Question 6 [5x1=5]
1.Give the output of the following :

a. char c= (char) 69;


String res=(c>=’a’ && c<=’z’) : “Lower Case “ : “Upper Case”;
System.out.println(res);

1.Lower case 2. Upper case 3. False 4.true

b int a=6,b=3,c=9;
int x=(a--)-(--a)+(b++)*(--c);

1.23 2. 22 3. 26 4. - 26
c. Math.pow(Math.max(5,3), Math.min(5,3));

1. 625 2.125 3. 25.0 4.125.0

d. class A
{
static int add(int a)
{
return a+10;
}
static double add(double a)
{
return a+20;
}
void calc()
{
int x=add(50);
System.out.println(“The value of x is :”+x);
}
}

1.The value of x is : 50 2. The value of x is : 70.0


3. The value of x is : 60 3. The value of x is : 50.0

e. int n = 2;
switch (n)
{
case 1: System.out.println(“One”);
case 2: System.out.println(“Two”);
case 3: System.out.println(“Three”);
case 4: System.out.println(“Four”);
break;
default: System.out.println(“Invalid number”);
}

1. One
Two
Three
Four
2. Two
Three
Four
3. Two
Three
4. Two
Three
Four
Invalid number

SECTION B (20 Marks)

Question 7
A company announces revised Dearness Allowance (DA) and Special Allowance (SA) for their
employees as per the tariff given below :
Basic DA SA
Upto Rs.10,000 10% 5%
Rs.10,001 to Rs.20,000 12% 8%
Rs.20,001 to Rs.30,000 15% 10%
Rs.30,001 and above 20% 12%

WAP to accept the name and Basic Salary of an employee and calculate and display the
gross salary.
Gross Salary = Basic + Dearness Allowance + Special Allowance
Display the information in the given format :
Name Basic DA Spl. Allowance Gross Salary [6x1=6]
….. ….. ….. ….. ……

import java.util.Scanner;
class EmployeeSalary
{
public static void main(String args[])
{
String name;
double basic, da, sa, gross, daPerc, saPerc;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the employee name :");
name=sc.nextLine();
System.out.println("Enter the basic salary :");
(a) __________
if(basic<=10000)
{
(b)___________
saPerc=5.0;
}
else if((c)___________)
{
daPerc=12.0;
saPerc=8.0;
}
else if(basic>=20001 && basic<=30000)
{
daPerc=15.0;
saPerc=10.0;
}
else
{
daPerc=20.0;
(d)_____________
}
da=(daPerc/100)*basic;
(e)_______________
System.out.println("Name\t\tBasic\tDA\tSpl. Allowance\tGross Salary");
(f)_______________
}
}
(a)1. basic=sc.nextInt();
2. basic=sc.nextDouble();
3. basic=sc.next();

(b)1. daPerc=10.0;
2. daPerc=5.0;
3. daPerc=10.0/10;

(c)1. basic>10001 || basic<=20000


2. basic >=10001 || basic <20000
3. basic>=10001 && basic<=20000

(d) 1. saPerc=12.0;
2. saPerc=12.0/10;
3. saPerc=20.0;

(e)1.sa=(saPerc/10.0) * basic;
2.sa=saPerc * basic;
3. sa=(saPerc/100)*basic;

(f)1. System.out.println(“name\t\t basic\t da\t sa\t gross”);


2. System.out.println(name+”\t\t”+ basic+”\t”+ da+”\t”+ sa+”\t”+ gross);
3. System.out.println(“name”+\t\t+”basic”+\t+” da”+\t+” sa”+\t +“gross”);

Question 8
WAP to create a class Overload, with the specifications given below :
display() – 1/2 + 2/3 + 3/4 + ………..+ 19/20
display(int a, int n) – S= 1/a + 1/ a2 + 1/ a3+……..+1/an
main()-calls the above method and passes the values of a and n. [6x1=6]

class Overload
{
static void display()
{
double sum=0.0;
double n, d;
for(n=1.0, (a)_______;n<=19.0; n++, d++)
{
sum=(b)__________
}
System.out.println("The sum of the series is :"+sum);
}
static void display((c)__________)
{
double sum=0.0;
for(int i=1; (d)________; i++)
{
sum+=(e)____________
}
System.out.println("The sum of the series is :"sum);
}
public static void main(String args[])
{
(f)__________
display(3,10);
}
}

(a)1. d=1.0
2. n=2.0
3. d=2.0

(b)1. sum+(n/d);
2. sum=sum+n/d;
3. sum+ (n*d);

(c)1.int a, double n
2.int a; int n;
3. int a, int n

(d)1. i<=n
2. i<n ;
3. i<=10

(e) 1. Math.pow(a,i);
2. 1/Math.pow(a ,i);
3. 1/Math.pow(a,a);

(f)1. display(10 );
2. display();
3. ob.display();

Question 9
The following program segment displays the sum of the digits of a number n. (A perfect
square is a number the square root of which is an integer number.)
Complete it by choosing the appropriate options. [4x1=4]
void perfectSquare(int n)
{
(a)__________ sq, flr;
sq=(b)____________
flr=Math.floor(sq);
if((c)______________)
(d)____________________
else
System.out.println(“The number “+n+” is not a Perfect square”);
}
(a)1. double
2. int
3. float

(b)1. sqrt(n);
2. Math.sqrt(n);
3. Math.ceil(n);

(c)1. sq != flr
2. sq==flr
3. flr==n

(d)1. System.out.println(“The number “+n+” is not a Perfect square”);


2. System.out.println(“The number “+sq+” is a Perfect square”);
3. System.out.println(“The number “+n+” is a Perfect square”);

Question 10
Read the paragraph given below and answer the questions given below.

Case study 1
The flow of control during the execution of a program takes place in the following ways :
i)Normal / Sequential flow of control
ii)Conditional flow of control
iii)Multiple branching of control
In the Normal flow of control, the statements are executed one after the other in a
sequence.
In a Conditional flow of control, a condition is checked and if the condition evaluates to
true, one set of statements are executed, otherwise another set of statements are
executed. The constructs if, if-else, if-else if, nested if, ternary operator are Conditional
statements.
In Multiple branching of control, a particular block of statements are executed out of a
number of blocks, as per the user’s choice. Switch-case is a multiple branching
construct. In this based on the value of a variable, the block of statements pertaining to
the matching case value is executed. A break statement is used to terminate a block.
[4x1=4]
(a)A set of statements are executed based on a condition check.
1. Normal flow
2. Conditional flow
3. Multiple-branching

(b) The statement used to jump out of switch case :


1. switch-case
2. condition check
3. break

(c) Statements are executed in sequence.


1. Normal flow
2. Conditional flow
3. Multiple-branching

(d)if char c=’2’;


switch(c)
{
case ‘1’: day=”Sunday”;
break;
case ‘2’: day=”Monday”;
break;
case ‘3’: day=”Tuesday”;
break;
default: day=”Wrong day”;
}
What will be the value in variable day?
1. Sunday
2. Monday
3. Wrong day

xxxxxxxxxxx

You might also like