0% found this document useful (0 votes)
30 views7 pages

Computer Application

The document contains a series of programming questions and tasks related to Java, including multiple-choice questions, coding exercises, and problem-solving scenarios. It covers topics such as arrays, object-oriented programming concepts, control structures, and string manipulation. Additionally, it includes practical programming tasks such as creating classes, implementing functions, and using switch statements for pattern generation.

Uploaded by

Pritam Sen
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)
30 views7 pages

Computer Application

The document contains a series of programming questions and tasks related to Java, including multiple-choice questions, coding exercises, and problem-solving scenarios. It covers topics such as arrays, object-oriented programming concepts, control structures, and string manipulation. Additionally, it includes practical programming tasks such as creating classes, implementing functions, and using switch statements for pattern generation.

Uploaded by

Pritam Sen
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

SECTION A

Attempt all questions from this part.

QUESTION 1.
Choose the correct answer and write the correct option.
(Do not copy the question, write the correct answers only.)

(i) What will this code produce as output?


int a[] = {2, 4, 6, 8, 10};

a[0] = 23;
a[3] = a[1];
int c = a[0] + a[1];
[Link]("Sum = " + c);
(a) 26
(b) 23
(c) 25
(d) 27

(ii) The process of binding the data and method together as one unit is called as
(a) Dynamic binding
(b) Inheritance
(c) Polymorphism
(d) Encapsulation

(iii) A collection of classes is known as a _______.


(a) Package
(b) Function
(c) Method
(d) Wrapper class

(iv) What is the return type of the following function?


is Letter or Digit (char)
(a) String
(b) Char
(c) Integer
(d) Boolean

(v) What will the following code output?


String str = "Computer Applications" + 1 + 0;
[Link]("Understanding " + str);
(a) Understanding Computer Applications 10
(b) Understanding Computer Applications 20
(c) Understanding Computer Application 10
(d) Error

(vi) What is the output of the following code?


String s1 = "welcome";
String s2 = "island";
[Link]([Link](0).concat([Link](2)));
[Link]([Link]());
(a) Welcome-land ISLAND
(b) Welcome Land Island
(c) WELCOME LAND
(d) Welcome land ISLAND Island

(vii) This term refers to the name assigned to a package, class, interface, method, or variable.
(a) Keyword
(b) Token
(c) Literal
(d) Identifier

(viii) These constructors require parameters to be provided when creating objects.


(a) Copy
(b) Default
(c) Parameterized
(d) None of the above

(ix)
int code[ ] = {25, 37, 38, 42};
The given statement
(a) assigns 37 to code [1]
(b) assigns 25 to code [1]
(c) assigns 38 to code [3]
(d) assigns 42 to code [0]

(x) The automatic conversion of a primitive data type into an object of its corresponding
wrapper class is called:
(a) auto-boxing
(b) explicit conversion
(c) shifting
(d) None of the above

(xi) The parseInt() function is a member of


(a) integer wrapper class
(b) character wrapper class
(c) boolean wrapper class
(d) None of these

(xv) Classes that inherit from Runtime-exception are referred to as:


(a) Checked exceptions
(b) Unchecked exceptions
(c) Impure exceptions
(d) Static exceptions

(xvi) Which of the following are invoked directly when an object is created?
(a) Methods
(b) Arrays
(c) Constructors
(d) Strings

(xvii) Assertion (A): Array is a data type which can store multiple homogeneous variables.
Reason (R): Elements of an array are stored in an indexed manner starting with index 0.
(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) is not a correct explanation of
Assertion (A).
(c) Assertion (A) is true and Reason (R) is false.
(d) Assertion (A) is false and Reason (R) is true.

(xviii) Read the following text and choose the correct answer.
Abstraction is a key concept in Object-Oriented Programming (OOP) that focuses on
representing essential features while omitting unnecessary background details or
explanations.
What is an abstraction?
(a) Abstraction is more about ‘What’ a class can do.
(b) Abstraction is more about ‘How’ to achieve that functionality.
(c) It binds data and methods in a single unit.
(d) It implements using private access modifier.

(xix) Assertion (A): The factory of object means a factory that produces the objects.
Reason (R): Class is known as an object factory because a single class generates a lot of
objects.
(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) is not a correct explanation of
Assertion (A).
(c) Assertion (A) is true and Reason (R) is false.
(d) Assertion (A) is false and Reason (R) is true.

(xx) Which of the following statements is incorrect?


(a) Array can be initialized when they are declared.
(b) Array can be initialized using ‘comma’ separated expressions surrounded by curly braces.
(c) It is necessary to use ‘new’ operator to initialize an array.
(d) None of the above

QUESTION 2.

(i) If int a[] = {7, 3, 4, 8, 9, 2}; what are the values of x and y?
(a) x = a[1] * a[0] + a[3]
(b) y = [Link]
(ii) Determine the values of n and m after executing the following code:
int m;
int n;
m = 5;
n = (5 * ++m) % 3;
[Link]("n=" + n + " m=" + m);
(iii) Identify the keyword that:
(a) Indicates an error has occurred during an input/output operation.
(b) Differentiates between an instance variable and a class variable.

(iv) What will be the outcome of the following statements?


int a = 3;
[Link]("-" + (1 + a));
[Link]("-" + 1 + a);

(v) Name the primitive data type in Java that is a 64-bit integer and is used when you need a
range of values under than those provided by int.

(vi) Give the prototype of a function search, which receives a sentence sntc and a word wrd and
returns 1 or 0.

vii) Determine the output of the following code:


String str = "I Love My Family";

[Link]([Link]([Link]()));
[Link]([Link](12));
(viii) Write a Java statement for the following mathematical expression:

V=13πr2hV=31πr2h

(ix) What will be the output of the following expressions?


(a) [Link](3.4, 2) + 2 * [Link](64)
(b) [Link](3.4) + 2 * [Link](3.4) + 2

(x) How many times will the loop in the following code execute?

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

SECTION B
Attempt any four questions from this section.

QUESTION 3

Write a program in Java which prints Fibonacci series using arrays.

QUESTION 4
Rahul Transport Company charges customers for parcel deliveries based on the following
specifications:

Class name Atransport


Member
variables
String name to store the name of the customer
int w to store the weight of the parcel in Kg
int charge to store the charge of the parcel
Member
functions
to accept the name of the customer, weight of the parcel from the user
void accept()
(using Scanner class)
To calculate the charge as per the weight of the parcel as per the following
void calculate()
criteria:

Weight in Kg → Charge per Kg

• Up to 10 Kgs → Rs. 25 per Kg


• Next 20 Kgs → Rs. 20 per Kg
• Above 30 Kgs → Rs. 10 per Kg

A surcharge of 5% is charged on the bill.

void to print the name of the customer, weight of the parcel, total bill inclusive of
print() surcharge in a tabular form in the following format:
Name Weight

Define a class with the above-mentioned specifications, create the main method, create an
object, and invoke the member methods.
QUESTION 5
Use a switch statement to draw the following patterns:

(i)
ABCDEDCBA

ABCDCBA

ABCBA

ABA

(ii)
1
21

321

4321

54321

QUESTION 6
Using the switch statement, write a menu-driven program for the following:

(i)
1

12

123

1234

12345

(ii)
B

BL

BLU

BLUE

QUESTION 7

A showroom offers the following discounts based on the total cost of items purchased:

Total Cost Discount Item

Less than or up to Rs. 1000 3% Teapot

Rs. 1001 to Rs. 3000 5% Dinner set

Rs. 3001 to Rs. 5000 10% Plate

More than Rs. 5000 15% Rack


Write a program to input the total cost of the item purchased, discount, and the amount to be
paid after availing the discount.

QUESTION 8

Write a Java program to display the pattern of the string entered by the user. There are two
choices: F and L.

• If the user chooses F, then the first character of each word is displayed.
• If the user chooses L, then the last character of each word is displayed.

Sample Input:

HELLO WONDERS WORLD

Output:
Choose F Choose L

H O

W S

W D

You might also like