Previous Questions and Answers: 2019
COMPUTER APPLICATIONS
SECTION A (40 Marks)
Attempt all questions
Question 1
(a) Name any two principles of Objetc-oriented Programming. [2]
1) Abstraction
2) Encapsulationm
(b) Write a difference between unary and binary operator. [2]
Operator that operates on one operand is known as unary operator. E.g.: ++, --
Operator that operates on two operands is known as binary operator. E.g.: = + etc
(c) Name the keyword which:
(i) indicates that a method has no return type.
(ii) makes the variable as class variable
[2]
(i) void
(ii) static
(d) Write memory capacity of short and float data type in bytes. [2]
short: 2 bytes
float: 4 bytes
(e) Identify and name the following tokens: [2]
public: Keyword
‘a’: Literal
== operator
{ } Punctuator
Question 2
(a) Differentiate beween if else if and switch case statements. [2]
switch
1) Only equality checking can be done.
2) Only integer and character values can be checked.
3) Only one variable can be used to test.
if
1) Relational or logical expressions can be used.
2) Any type of value can be tested including floating point or string or boolean.
3) Various variables can be used for condition checking.
(b) Give output:
String P=”20”, Q=”19”;
int a=Integer.parseInt(P);
int b =Integer.parseInt(P);
System.out.println(a+""+b); [2]
2019
(c) What are the various types errors in Java? [2]
1) Syntax errors. E.g.: Class Sum
2) Run time error. E.g.: System.out.println(5/0);
3) Logical error: remainder=a/b;
(d) State the data type and value of res after the following is executed:
char ch=’9’;
res=Character.isDigit(ch); [2]
Data type: boolean
Value: true
(e) What is the difference between linear search and binary search? [2]
Linear Search: Search can be done in srted or unsorted elements. It searches data sequentially from index 0 to index n-1. So the searching speed is lower than binary search.
Binary search: The search can be done only in sorted elements. Its first search is in the middle of the array. If the serch element is found then the search is finished. If it is not there and it is greater than the middle element then the next search is the middle of the right half of the array. If the search element is lower than the middle element is the search is in the middle of of left half of the array. Such a way the search is done.
Question 3
(a) Write a Java expression for the following:
|x2+2xy| [2]
Math.abs(x*x+2*x*y)
(b) Write return type of the following functions:
(i) startsWith()
(ii) random() [2]
(i) boolean
(ii) double
(c) If the basic=1500, what will be the value of tax after the following is executed?
tax=basic>1200?200:100; [2]
200
(d) Give output of the following and mention how may times the loop will execute.
[2]
4
2
Loop executes 5 times
(e) State a difference between call by value and call by reference. [2]
(1) When a method is called by passing primitive values then it is call by value. When a method is called by passing reference values like objects then it is known as call by reference.
(2) In call by value copies of values are passed to method definition and these copies are received by formal parameters. Process are done with these copies and any change that takes place reflects in the copy only and original data remain unchanged.
(f) Give output:
Math.sqrt(Math.max(9,16)); [2]
4
(g) Write the output of the following:
String s1=”phoenix”, s2=”island”;
System.out.println(s1.substring(0).concat(s2.substring(2)));
System.out.println(s2.toUpperCase()); [2]
phoenixland
ISLAND
(h) Evaluate the following expression if the value of x=2,y=3 and z=1.:
v=x+--z+y+++y [2]
9
(j) What is meant by a package? Give an example. [2]
Package is group of related classes and interfaces. E.g.: java.lang is a package
SECTION B (60 Marks)
Attempt any four questions
Question 4
Design a class ShowRoom with following description:
Instance variables/data members:
String name : To store the name of the customer
long mobno : To store customer’s mobile number
double cost : To store cost of the items purchased
double dis : To store discount
double amount : To store amount to be paid after discount
Member methods:
ShowRoom - default constructor to initialize data members
void input() - To input customer name, mobile number and cost.
void calculate() - To calculate dicount on cost of purchased items based on following citeria:
(extra amount to be added in the amount as follows)
Cost | Discount Rate |
---|---|
Less than equal to Rs. 10000 | 5% |
More than 10000 and less than equal to 20000 | 10% |
More than 20000 and less than 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 also to create an object of the class and call the above member methods. [15]
Question 5
Using switch statement write a menu driven program to do the following:
(a) To generate and print Letters from A to Z and their Unicode
Letters | Unicode |
---|---|
A | 65 |
B | 66 |
.. | .. |
Z | 90 |
b) Display the following pattern using iteration statement:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5 [15]
Question 6
Write a program to input 15 integers in an array and sort them in ascending order using bubble sort. [15]
Question 7
Design a class to overload a function series() as follows
(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 sum of series:
1/2 + 1/3 + 1/4 … 1/10
[15]
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 letter ‘A’.
Sample input: ADVANCEMENT AND APPLICATION OF INFORMATION TECHNOLOGY ARE EVER CHANGING
Sample output: Total number of words starting with letter ‘A’= 4. [15]
Question 9
A tech number has even number of digits. If the number is split in two equal halves, then square of sum of these halves is equal to the number itself. Write a program to generate and print all four digits tech numbers.
Example: Consider the number 3025
Square of sum of the halves of 3025 = (30+25)2 = (55)2 = 3025 is a tech number
[15]