Professional Documents
Culture Documents
General Instructions :
Question 1.
(a) Name any two basic principles of Object-oriented
Programming.
(b) Write a difference between unary and binary
operator.
(c) Name the keyword which :
(i) indicates that a method has no return type.
(ii) makes the variable as a class variable.
(d) Write the memory capacity (storage size) of short
and float data type in bytes.
(e) Identify and name the following tokens :
(i) public
(ii) ‘a’
(iii) ==
(iv) {}
Solution.
(a) Abstraction and encapsulation are the basic
principles of Object-oriented Programming.
(b)
Unary Operators
(i) The operators which act upon a single operand (i) The op
(c)
(i) void
(ii) static
Question 2.
(a) Differentiate between if else if and switch-case
statements. [2]
(b) Give the output of the following code : [2]
String P = “20”, Q = “19”,
int a = Integer .parselnt(P);
int b = Integer. valueOf(Q);
System.out.println(a+””+b);
(c) What are the various types of errors in Java ? [2]
(d) State the data type and value of res after the
following is executed : [2]
char ch = ‘9’;
res = Character. isDigit(ch) ;
(e) What is the difference between the linear search
and the binary search technique? [2]
Solution.
(a)
if else if
(b) 2019
(c) Syntax error, Runtime error, Logical error
(d) boolean
True
(e)
Linear Search
(i) Linear search works both for sorted and unsorted (i) Binary
data. ascendin
(ii) Linear search begins at the start of an array i.e. (ii) This t
Question 3.
(a) Write a Java expression for the following : [2]
|x2+2xy|
(b) Write the return data type of the following
functions : [2]
(i) startsWith( )
(ii) random( )
(r) If the value of basic=1500, what will be the value
of tax after the following statement is executed? [2]
tax = basic > 1200 ? 200 : 100;
id) Give the output of following code and mention
how many times the loop will execute ? [2]
int i;
for(i=5; i> =l;i~)
{
if(i%2 ==1)
continue;
System.out.print(i+ ”
}
(e) State a difference between call by value and call
by reference. [2]
(f) Give the output of the following: [2]
Math.sqrt(Math.max(9, 16))
(g) Write the output for the following: [2]
String s1 = “phoenix”; String s2 =”island”;
System.out.prindn (s1.substring(0).concat
(s2.substring(2)));
System.out.println(s2.toUpperCase( ));
(h) Evaluate the following expression if the value
ofx=2,y=3 and z=1. [2]
v=x+–z+y+ + +y
(i) String x[ ] = {“Artificial intelligence”, “IOT”,
“Machine learning”, “Big data”}; [2]
Give the output of the following statements:
(i) System.out.prindn(x[3]);
(ii) System.out.prindn(x.length);
(j) What is meant by a package? Give an example.
[2]
Solution.
(a) Math.abs((x * x) + (2 * x * y);
(b) (i) boolean
(ii) double
(c) 200
(d) 4 2
Loop will execute 5 times.
(e)
Call by Value
(i) In call by value the method creates its new set of (i) In call
(ii) Any change made in the formal parameter is not (ii) Any c
(iii) Refer
(iii) Primitive data types are passed by call by value.
passed b
(f) 4.0
(g) phoenix land
ISLAND
(h) = 2 + 0 + 3 + 4
(i) (i) Big data
(ii) 4
(j) A package is an organized collection of classes
which is included in the program as per
the requirement of the program. For example java.io
package is included for input and output operations
in a program.
Question 4.
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
Question 5.
Using the switch-case statement, write a menu
driven program to do the following : [15]
(a) To generate and print Letters from A to Z and
their Unicode Letters Unicode
Question 6.
Write a program to input 15 integer elements in an
array and sort them in ascending order using the
bubble sort technique. [15]
Solution.
import java.io.*;
import java.util’*;
class AscendingOrder {
public static void main(String args[]) {
int i, j, temp;
Scanner sc = new Scanner(System.in);
int arr[] = new int[15];
System.out.println(“Enter 15 integers:”);
for (i = 0; i < = 15; i+ +) {
arr[i] = sc.nextlntO;
for(i = 0; i < 14; i++){
for(j = 0; j < 14 -i; j + +){
if(arr[j] > arr[j + 1]){
temp = arr[j];
arr[j] = arr [j + 1];
arr[j + 1] = temp;
}
}
}
System.out.println(“Elements in ascending order
are::”);
for (i = 0; i < 15; i+ +) {
System.out.println(arr[i]);
}
}
}
}
Question 7.
Design a class to overload a function series() as
follows: [15]
(a) void series (int x, int n) – To display the sum of
the series given below:
x1 + x2 + x3 + ……………. xn terms
(b) void series (int p) – To display the following
series:
0, 7, 26, 63 p terms.
(c) void series () – To display the sum of the series
given below:
Solution.
import java.io.*;
import java.util.*;
class OverloadSeries {
void series( int x, int n) {
int i; .
double a;
double sum = 0;
for (i = 1; i < = n; i++) {
a = Math.pow(x, i);
sum = sum + a;
}
System.out.prindn(“Sum::” +sum)r
}
void series(int p) {
int i;
for (i = 1; i < = p; i++) {
System.out.prindn((i * i * i) – 1 + ” “);
}
}
void series() {
double i;
double s = 0;
for (i =-2; i < = 10; i+ +) {
s = s + 1/i;
}
System.out.println(“Sum:” +s);
}
}
Question 8.
Write a program to input a sentence and convert it
into uppercase and count and display the total
number of words starting with a letter ‘A’. [15]
Example:
Sample Input: ADVANCEMENT AND APPLICATION
OF INFORMATION TECHNOLOGY ARE EVER
CHANGING.
Sample Output : Total number of words starting with
letter A’ = 4.
Solution.
import java.io.*;
import java.util.*;
class UpperCount {
public static void main(String args[ ]) {
int i, a;
Scanner sc = new Scanner(System.in);
String str, str1, str2;
System.out.prindn(“Enter sentence::”);
str = sc.nextLine();
strl = str.toUpperCaseO; ‘
str2 = “” + strl;
a = 0; ,
for (i = 0; i < = str2.1ength(); i+ +) {
if(str2.charAt(i) == ‘ ‘)
if(str2.charAt(i + 1) == ‘A’);
a+ +;
}
System.out.println(“Total number of words starting
with letter ‘A’::” +a);
}
}
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. [15]
Example :
Consider the number 3025
Square of sum of the halves of 3025 = (30+25)2
= (55)2
= 3025 is a tech number.
Solution.
import java.io.*;
import java.util.*;
class TechNumber {
public static void main(String args[ ]) {
int i, a, b, sum;
String n;
System.out.println(“Four Digits Tech Numbers
are::”);
for(i = 1000; i < 1000; i+ +) {
n = i +””;
a = lnteger,parselnt(n.substring(0, 2));
b = Integer.parselnt(n.substring(2));
sum = (int)Math.pow((a + b), 2);
if (sum == i)
System.out.println(i);
}
}
}
General Instructions:
Question 1.
(a) Define abstraction.
(b) Differentiate between searching and sorting.
(c) Write a difference between the functions
isUpperCase( ) and toUpperCase( ).
(d) How are private members of a class different
from public members ?
(e) Classify the following as primitive or non-primitive
data types :
(i) char
(ii) arrays
(iii) int
(iv) classes
Solution:
(a) Abstraction is a process of hiding the
implementation details and showing only
functionality to the user.
(b) Searching is a technique which is used to search
a particular element in an array or string. Sorting is a
technique which is used to rearrange the elements
of an array or string in a particular order either
ascending or descending.
(c) The isUpperCase( ) method is used to check
whether the given character is in upper case or not.
It returns Boolean data type.
The toUpperCase( ) method is used to convert a
character or string into upper case. It returns char or
String type. •
(d) Scope of the private members is within the class
whereas scope of the public members is global.
(e) (i) char is primitive data type.
(ii) arrays are non-primitive data type.
(iii) int is primitive data type.
(iv) classes are non-primitive data type.
Question 2.
(a) (i) int res = ‘A’; [2]
What is the value of res ?
(ii) Name the package that contains wrapper
classes.
(b) State the difference between while and do while
loop. [2]
(r) System.out.print(“BEST”); |2]
System.out.println(“OF LUCK”);
Choose the correct option for the output of the
above statements
(i) BEST OF LUCK
(ii) BEST
OF LUCK
(d) Write the prototype of a function check which
takes an integer as an argument and returns a
character. [2]
(e) Write the return data type of the following
function. [2]
(i) endsWith( )
(ii) log( )
Solution:
(a) (i) Value of res is 65.
(ii) Java.lang
(b)
Question 3.
(a) Write a Java expression for the following :
Question 4.
Design a class Railway Ticket with following
description : [15]
Instance variables/s data members :
String name : To store the name of the customer
String coach : To store the type of coach customer
wants to travel
long mobno : To store customer’s mobile number
int amt : To store basic amount of ticket
int totalamt : To store the amount to be paid after
updating the original amount
Member methods
void accept ( ) — To take input for name, coach,
mobile number and amount
void update ( )— To update the amount as per the
coach selected
Type of Coaches
First_ AC
Second_AC
Third _AC
sleeper
Question 5.
Write a program to input a number and check and
print whether it is a Pronic number [15] or not.
(Pronic number is the number which is the product
of two consecutive integers)
Examples : 12 = 3 × 4 .
20 = 4 × 5
42 = 6 × 7
Solution:
import java.io.*;
import java.util. Scanner;
class Pronic]
public static void main(String argsQ) throws
IOException {
Scanner sc = new Scanner(System.in);
System.out.print(“Enter the number: “);
int n = sc.nextlnt();
int i = 0;
while(i * (i + 1) < n) {
i++;
}
if(i *(i + 1) = = n){
System.out.println(n + ” is a Pronic Number.”);
}
else {
System.out.prindn(n + ” is not a Pronic Number.”);
}
}
}
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. [15]
Sample input: we are in cyber world
Sample output : We Are In Cyber World
Solution:
import java.io.*;
import java.util.Scanner;
class ChangeLetter {
public static void main(String args[ ]) throws
IOException {
Scanner sc = new Scanner(System.in);
System.out.print(“Enter String in lowercase:”);
String str 1 = sc.next( );
strl = “” +strl;
String str2 = ” “:
for (int i = 0; i<strl.length( ); i+ +) {
if(strl ,charAt(i) = = “) {
str2 = str2 + ” +Character.
toUpperCase(strl.charAt(i+l));
i+ + ;
}.
else
str2= str2 + strl.charAt(i);
}
System.out.println(str2.trim( ));
}
}
Question 7.
Design a class to overload a function volume() as
follows : [15]
(i) double volume (double R) — with radius (R) as an
argument, returns the volume of sphere using the
formula.
V = 4/3 × 22/7 × R3
(ii) double volume (double H, double R) – with
height(H) and radius(R) as the arguments, returns
the volume of a cylinder using the formula.
V = 22/7 × R2 × H
(iii) double volume (double L, double B, double H) –
with length(L), breadth(B) and Height(H) as the
arguments, returns the volume of a cuboid using the
formula.
Solution:
class ShapesVolume {
public static double volume (double R) {
double V = 4.0 / 3, * 22.0 / 7 * Math.pow(R, 3);
return V;
}
public static double volume(double H, double R) {
double V = 22.0 / 7 * R * R * H ;
return V;
}
public static double volume (double L, double B,
double H) {
double V = L * B * H;
return V;
}
}
Question 8.
Write a menu driven program to display the pattern
as per user’s choice. [15]
For an incorrect option, an appropriate error
message should be displayed.
Solution:
import java.io.*;
import java.util.Scanner;
class Pattern {
public static void main(String args[]) throws
IOException {
Scanner sc = new Scanner(System.in);
System.out.println(“::::MENU::::”)
System.out.println(” 1. To display ABCD Pattern”);
System.out.print(” 2. To display Word Pattern”);
System.out.print(“Enter your choice:”);
int ch= sc.nextlnt();
switch(ch) {
case 1:
for (char i = ‘E’; i > = ‘A’; i- -){
for(char j = ‘A’;j <=i;j + +){
System.out.print(j);
}
System.out.prindn( );
}
break;
case 2:
String S = “BLUE”;
for (int i = 0; i < S.length(); i+ +) {
for(int j = 0; j < =i; j + +) {
System.out.print(S.charAt(i));
}
System.out.println();
}
break;
default:
System.out.println(“Invalid Input”);
break;
}
}
}
Question 9.
Write a program to accept name and total marks of
N number of students in two single subscript array
name[] and totalmarks[ ]. [15]
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] ‘
Solution:
import java.io.*;
import java. util. Scanner;
class NameMarks {
public static void main(String argsO) throws
IOException {
Scanner sc = new Scanner(System.in);
System.out.print(“Enter number of students:”);
int N = sc.nextlnt( );
String named = new String[N];
int totalmarksG = new int[N];
double deviation[ ] = new double[N];
double sum = 0;
for (int i = 0; i < N; i+ +) {
System.out.print(“Enter Name of the Student:”);
name[i] = sc.next( );
System.out.print(“Enter Marks:”);
totalmarks[i] = sc.nextlntO;
sum = sum + totalmarks [i];
}
double average = sum / N;
System.out.println(“The average of the total marks of
” +N+” number of students:” +average);
for (int i = 0; i < N; i+ +) {
deviadon[i] = total marks (i] – average;
System.out.println(“Deviation of” + name[i] + “s
marks with the average:” +deviation[i]);
}
}
}
General Instructions:
Question 1.
(a) What is inheritance ? [2]
(b) Name the operators listed below r [2]
(0 <
(it) + +
(iii) &&
(iv) ? :
(c) State the number of bytes occupied by char and
int data types. [2]
(d) Write one difference between / and % operator.
[2]
(e) String x[ ] = {“SAMSUNG”, “NOKIA”, “SONY”,
“MICROMAX”, “BLACKBERRY”}; [2]
Give the output of the following statements :
(i) System.out.prindn(x[1]);
(ii) System.out.println(x[3].length{ )); ,
Answers:
(a) Inheritance in java is a mechanism in which one
object acquires all the. properties and behaviors of
parent object.
The idea behind inheritance in java is that you can
create new classes that are built upon existing
classes. When you inherit from an existing class,
you can reuse methods ‘and fields of parent class,
and you can add new methods and fields also.
Question 2.
(a) Name the following : [2]
(i) A keyword used to call a package in the program.
(ii) Any one reference data type.
(b) What are the two ways of invoking functions? [2]
(c) State the data type and value of res after the
following is executed: [2]
char ch = ‘t’;
res=Character. toUpperCase(ch);
(d) Give the output of the following program segment
and also mention the number of times
the loop is executed: [2]
int a,b;
for (a=6, b=4; a< =24; a=a + 6)
{
if (a%b= =0)
break;
}
System, out .println(a);
Answers:
(a) (i) import
(ii) Array
(b) By Value and By Reference
(c) int type and value is 84.
(d) Output is 12. Twice.
In the loop : for (a = 6, b=4; a< =24; a = a+6), the
value of a will be
incrementing as 6, 24 and upon incrementing the
value to 42, the loop will terminate. Accordingly the
loop has to execute two times.
But within the loop there is a condition : if(a%b = =0)
break;
This means when remainder on dividing a by b
comes out to be 0 (at 24/4 = 0), the condition breaks
and from the above it is clear that value of a is
incremented from 6 to 24 when the loop executes
second time.
(e) 75 F
Question 3.
(a) Write a Java expression for the following : [2]
ax5 + bx3 + c
(b) What is the value of xl if x=5 ? [2]
x1 = + +x – X+ + + –x
(c) Why is an object called an instance of a class ?
[2]
(d) Convert following do-while loop into for loop. [2]
int i = 1;
int d = 5;
do {
d=d*2;
System.out.println(d);
i+ + ; } while (i< =5);
(e) Differentiate between constructor and function.
[2]
(f) 0
Today i Holiday
(g) r1 = 5.83 .
r2 = 4.0
(h) Result 1 = 26100200
Result 2 = 126
(i) (i) Once
(ii) WIN
WIN
Question 5.
Write a program to accept a number and check and
display whether it is a spy number or not. (A number
is spy if the sum of its digits equals the product of its
digits.) [15]
Example : consider the number 1124,
Sum of the digits = l + l+ 2 + 4 = 8
Product of the digits = 1×1 x2x4 = 8
Answer:
class Spy {
public static void main(int n) {
int sum = 0;
int multiple = 1;
int a;
int p = n;
// a stores each digit extracted and p creates a
backup of input.
while(n ! = 0) {
a = n % 10; ,
sum = sum + a;
multiple = multiple * a;
n = n/10;
}
System.out.println(“The sum of ” +p +” is ”+sum);
System.out.println(“The product of “+p +” is ” +
multiple);
if(sum = = multiple) {
System.out.println(“Aha, ” + “It is a Spy Number
Where Sum = Product”);
}
else {
System.out.println(” It is NOT a Spy Number Where
Sum ft Product”);
}
}
}
Question 6.
Using switch statement, write a menu driven
program for the following : [15]
(i) To find and display the sum of the series given
below :
S = x1 -x2 + x2 – x4 + x5 – x20
(where x = 2)
(ii) To display the following series :
1 11 111 1111 11111
For an incorrect option, an appropriate error
message should be displayed.
Answer:
import java.io.*;
class SwitchStatement {
public static void main(String argsQ) throws
IOException {
InputStreamReader reader = new
InputStreamReader(System.in);
BufferedReader input = new
BufferedReader(reader);
System.out.println(“l-Sum of Series:”);
System.out.println(“2-Display Special Series:”);
System.out.println(“Enter your choice:”);
String n1 = input.readLine( );
int ch = Integer.parselnt(nl);
System.out.println(“Enter Number of Terms
String t = input.readLine();
int n = Integer.parselnt(t);
switch (ch) {
case 1:
int sign = -1;
double term = 0;
double sum = 0;
int x = 2;
System.out.println(“Value of x: ” +x);
System.out.println(“Number of terms: ” +n);
sum + = x; // First term added here,
for (int i = 2; i < = n; i+ +){
term = sign * Math.pow(x,i);
sum + = term;
sign *= -1;
}
System.out.println(“Sum of Series +sum);
break;
case 2 :
int num;
System.out.println(“Enter the number of terms: ”);
String tm = input.readLine(); .
num = Integer.parselnt(tm);
int s = 0, c;
for (c = 1; c < = num; c+ +){
s = s * 10 + 1;
System.out.print(s + ” “);
}
break;
}
}
}
Question 7.
Write a program to input integer elements into an
array of size 20 and perform the following
operations: [15]
(i) Display largest number from the array.
(ii) Display smallest number’from the array.
(iii) Display sum of all the elements of the array.
Answer:
import java.util.Scanner;
class LargeSmallSum {
public static void main(String args[ ]) {
int n;
int max, min, sum = 0;
int i, j;
Scanner s = new Scanner(System.in);
System.out.print(“Enter no. of elements you want in
array:”);
n = s.nextlnt();
int a[ ] = new int[n];
System.out.println(“Enter all the elements:”);
for (i = 0; i < n; i+ +) {
a[i] = s.nextlntO;
}
max = a[0];
min = a[0];
for(i = 0; i < n ; i + +) { if(a[i] > max) {
max = a[i];
}
if (a[i] < min) {
min = a[i];
}
}
System.out.println(“Maximum Number is:”+max);
System.out.println(“Smallest Number is:” +min);
for(i = 0; i < n; i+ +) {
sum = sum + a[i];
}
System.out.println(“Sum of the Numbers is:” +sum);
}
}
Question 8.
Design a class to overload a function check ( ) as
follows : [15]
(i) void check (String str, char ch) – to find and print
the frequency of a character in a string.
Example : *
Input:
str = “success”
ch = ‘s’ .
Output:
number of s present is = 3
(Two Hours)
Answers to this Paper must be written on the paper
provided separately.
You will not be allowed to write during the first 15
minutes.
This time is to be spent in reading the question
paper.
The time given at the head of this Paper is the time
allowed for writing the answers.
This paper is divided into two Sections.
Attempt all questions from Section A and any
four questions from Section B.
The intended marks for questions or parts of
questions are given in brackets [ ].
(Attempt all questions)
Question 1:
(a) Define Encapsulation. [2]
(b) What are keywords ? Give an example. [2]
(c) Name any two library packages. [2]
(d) Name the type of error ( syntax, runtime or
logical error) in each case given below: [2]
(i) Math.sqrt (36 – 45)
(ii) int a;b;c;
(e) If int x [ ] = { 4, 3,7, 8, 9,10}; what are the values
of p and q ? [2]
(i) p = x.length
(ii) q = x[2] + x[5] * x[1]
Answer:
(a) Encapsulation: It is process of wrapping code
and data together into a single unit (called class).
(b) Keywords: Keywords are reserved words in
Java, which have a special meaning in the
language.
Example: if, void, int etc.
(c) (i) java.io
(ii) java.util
Question 2:
(a) State the difference between == operator and
equals ( ) method. [2]
(b) What are the types of casting shown by the
following examples: [2]
(i) char c = (char) 120;
(ii) int x = ‘t’;
(c) Differentiate between formal parameter and
actual parameter. [2]
(d) Write a function prototype of the following: [2]
A function PosChar which takes a string argument
and a character argument and returns an integer
value.
(e) Name any two types of access specifiers. [2]
Answer:
(a)
= = operator
It is a relational operator.
(c)
Formal parameter
They ar
They are variables define in function signature.
Question 3:
(a) Give the output of the following string
functions: [2]
(i) “MISSISSIPPI”.indexOf(‘S’) +
“MISSISSIPPF”.lastIndexOf(‘I’)
(ii) “CABLE”.compareTo(“CADET”)
(b) Give the output of the following Math
functions: [2]
(i) Math.ceil(4.2)
(ii) Math.abs(-4)
Answer:
(a) (i) 2 + 10 = 12
(ii) -3
(b) (i) 5.0
(ii) 4
(c) Parameterized Constructor: It is a constructor
which accepts parameters. When an object is
declared using parameterized constructor, the initial
values have to be passed as arguments to the
constructor.
(e) String k;
k = x%2 == 0 ? “EVEN” : “ODD”;
System.out.print(k);
(g)
boolean.
(h) (i) Output:
5
10
(ii) 3 times
Question 4:
Define a class named BookFair with the following
description: [15]
Instance variables/Data members :
String Bname — stores the name of the book
double price — stores the price of the book Member
methods :
(i) BookFair() — Default constructor to initialize data
members
(ii) void Input() — To input and store the name and
the price of the book.
(iii) void calculate() — To calculate the price after
discount. Discount is calculated based on the
following criteria.
Price
3000
2 3
4 5 6
I C
I C S
I C S E
Question 7:
Design n class to overload a function SumSeriesO
as follows: [15]
(i) void SumSeries(int n, double x) – with one integer
argument and one double argument to find and
display the sum of the series given below:
Answer:
Question 8:
Write a program to accept a number and check and
display whether it is a Niven number or not. [15]
(Niven number is that number which is divisible by
its sum of digits).
Example:
Consider the number 126.
Sum of its digits is 1+2+6 = 9 and 126 is divisible by
9.
Answer:
Question 9:
Write a program to initialize the seven Wonders of
the World along with their locations in two different
arrays. Search for a name of the country input by the
user. If found, display the name of the country along
with its Wonder, otherwise display “Sorry Not
Found!”. [15]
Seven wonders — CHICHEN ITZA, CHRIST THE
REDEEMER, TAJMAHAL, GREAT WALL OF
CHINA, MACHU PICCHU, PETRA, COLOSSEUM
Locations — MEXICO, BRAZIL, INDIA, CHINA,
PERU, JORDAN, ITALY
Example — Country Name: INDIA Output: INDIA-
TAJMAHAL
Country Name: USA Output: Sorry Not Found!
Answer:
(Attempt all questions)
Question 1:
(a) What are the default values of the primitive data
type int and float ? [2]
(b) Name any two OOP’s principles. [2]
(c) What are identifiers ? [2]
(d) Identify the literals listed below: [2]
(i) 0.5 (ii) ‘A’ (iii) false (iv) “a”
(e) Name the wrapper classes of char type and
boolean type. [2]
Answer:
(a) Default values of:
int 0
float 0.0
Question 2:
(a) Evaluate the value of a. if value of p = 5, q = 19
[2]
int n = (q – p) > (p – q) ? (q – p) : (p – q);
(b) Arrange the following primitive-data types in an
ascending order of their size:
(i) char (ii) byte (iii) double (iv) int [2]
Answer:
(a) 14.
Question 3:
(a) State the data type and value of y after the
following is executed:
char x=7;
y-Character.isLetter(x); [2]
(h) output: a b c d
Question 4:
Define a class named ParkingLot with the following
description :
Instance variables/data members:
int vno — To store the vehicle number
int hours — To store the number of hours the vehicle
is parked in the parking lot
double bill — Tb store the bill amount
Member methods:
void input( ) — To input and store the vno and
hours.
void calculate( ) — To compute the parking charge
at the rate of Rs.3 for the first hours or part thereof,
and Rs. 1.50 for each additional hour or part thereof.
void display ( ) — To display the detail
Write a main method to create an object of the class
and call the above methods. [15]
Answer:
Question 5:
Answer:
Question 6:
Write a program to input and store roll numbers,
names and marks in 3 subjects of n number
students in five single dimensional array and display
the remark based on average marks as given
below : (The maximum marks in the subject are
100) [15]
Answer:
Question 7:
Design a class to overload a function Joystring( ) as
follows :
(i) void Joystring (String s, char ch1 char ch2) with
one string argument and two character arguments
that replaces the character argument ch1 with the
character argument ch2 in the given string s and
prints the new string.
Example:
Input value of s = “TECHNALAGY”
ch1=‘A’,
ch2=‘O’
Output: TECHNOLOGY
(ii) void Joystring (String s) with one string argument
that prints the position of the first space and the last
space of the given string s.
Example:
Input value of = “Cloud computing means Internet
based computing”
Output: First index : 5
Last index : 36
(iii) void Joystring (String s1, String s2) with two
string arguments that combines the two string with a
space between them and prints the resultant string.
Example :
Input value of s1 =“COMMON WEALTH”
Input value of s2 =“GAMES”
Output: COMMON WEALTH GAMES
(use library functions) [15]
Answer:
Question 8:
Write a program to input twenty names in an array.
Arrange these names in descending order of
alphabets, using the bubble sort technique. [15]
Answer:
Question 9:
Using the switch statement, 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 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! = 1×2×3×4×5 = 120.
For an incorrect choice, an appropriate error
message should be displayed. [15]
Answer:
(Two Hours)
Answers to this Paper must be written on the paper
provided separately.
You will not be allowed to write during the first 15
minutes.
This time is to be spent in reading the question
paper.
The time given at the head of this Paper is the time
allowed for writing the answers.
This paper is divided into two Sections.
Attempt all questions from Section A and any
four questions from Section B.
The intended marks for questions or parts of
questions are given in brackets [ ].
(Attempt all questions)
Question 1:
(a) Which of the following are valid comments ?
(i) /* comment */
(ii) /* comment
(iii) / / comment
(iv) */ comment */ [2]
Answer:
(a) (i) /* comment */
(iii) //comment
(b) A package in java is a mechanism for organizing
java classes into namespaces similar to the modules
of modula. Java packages allow classes in the same
package to access each other’s package-access
members.
Two Java application programming interface
packages are java.lang and java.io.
(c) (i) long
(ii) char.
(d)
float literals
Question 2:
(a) Operators with higher precedence are evaluated
before operators with relatively lower precedence.
Arrange the operators given below in order of higher
precedence to lower precedence. [2]
(i) && (ii)% (iii) > = (iv) ++
(b) (i) System.out.println(“Java”);—method
invocation statement.
(ii) costPrice = 457.50;—assignment statement.
(iii) Car hybrid= new Car();—object creation
statement.
(iv) petrolPrice++;—increment statement.
(c)
Switch statement
value of an expression.
Syntax :
if (condition)
statements;
Else
statements;
}
(d) An infinite loop can be created by skipping the
condition. This provides infinite statements to be
executed again and again.
An infinite loop statement :
int i;
for (i = 1; ; i++)
{
System.out.println(“This is an end loop”).
}
Question 3:
(a) List the variables from those given below that are
composite data types: [2]
(i) static int x;
(ii) arr[i]=10;
(iii) obj.display();
(iv) boolean b;
(v) private char chr;
(vi) String str;
Answer:
(a) The composite data types are:
(i) string str;
(ii) arr[i] = 10;
(iii) obj.display();
(h) (i) 6 times.
(ii) range between 0 and 10.
Question 4:
Define a class named movieMagic with the
following description:
Instance variables/data members:
int year — to store the year of release of a movie.
String title — to-store the title of the movie
float rating — to store the popularity rating of the
movie
(minimum rating=0.0 and maximum rating=5.0)
Member methods:
(i) movieMagic() Default constructor to initialize
numeric data members to 0 and String data member
to “ ”.
(ii) void accept() To input and store year, title and
rating.
(iii) void display() To display the title of a movie and
a message based on the rating as per the table
below.
Rating Me
0.0 to 2.0
2.1 to 3.4
3.5 to 4.5
4.6 to 5.0
1. year int
2. title string
3. rating float
4. IR —
5. br —
6. obj —
Question 5:
A special two-digit number is such that when the
sum of its digits is added to the product of its digits,
the result is equal to the original two-digit number.
Example: Consider the number 59.
Sum of digits = 5 + 9=14
Product of its digits = 5 x 9 = 45
Sum of the sum of digits and product of digits = 14 +
45 = 59
Write a program to accept a two-digit number. Add
the sum of its digits to the product of its digits. If the
value is equal to the number input, output the
message “Special 2-digit number” otherwise, output
the message “Not a special 2-digit number”. [15]
Answer:
The variable description is as follows:
1. num int
2. sum int
3. pro int
5. IR —
6. hr —
7. digit int
8. n int
9. obj —
Question 6:
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 / admin / Pictures / flower.jpg
Output path: C: / Users/admin/Pictures/
File name: flower
Extension: jpg [15]
Answer:
The variable description is as follows:
1. pathname string
2. filename string
3. extensionname string
4. path string
5. IR —
6. br —
7. r int
8. s int
Question 7:
Design a class to overload a function area( ) as
follows:
(i) double area (double a, double b, double c) with
three double arguments, returns the area of a
scalene triangle using the formula:
area = s(s−a)(s−b)(s−c)−−−−−−−−−−−
−−−−−−√2ab
where s=a+b+c2
(ii) double area (int a, int b, int height) with three
integer arguments, returns the area of a trapezium
using the formula:
area = 12 height (a + b)
(iii) double area (double diagonal 1, double diagonal
2) with two double arguments, returns the area of a
rhombus using the formula :
area = 12 (diagonal 1 x diagonal 2) [15]
Answer:
The variable description is as follows:
1. a double
2. b double
3. c double
4. s double t
5. r double t
6. area double
7. a int
8. b int
9. height int
10. diagonal 1 double
Question 8:
Using the switch statement, write a menu driven
program to calculate the maturity amount of a Bank
Deposit.
The user is given the following options :
(i) Term Deposit
(ii) Recurring Deposit
For option (i) accept principal (P), rate of interest(r)
and time period m years(n). Calculate and output the
maturity amount (A) receivable using the formula
Answer:
Question 9:
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, 20101. [15]
Answer: