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

Question 1                                                                              [5X2=10]

 

  1. How is abstraction different from Encapsulation.
  2. i) Name the mathematical function which is used to find sine of an angle given in radians. ii) Name a string function which removes the blank spaces provided in the prefix and suffix of a string.
  3. What will this code print, choose from the given options?

int arr[]= new int[5];

System.out.println(arr);

  • 0       2. values stored in arr[0]             3.  0000              4. garbage value

4. Name the keyword which is used to resolve the conflict between method parameter and instance variables/fields.

5.State the package that contains the class:i) BufferedReader ii) Scanner

 

Question 2                                                                                     [5X2=10]

  1. Write statements for the following.                                                                             To create an object of class student with default constructor.                                         To invoke a method of class student i.e Grade_calculation(int x)
  2. What is the difference between literals and identifiers?
  3. What are tokens, name any four of them.
  4. Write any two differences in implicit & explicit type casting
  5. Write a main difference between while loop & do while loop

Question 3.                                                                                   [5X2=10]

  1. a) List the variables from those given below that are composite data types.

i) Static int x;    ii) arr[i]=10;                    iii) obj.display();       iv) Boolean b;

v) private char chr                            vi) String str;

  1. b) What are the final values stored in x and y below?

double a= -22.71;     double b= 99.29;

double x=Math.abs(Math.ceil(a));

double y=Math.rint(Math.max(a,b));

c) Rewrite the following program segment using while instead of for statement.

int f=1,i;

for(i=1;i<=5;i++)

{

f*=i;

System.out.println(f);

}

d) Name the data member of an Array class that stores the length of the array.

e) What is the difference between / and % operator?

Question 4.                                                                                 [5X2=10]

  1. Analyse the following program segment and determine how many times the loop will be executed and what will be the output of the program segment.

int k=1,i=2;

while(++i<6)

k*=i;

System.out.println(k);

2. State the output of the following program segment:

String str1=”java”;

String str2=”program”;

System.out.println(str1.substring(0,2).concat(str2.substring(1)));

System.out.println(“WH”+(str1.substring(2).toUpperCase())));

3. Write the output of the following program code:

char ch; int x= 97;

do

{

ch=(char)x;

System.out.print(ch + “ “);

if(x%10 = =0)

break;

++x;

}

while(x<=100);

4. Write the Java expressions for:

A5 +B3

——–

2AB

5. If int y=10 then find

int z=(++y * (y++ + 5));

Section B (60 marks) 

Attempt any 4 questions from this section

Each program should be written using a variable list so that the logic of the program is clearly depicted.

Question 5                                                                                [15] 

 

Write a menu driven program to perform the following . (Use switch-case statement)

(a)  To        print        the        series        0,        3,        8,        15,        24        …….        n        terms

(value of ‘n’ is to be an input by the user).

(b)       To find the sum of the series given below:

S =1/2+ 3/4 + 5/6 + 7/8 …….. +19/20

 

Question 6                                                                                                                  [15]

Write a program that has a method integerPower (base, exponent) that returns the value of base exponent.

For example, integerPower (4, 3) calculates 43 (or 4 * 4 * 4). Assume that exponent is a positive, nonzero integer and that base is an integer. The method should use a for or while loop to control the calculation. Do not use any math-library methods.

 

Question 7                                                                                                                   [15] 

 

Write a program to accept the year of graduation from school as an integer value from the user. Using the Binary Search technique on the sorted array of integers given below, output the message “Record exists” if the value input is located in the array. If not, output the message “Record does not exist”.

{1982,1987,1993,1996,1999,2003,2006,2007,2009,2010}

 

Question 8.                                                                                                                [15]

 

Write a program to input a number and print whether the number is a special number or not.  (A number is said to be a special number, if the sum of the factorial of the digits of the number is same as the original number).

Example: 145 is a special number, because 1! + 4! + 5! = 1 + 24 + 120 = 145(where ! stands for the factorial of the number and the factorial value of a number is the product of all integers from 1 to that number, example 5! = 1*2*3*4*5 = 120).

 


 

Question 9                                                                                                                      [15] 

 

Write a program to assign a full path and file name as given below. Using library functions, extract and output the file path, file name and file extension separately as shown.

Input C:\Users\Public\Pictures\Sample Pictures\Desert.jpg

Output Path: C:\Users\Public\Pictures\Sample Pictures\

File name: Desert

Extension: jpg

 

Question 10.                                                                                                                   [15] 

An airline announces discount on tickets depending upon destination chosen by the passenger from the following:

 

Destination Rate of ticket (per person)

 

America Rs. 50000.0
Singapore Rs. 20000.0
Japan Rs. 40000.0
Thailand Rs. 30000.0

 

The discount will be given as per the given criteria:

 

Ticket Amount Discount on Total amount
Above Rs. 200000 25%
Rs. 150001 to Rs. 200000 20%
Rs. 100001 to Rs. 150000 15%
Less than Rs. 100000 10%

 

Write a Java program to input name of the passenger/group head (in case of more than 1 passengers), number of passengers and destination code viz: A or a for America, S or s for Singapore, J or j for Japan, and T or t for Thailand.

 

Calculate the total ticket amount and discount amount. Find the net balance to be paid excluding the discount. Print name, number of passengers, destination code, discount and total ticket amount to be paid.

LEAVE A REPLY

Please enter your comment!
Please enter your name here