[go: up one dir, main page]

0% found this document useful (0 votes)
38 views11 pages

Nishanth X D Computer Applications Home Test

Uploaded by

krishnapatelh66
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)
38 views11 pages

Nishanth X D Computer Applications Home Test

Uploaded by

krishnapatelh66
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/ 11

ST.

PETER’S SCHOOL, BENGALURU


COMPUTER APPLICATIONS
Grade: X Date: 07.11.24
Time: 1 hour Marks: 50
Name: Roll No:

SECTION A (30 marks)


Question 1
Choose the Correct option [5]

1. What does the random() method do?


a) It returns a double value with a positive sign and greater than or equal to 0 and
less than 100
b) It returns a double value but less than 10
c) It returns a double value that is positive and less than 1
d) None of these
2. What is the other name given for dummy parameters?
a) Actual parameter b) Default parameter c) Formal parameter d) None of these
3. ________ are data variables associated with a class and its objects.
a) Methods b) Interfaces c) Fields d) Attributes
4. Which of the following gives the sequence for the horizontal tab?
a) ‘\b’ b) ‘\\’ c) ‘\t’ d)’\n’
5. Which of the following is a primitive data type ?
a) boolean b) byte c) float d) All of these

Question 2 [5]
Tick the correct option to fill in the blank space.
1. ________ of a class is simply an object that has been created based on the class description.
a) Blueprint b) Design c) Object d) An instantiation
2. ______ notation is an expression used to get an access to the instance variables and methods
inside a given object
a) Arrow b) Colon c) Semicolon d) Dot
3. In a function, the ___________ contains a collection of statements that define what the
method does.
a) Return statement b) Parameter’s list c) Method body d) None of these
4. A class is called an ___________ because it creates objects and used them.
a) Object destructor b) Object factory c) Object modifier d) Object updater
5. Unlike instance variables, whose values are stored in the instance, ______ values are stored
in the class itself.
a) Class variable’s b) Global Variable’s c) final variable’s d) side variable’s
Question 3

Give the output of the following [5]

1. If int y =10 then find int z = (++y*(y+++5));

a) z=176

b) z= 175
c) z=178

d) z=174
2. if int p=5, q=19, then int n= (q-p)>(p-q)? (q-p) :(p-q);

a) n= 15

b) n =14

c) n =10
d) n=16

3.
int a,b;
for(a=6,b=4;a<=4;a=a+6)

if(a%b==0)
break;

System.out.println(a);
a) 4

b) 6

c) 5
d) 0
4. int a=18, b=12;

boolean t=(a>20&&b<15)?true:false;

a) true
b) false
5. if(a>10&&b>10)

R=a*2;

else

R =b*3;
}
What will be the value of r if a= 20 , b=10?
a) r= 45

b) r= 200

c) r =30

d) None of these
Question 4

Name the following [5]

1. To access the current class.

a) new b) this c) void d) final

2. If a loop contains no code in it.

a) infinite loop b) delay loop c) empty loop d) nested loop

3. A statement terminates the loop and the control moves out of the loop.

a) break b) continue c) exit d) all of these

4. The methods create a local copy of the arguments sent to it

a) call by reference b) call by value c) both a and b c) None


5. Operators that act on a single operand.

a) Binary operator b) Relational Operator c) Unary Operator d) Logical Operator

Question 5 [5]

State true or false


1. Access specifiers help in data initialization.

a) true b) false
2. 5_$ is a valid identifier.

a) true b) false

3. Priority of + is less than %

a) true b) false
4. A method can accept one or more values as arguments.
a) true b) false

5. A constructor has return data type.

a) true b) false

Question 6 [5]
1. Identify the protoype of a method names as fnFest , which has return type of int , and take
one int argument .
a) int fnFest(int n) b) int fnfest(n) c) int FnFest( int n) d) None
2. What is the output of the following code?

class loop

{
public static void main()

{
int a=0,m=27;

for(a=25;a<=m;a++)

System.out.println("A="+a);

System.out.println("B="+a);
}}
a) A= 25 b) A=25 c) A=25 d) A=25

B=25 A=26 A=26 B=26

A= 26 A=27 A=27 A=27


B=26 A=28 B=28 B=28
A=27 B=29

B=27

3. What’s wrong in the given code statement: for(int k=2,k<=12,k++)

a) the increment should always be ++k

b) the loop counter must be i and not k

c) there should be semicolon at the end of the statement

d) the commas should be semicolons


4. What will be the output of the snippet?
int ab=948;
int a=Math.max(ab%100, ab/100);

System.out.println(“A=” +a);

a) A=48 b) A=9 c) A= 94 d) A=49

5. What will be the value of v if op=’w’


switch(op)

{ case ‘a’:
case ’e’:

case ‘i’:

case ‘o’:

case ‘u’ : v=’Y’;


break;

default : v=’N’;
}

a) v=’Y’ b) v=’N’ c) both a and b d) None of these


SECTION B (20 Marks)

Question 7

Design a class name ShowRoom with the following description:


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

cost Discount (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. [6]

import java.io. *;
import java.util.*;
class ShowRoom

{
String name;
long mobno;
double cost;
double dis;
double amount;

----------1-------------

{
name =” “;
mobno =0;
cost = 0;
dis = 0;
amount = 0;
}
void input ()

{
Scanner sc = new Scanner (System.in);
System.out.println(“EnterName:”);
name = sc.nextLine( );
System.out.println(“Enter Mobile number:”);
mobno = sc.nextLong( );
System.out.println(“Enter cost:”);
cost = ___________2________________
}
void calculate( )

{
if (cost <= 10000){
dis cost*5/100;
amount = cost – dis;
}
else if (cost > 10000 && cost < = 20000){
dis =_________________3_________

amount cost – dis;


}
else if (cost > 20000 && cost < = 35000){
dis = cost* 15/100;
amount = cost – dis;
}
else __________________4______________

{
dis = cost*20/100;
amount = cost – dis;
}
}
void display( )

{
System.out.println(“Name : ” +name);
System.out.println(“Mobile No : ” +____________5_________);
System.out.println(“Amount : ” +amount);
}
public static void main(String args( ))

{
_____________________6________________________
ob.input( );
ob.calculate( );
ob.display( );
}
}

1.
a) ShowRoom( )
b) ShowRoom( );
c) showroom ( )
d) showroom ( );
2.
a) sc.nextLong();
b) sc.nextDouble();
c) sc.nextInt();
d) sc.next();
3.
a) cost* 10/100;
b) cost*5/100;
c) cost*15/100;
d) cost *20/100;

4. a) if (cost > 35000)


b) if (cost >= 35000)
c) if (cost < 35000)
d) if (cost <= 35000)

5. a) Mobno
b) mobno
c) MobNo
d) MOBNO

6. a) ShowRoom ( ) ob = new ShowRoom( );


b) ShowRoom new = ob ShowRoom( );
c) ShowRoom ob = new ShowRoom( );
d) ShowRoom obj = new ShowRoom( );

Question 8

Write a program to input a number. Display the product of the successors of even digits of the
number entered by user.
Input: 2745
Output: 15
[Hint: The even digits are: 2 and 4
The product of successor of even digits is: 3*5= 15] [6]

import java.util.Scanner;
public class evensuccessor
{
public static void main()
{
Scanner in = new Scanner(System.in);
System.out.print("Enter the number: ");
int num = in.nextInt();
int orgNum = ___________1__________;
int prod = ____________2_____________;

while (num != 0)
{
int digit = num % 10;
num /= 10;

if (________3_________)
prod = ________4_________
}

if (______________5_________)

System.out.println("No even digits in " + orgNum);


else
System.out.println("Product of even digits successors is " + _________6_______);
}
}

1.
a) num
b) Num
c) Num;
d) num;
2.
a) 0
b) 1
c) -1
d) None
3.
a) digit % 2 = = 0
b) digit / 2= =0
c) digit%2! = 0
d) digit /2! =0
4.
a) prod * (digit *1);
b) prod * (digit+ 1);
c) prod +(digit + 1);
d) prod * (digit - 1);
5.
a) prod = = 1
b) prod = 1
c) prod = = 1;
d) prod= =0
6.
a) Orgnum
b) prod
c) num
d) none

Question 9
Design a class to find the factorial of a number. [4]

import java.io.*;
class fact
{
void _________1_________(int n)
{
int i;
int f=1;
for(i=1;i<=n;i++)
{
___________2__________
System.out.println("Factorial of "+n+"is="+f);
}
}
public static void main(__________3________)
{
fact nfactorial = new fact();
__________4________ factorial(x);
}
}

1.
a) factorial
b) Factorial
c)nFactorial

2.
a) f=f+i;
b) f=f*i;
c=f=f-i;

3.
a) int x;
b) int n;
c) int f;
4.
a) factorial .
b) factorial .
c)nfactorial .

Question 10
Read the paragraph given below and answer the questions given below: [4]
Case study

All modern programming languages provide ways for programmers to leave helpful notes,
reminders , or documentation within their source code. These reminders are known as comments.
Comments are not actually statements because they are skipped by the compiler and do not exist
at runtime.Although the compiler ignores comments, the software developer should not ignore
them. Java provides developers with three separate ways to add comments to their code. The
following symbol are used to denote comments in Java:
• / *……..*/ These delimiters are used to surround single or multiple line comments
• // This delimiter denotes a single line comment
• /**……….*/ comments used by Javadoc, a java documentation tool provided with the
Java Developer Kit (JDK) from Sun Microsystems.

1) What does the compiler do to the comments?

a) It processes them b) It ignores them c) It calculates them d) None of these

2) Which of the following is meant exclusively for single line comments?


a) /* ………*/ b) // c) /**……. */ d) All of these

3) What happens to comments in runtime?

a) They do not exist b) They are processed c) They are executed d) None of these

4) Which part of Java system uses the /** ………. */ system of making comments?

a) Any Java program b) The JRE c) The Javadoc d) The JDK

You might also like