Read the questions as text
This paper is divided into two sections. You are to answer all the questions from section A, and any four from section B.
SECTION A (40 Marks) Attempt all questions
Q A. 1. State the total size in bytes, of the arrays a[3] of char data type and p[7] of float data type. 2. What is a constructor? When is it invoked? 3. Write a statement to create an integer array called RollCall , of size 10.
4. Differentiate two kinds of data types? 5. What are wrapper classes? Give two examples?
Q B. 1. Identify (class name, object name, constructor and parameter from the following) Calculator obj=new Calculator(10,20); 2. Write an expression in java for A 2 -4B6 3. State the output when number=132.
void main(int number) { int a, b=number, c=0, d, s=0;
while (b!=0) {
d=b%10; a=(int)Math.pow(10,c++); System.out.println(d*a);
b=b/10; }
} 4. Write a java statement to check if the fourth element of an array arr[10] is divisible by 2. 5. Explain a literal. Q C. 1. What is the use of default in a switch? 2. What will be the output for the following program segment?
int a = 10,b=3,c=4; a= --b + c * a / 2;
System.out.print("a" + a);
System.out.print("b " +b );
3. What are the final values stored in x and y below?
double x=Math.abs(Math.min(-2.53,-5.75));
double y=Math.sqrt(Math.floor(16.2));
4. System.out.print("BEST "); System.out.println("OF LUCK"); Choose the correct option for the output of the above statements (i) BEST OF LUCK (ii) BEST OF LUCK
5. Write the return data type of the following function.
(i) startsWith()
(ii) random()
6. Give the output of the following:
(i)Math.floor (-4.7)
(ii)Math.ceil(3.4) + Math.pow(2, 3)
7. Convert the following if else if construct into switch case
if( var==1)
System.out.println("good");
else if(var==2)
System.out.println("better"); else if(var==3) System.out.println("best");
else System.out.println("invalid");
8. Give the output of the following string functions:
(i)"ACHIEVEMENT".replace('E', 'A')
(ii)"DEDICATE".compareTo("DEVOTE")
9. What will be the output of the following code?
int m=5;
int n=13; for(int i=1;i<=15;i++)
m++; --n; System.out.println("m="+m); System.out.println("n="+n); 10. Consider the following String array and give the output String arr[]= {"DELHI", "CHENNAI", "MUMBAI", "LUCKNOW", "UDAIPUR"}; System.out.println(arr[0].length()> arr[3].length()); System.out.print(arr[4].substring(0,4));
SECTION B (60 Marks) Attempt any four questions from this Section.
Question 4.
Design a class to overload a function series( ) as follows :
i) double series(double n) with one double argument and returns the sum of the series,
sum= 1/1 + 1/2 +1/3 + …. 1/n
ii) double series(double a, double n) with 2 double arguments and returns the sum of the series,
sum = 1/a2 + 4/a5 + 7/a8 + 10/a11+ …… to n terms
[15 ]
Question 5. Using the switch write a menu driven program to : i) To find and display all the factors of a number input by the user (including 1 and excluding the number itself). Example: Sample input : n = 15 Sample output : 1, 3, 5 ii) To find and display the factorial of a number input by the user ( the factorial of a non-negative integer n , denoted by n!, is the product of all integers less than or equal to n. Example: Sample input : n =5
Sample output : 5!=1x2x3x4x5=120
For an incorrect choice an appropriate error message should be displayed.
[15]
Question 6.
Write a program in Java to accept a string in lower case and change the first letter of every word
to upper case. Display the new string.
Sample input: we are in cyber world Sample output: We Are In Cyber World
[15]
Question 7.
Write a program to accept name and total marks of N number of students in two single array
name[ ] and totalmarks[ ].
Calculate and print:
(i) The average of the total marks obtained by N number of students. [average = (sum of
total marks of all the students)/N]
(ii) Deviation of each student’s total marks with the average. [deviation = total marks of a
student – average]
[15]
Question 8. 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.
Question 9.
A tech number has even number of digits. If the number is split in two equal halves, then the
square of sum of these halves is equal to the number itself. Write a program to generate and print
all four digit tech numbers. Example : 2025 is a tech number. 20+25=45
Square of 45 =2025
[15]