Computer Applications JML
Computer Applications JML
Computer Applications JML
JASUDBEN M. L. SCHOOL
AND BLOOMINGDALES PRE-PRIMARY
SectionA(40 Marks)
(Attempt all questions from this Section)
Question 1
Choose the correct answers to the questions from the given options.
(Do not copythe question, write the correct answers only.)
1 Name the feature of java depicted in the above picture. [1]
Class
Voriobies Methods
(a) Encapsulation
(b) Inheritance
(c) Abstraction
(d) Polymorphism
2. State the type of loop in the given program segment: [1)
for (int i =5; i!= 0; i-=2)
System.out.printin(i):
a) finite
b) infinite
c) null
d) fixed
3 Write a method prototype name check() which takes an integer argument and returns a [1]
char:
a) char check()
b) void check (int x)
c) check (int x)
d) char check (int x)
1
[1
4 int x = (int)32.8; is an example of .............. typecasting.
a) implicit
b) automatic
c) explicit
d) coercion
(a) Only 1.
(b)1. and 3.
(c) 2. and 4.
(d) 1. and 2.
14. For a two-dimensional array with Mrows and Ncolumns in Java, what will be the index of
the last element in the last row?
a) (M-1,N-1)
b) (M, N)
c) (M-1, N)
d) (M, N-1)
15. Assertion (A): Java supports the use of the ASCIl character set only.
Reason(R); Unicode can represent nearly all languages of the world like English, Hindi,
Bengali, Kannada, Arabic, Japanese, etc.
a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation
of Assertion (A).
b) Both Assertion (A) and Reason (R)are true but Reason (R) is not a correct
explanation of Assertion (A).
c) Assetion (A) is true and Reason (R) is false.
d) Assertion (A)is false and Reason (R) is true.
[1]
16. How many times will the followingcode print "Hello"?
for (int i= 1; i<=3; it+);
System.out.printin("Hello");
(a) o
(b) 1
(c) 3
(d) 2
17. Assertion (A): In Java, the keywords public, Public. and PUBLIC are treated as the
same.
Reason (R): Javais a case-sensitive language.
(a)Both Assertion (A)and Reason (R) are true and Reason (R)is a correct explanation
of Assertion (A).
(b) Both Assertion (A) and Reason (R)are true and Reason (R) 0s not a correct
explanation of Assertion (A)
(C) Assertion (A) is true and Reasorn (R) is false
(d) Assertion (A)is false and Reason (R) is true
18 Read the following text, and choose the correct answer [1]
Aclass encapsulate Data Members that contains the information necessary to
represent the class and Member methods that perform operations on the data memoel.
What does a class encapsulate?
(a) Only A
(b) Only C
(c) Allthe three
(d) Both A and C
Question No.2
(21
1. Write the Java expression for x=Jy
statement: (21
2. Rewrite the following code using a single if
if (grade =='A)
System.out.println("Excellent");
else if (grade == 'a')
System.out.println("Excellent"):
else if (grade =='B')
System.out.println("Good");
else if (grade == 'b')
System.out.printin("Good");
respectively.
values of x and y are 5 and 7,
3. Evaluate the given expression when the
y += X-- * ++y -+x,
System.out.printin("x="+x);
System.out.println("'y ="+ y);
4
4 Stuuellexecues the following program segment and encounters an error. ldentify the 2]
Statement which has an error. and correct the code to get the output as "SUCCESS".
char x='A;
switch(x) {
case 'B': System.out.println("SUCCESS");
case 'A': System.out. println("FAIL"),
5. Consider the following code snippet. Determine how many times the loop will execute (2]
and write the output of the code:
int z = 20;
while (true) {
System.out.printin(z- 5);
if (z % 7 == 0){
break;
Z +=3:
6. When there is no explicit initialization, what are the default values set for variables in the [21
following cases?
(a) Integer variable
(b) String variable
7. Predict the output of the following code snippet: [2]
char ch = 'M:
ch = Character.tolLowerCase(ch);
int n = (int) ch + 5;
System.out.println(char) n +"t" +ch);
A student is trying to convert a stringpresent in str tO a numerical value so that they can [21
compute the cube of the converted value. However, the code has an error. Name the
error (syntax / logical / runtime). Correct the code so that it compiles and runs correcty.
String str = "64":
int num = Integer.parselnt(str):
int result = Math.pow(num,3);
system.out.println(result);
9. Consider the following program segment and answer the questions below:
class calculate {
int a;
double b;
calculate()
a=0;
b=0.0:
}
calculate(int x, double y\.
a=x;
b=y;
void sum(X
System.out.printin(a'b);:}}
Name the type of constructors used in the above program segment.
10. Consider the following program segment and answer the questions given below: (21
int x[]0 ={2,4,5,6}, {5,7,8,1), (34, 1,10, 93):
(a)What is the position of 34?
(b)What is the result of x[2][3] + x[1I212
SECTION B
(Answer any four questions from this Section.)
The ansWers in this section should consist of the progrems in either
BlueJ environien
or any
program environment with java as the base.
Each program should be written using variable
description / mnemonic codes so iat to
logic of the
program is clearly depicted.
Flowcharts and algorithms are not required
Question 3
(15]
Define aclass with the following
specifications:
Class name: Bank
Member variables:
double p - stores the principal amount
double n - stores the time period in years
double r- stores the rate of interest
double a- stores the amount
member methods:
Void accept () - input values for p and n using Scanner class methods only.
void calculate () -calculate the amount based on the following conditions:
a=p(1+100
void display () - display the details in the given format.
Write the main method to create an object and call the above methods.
Question 4: [15]
below.
Define a class to search for a value input by the user from the list of values given
If it is found display the message "Search successful", otherwise display the message
"Search element not found" using Binary search technique.
Output:
sum of row 1= 10 (1+2+3+4)
sum of row 2 = 26 (5+6+7+8)
sum of row 3= 16 (1+3+5+7)
sum of row 4= 11 (2+5+3+1)
Question7
Define aclass to accept a number andcheck whether it is a SUPERSPY number or not.
A number is called SUPERSPY if the sum of the digits equals the number of the digits.
Example: Input: 1021
Output: SUPERSPY number
SUM OF THE DIGITS = 1+0+2+1 =4, NUMBER OF DIGITS =4]
Example2: Input: 125
Output: Not a SUPERSPY number
[SUM OF THE DIGITS = 1+2+5 =8, NUMBER OF DIGITS =3, Does not match with sum
of digits]
Question 8:
Define a class to overload the method display as follows:
void display(int n): Toprint the square root of each digit of the given number
Example: n=4329
output-3.0
1.414213562
1.732050808
2.0
****** *********