Computer (A I) New
Computer (A I) New
Worksheet-1
SECTION A
Question 1
1. Name the characteristics of Object Oriented Programming that hides the complexity and provides a
simple interface.
a. Encapsulation b. Polymorphism c. Abstraction d. Inheritance
5. If the name of a class is ‘Number’, what can be the possible name for its constructor?
a. number b. Number c. No d. No
9. What package is a part of the wrapper class which is imported by default into all Java programs?
a. java.util b. java.lang c. java.awt d. None of these
10. The output of the method “Computer Application”. substring (2,8) is:
a. Application b. Computer c. puter A d. mputer
11. A wrapper class converts-
12. A string is –
a. Wrapper Class b. Data Type c. Group of characters d. All of the above 13. To
remove extra spaces from both sides of string, the functions used is_______
a. truncate () b. replace () c. trim () d. remove ()
14. The minimum number of parameters required for the function substring () is:
a. 2 b. 1 c. 0 d. 3
15. We can create a composite user defined data type using:
a. A Class Definition b. An Integer Definition
c. A Boolean Definition d. A String Definition’
16. To extract a character at index ‘n’ from a string ‘mystr’, the statement will be_______
a. mystr.charAt(n) b. mystr.indexOf(n) c. mystr.charOf(n) d. mystr.indexAt(n) 17.
By using you can force immediate termination of loop, bypassing the conditional expression and
any remaining code in the body of the loop.
a. switch b. break c. continue d. default
18. A type of parameter that are used to identify what data is to be passed to a function is called:
a. Formal parameter b. Actual parameter c. Both a and b d. None of these
19. Math.pow (625,1/2) +Math.sqrt(144)
a. 17.0 b. 13.0 c. 37.0 d. 13
20. Which among the following is a logical error?
a. Missing semicolon b. Mismatched braces in classes and methods.
c. Misspelled keywords and identifiers. d. Addition is required but subtraction is performed.
Question 2
(i) Give the output of the following expression:
a+=a++ + ++a + --a + a--; when a=7.
(ii) Write java expression for-
System.out.print(“ODD”);
(iv) Convert the following while loop to the corresponding for loop:
int m = 5, n = 10; while (n>=1)
{
System.out.println(m*n); n-
-;
}
(v) Analyze the given program segment and answer the following questions:
for(int i=3;i<=4;++)
{
System.out.println (“WIN”);
}
i. How many times does the inner loop execute?
ii. Write the output of the program segment.
(vi) Give the output of the following string functions:
“ACHIEVEMENT”.replace(‘E’,‘A’).toLowerCase()
(vii) Write the output for the following:
String s= “Today is Test”;
System.out.println(s.indexOf(‘T’));
(viii) Define Unboxing with an example (ix)
In the program given below:
class MyClass
{
static int x = 7;
int y = 2;
public static void main(String args[ ])
{
MyClass obj = new MyClass();
System.out.println(x);
obj.sampleMethod(5); int
a= 6;
System.out.println(a);
}
void sampleMethod(int n)
{
System.out.println(n);
System.out.println(y);
}
}
State the name of the following-:
(x) Write the function prototype for the function “sum” that takes an integer variable (x) as its
argument and returns a value of float data type.
SECTION B
Question 4
A cloth showroom has announced the following festival discounts on the purchase of items, based
on the total cost of the items purchased:
Total Cost Discount (in Percentage)
Less than ₹ 2000 5%
₹ 2001 to ₹ 5000 25%
₹ 5001 to ₹ 10000 35%
Above ₹ 10000 50%
Write a program to input the total cost and compute and display the amount to be paid by the
customer after availing the discount.
Question 5
Write a program to input a sentence and count the number of vowels and consonants in it.
Question 6
Create a class SalaryCalculation that is described as below:
Class Name : SalaryCalculation Data
members : name (String type data)
basicPay, specialAlw, conveyanceAlw, gross, pf, netSalary AnnualSal (All double type data)
Member methods :
i. SalaryCalculation( ) - A constructor to assign name of employee (name), basic salary
(basicPay) of your choice and conveyance allowance
Write a program in Java to calculate all the details mentioned above and print them all.
Question 7
Write a program to input a string and print out the text with the uppercase and lowercase letters reversed, but all
other character remains the same as before. Example: Input- ComPuteR aPPliCatiOn
Output- cOMpTEr AppLIcATIoN
Question 8
Write a menu driven program to perform the following task according to users choice: a)
Print the following series: 0,7,26,63…. N terms.
b) Print the sum of the following series: 1/1!-2/4!+3/9!-4/16!..n terms