Question 1 [10]
- What is dynamic initialization, with an example?
- How are the following passed in Java? i) primitive types ii) reference types
- Consider the following class:
public class myClass {
public static int x=3, y=5;
public int a=2, b=3; }
i) Name the variables for which each object of the class will have its own
distinct copy.
- ii) Name the variables that are common to all objects of the class.
- Create a class with one integer instance variable and one class variable. Initialize the variable using i) default constructor (ii) parameterized constructor
- Write a java statement to create an object mp4 of class digital.
Question 2 [10]
- Differentiate between String and Stringbuffer type data.
- Here is a skeleton definition of a class
class Sample {
int i;
char c;
float f;
} Implement the constructor.
- What will be the output of the following code fragment?
If the input given is i) 7 ii) 5
if(a=5)
out.println(“Five”);
else
System.out.println(“Not Five”);
- Differentiate between
i) equals() and compareTo() with examples and return value.
- ii) throw and throws
- Write an expression in Java for x4+ 6x2 + 25 / x
Question 3 [10]
- What are the values of x and y when the following statements are executed?
int a=63, b=36;
boolean x=(a>b) ?a:b;
int y=(a<b)?a:b;
- What will be the result stored in x after evaluating the following expression?
int x =4;
x+ = (x++ ) + (++x) +x;
- State the method that:
i) Converts a string to a primitive float data type.
- ii) Determines if the specified character is an uppercase characters.
- Write the Identifier Naming Rules. (All rules)
- Rewrite the following program segment using the if –else statements instead of the ternary operator.
String grade= (mark >= 90)?”A”: (mark >=80)? “B”: “C”;
Question 4 [10]
- Give the output of the following code
double m=6.25, n=7.45;
out.println(Math.sqrt(m));
System.out.println(Math.min(m,n));
System.out.println(Math.abs(6.25-7.45));
System.out.println(Math.ceil(m));
- Name the type of error (syntax, runtime or logical error) in each case given below:
i) Division of a variable that contains a value of zero.
ii) Multiplication operator used when the operation should be division
iii) Missing semicolon
- Write a java statement to input/read the following from the user using the keyboard.
- Character ii) String (using scanner class)
- Write about the differences between Primitive and Reference data types with example.
- What is temporary instance with example?
Section B (60 Marks)
Attempt any four questions from this Section.
The answers in this Section should consist of the Programs in either BlueJ
environment or any program environment with Java as the base.
Each program should be written using Variable descriptions/Mnemonic Codes
such that the logic of the program is clearly depicted.
Flow-Charts and Algorithms are not required.
Question 5 [15]
Given below is a hypothetical table showing rate of income tax for male citizens below the age of 65 years.
Taxable income(Ti) in Rs. Income Tax in Rs.
Does not exceed Rs. 1,60,000 Nil
Is greater than Rs.1,60,000 and less
than or equal to Rs. 5,00,000 (Ti-1,60,000)* 10%
Is greater than Rs. 5,00,000 and less than or
equal to Rs. 8,00,000 [(Ti – 5,00,000) * 20%] +34,000
Is greater than Rs. 8,00,000 [(Ti – 8,00,000)* 30%] + 94,000
Write a program to input that age, gender (male or female) and taxable income of a person. If the age is more than 65 years or the gender is female, display “Wrong category”. If the age is less than or equal to 65 years and the gender is male, compute and display the income tax payable as per the table given above.
Question 6 [15]
Define a class Library having the following description:
Instance variables/Data members:
int acnum stores the accession number of the book
String title stores the title of the book
String author stores name of the author.
Member Methods:
- void input() – to input and store accession number, title and author.
- void compute() – to accept the number of days late, calculate and display the fine charge at the rate Rs. 2 per day.
- void display() – to display the details in the following format:
Accession number Title Author
Write a main() to create an object of the class and call the above member methods.
Question 7 [15]
Write a program to accept a word and convert it into lower case if its in uppercase and display the new word by replacing only the vowels with the preceeding characters.
Sample Input : computer
Sample Output : cnmpttdr
Question 8 [15]
Write a program that encodes a word into Piglatin. To translate a word into a Piglatin word, convert the word into upper case and then place the first vowel of the original word as the start of the new word along with the remaining alphabets. The alphabets present before the vowel being shifted towards the end following by “YZ”.
Sample input : Flowers Sample Output: OWERSFLYZ
Sample input : Olympics Sample Output : OLYMPICSYZ
Question 9 [15]
Design a class named FruitJuice with the following description:
Instance variables/Data members:
int product_code – stores the product code number
String flavor – stores the flavor of the juice (eg: orange, apple etc.)
String pack_Type – stores the type oif packaging (eg:tetra-pack, PET bottle etc.)
int pack_size – stores package size(eg: 200mL, 400 mL, etc.)
int product_price – stores the price of the product.
Member Methods:
- FruitJuice() – deault constructor to initialize integer data members to 0 and String data members to “”
- void input() – to input and store the product code, flavor, pack type, pack size and product price.
- void discount() – to reduce the product price by 10%.
- void display() – to display the product code, flavor, pack type, pack size and product price.
Write a main method to create an object of the class and call the above member methods.
Question 10 [15]
Design a class to overload a function JoyString() as follows:
- void JoyString(String s, char c1, char c2) : with one string argument and two character arguments that replaces the character argument c1 with the character argument c2 in the given string s and prints the new string with first character as uppercase.
Example: s=”technology”
c1=’a’, c2=’o’
Output: “Technology”
- void JoyString(String s1, String s2) : check and print string having more characters compared to the other one.
- void JoyString(String s) : prints the position of the first space and last space of the given string s.
Example : Input value of= “Cloud computing means Internet based computing”
Output: First index= 5, Last index = 36
Write the main() and call the above member methods.