it51 java programming

5
ANNAI VAILANKANNI COLLEGE OF ENGINEERING AVK Nagar, Pothaiyadi Salai,Pottalkulam,Azhagappapuram P.O., Kanyakumari District, Tamil Nadu – 629 401. S5 – Information Technology First Internal Assessment Test IT51 - Java Programming Duration: 1 1 /2hrs Max.Marks: 50 Part A(5x2=10 Marks) 1. What is the purpose of using this keyword? Give an example. 2. Write a short note on finalize() method. 3. What is meant by polymorphism in OOP? 4. Distinguish between public, private and protected? 5. Why two classes are used to handle Sting in java? Part B(40 Marks) 1. The employee list for a company contains employee code, name, designation and basic pay. The employee is given a house rent allowance (HRA) of 10% of the basic pay and dearness allowance (DA) of 75% of the basic pay. The total pay of the employee is calculated as Basic Pay+HRA+DA. Write a class to define the details of the employee. Write a constructor to assign the required initial values. Add a method to calculate HRA, DA and total pay and print them out. Write another class with a main method. Create objects for three different employees and calculate the HRA,DA and total pay. (16) (OR) 2. Explain the following with suitable example a. Constructor (8) b. Passing an object as a method parameter (8) 3. A mark list contains reg_no. and marks for three subjects sub1,sub2 and sub3. Write a class to define the mark list. Write a constructor to initialize all the variables. Write a method called Result(int minmark) where, minmark indicates the minimum mark for “pass” for each subject. This method will declare a candidate as “Pass”, if the candidate secures marks in each subject greater than or equal to min. Write another overloading method Result(int minmark,int meritmark), where meritmark indicates that a candidate who gets a “Pass” and average of the three subjects equal to or greater than merit is eligible for getting a scholarship. Write another class with main method and try the method for 7 different candidates to determine whether they get “Pass” and also determine whether they are eligible for scholarship. (16) (OR)

Upload: renjith

Post on 03-Apr-2015

291 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: IT51 Java Programming

ANNAI VAILANKANNI COLLEGE OF ENGINEERINGAVK Nagar, Pothaiyadi Salai,Pottalkulam,Azhagappapuram P.O., Kanyakumari District, Tamil Nadu – 629 401.

S5 – Information TechnologyFirst Internal Assessment Test

IT51 - Java Programming

Duration: 11/2hrs Max.Marks: 50 Part A(5x2=10 Marks)

1. What is the purpose of using this keyword? Give an example.2. Write a short note on finalize() method.3. What is meant by polymorphism in OOP?4. Distinguish between public, private and protected?5. Why two classes are used to handle Sting in java?

Part B(40 Marks)

1. The employee list for a company contains employee code, name, designation and basic pay. The employee is given a house rent allowance (HRA) of 10% of the basic pay and dearness allowance (DA) of 75% of the basic pay. The total pay of the employee is calculated as Basic Pay+HRA+DA. Write a class to define the details of the employee. Write a constructor to assign the required initial values. Add a method to calculate HRA, DA and total pay and print them out. Write another class with a main method. Create objects for three different employees and calculate the HRA,DA and total pay. (16)

(OR)2. Explain the following with suitable example

a. Constructor (8)b. Passing an object as a method parameter (8)

3. A mark list contains reg_no. and marks for three subjects sub1,sub2 and sub3. Write a class to define the mark list. Write a constructor to initialize all the variables. Write a method called Result(int minmark) where, minmark indicates the minimum mark for “pass” for each subject. This method will declare a candidate as “Pass”, if the candidate secures marks in each subject greater than or equal to min. Write another overloading method Result(int minmark,int meritmark), where meritmark indicates that a candidate who gets a “Pass” and average of the three subjects equal to or greater than merit is eligible for getting a scholarship. Write another class with main method and try the method for 7 different candidates to determine whether they get “Pass” and also determine whether they are eligible for scholarship. (16)

(OR)4. List out the basic concept of oops? Explain. (16)5. Give brief notes about String class and its methods. (8)

(OR)6. Write a program to arrange five students name in an alphabetical order. The students name may be given by a

user. (8)

Page 2: IT51 Java Programming

ANNAI VAILANKANNI COLLEGE OF ENGINEERINGAVK Nagar, Pothaiyadi Salai,Pottalkulam,Azhagappapuram P.O., Kanyakumari District, Tamil Nadu – 629 401.

S5 – Information TechnologyFirst Internal Assessment Test- Answer key

IT51 - Java ProgrammingPart-A

1. What is the purpose of using this keyword? Give an example.

This keyword is used to refer the object which invoked the method. This keyword can be used inside any method to refer to the current object. That is, this always has reference to the object on which the method was invoked. Normally a method is called with two types of arguments implicit. Implicit arguments is assigned to thisExample

void change_val(int Num1,int Num2){

this.Num1 = Num1;this.Num2=Num2;

}2. Write a short note on finalize() method.

Finalize method is similar to destructor in c++. But manual memory reclamation is not needed, because java does automatic garbage collection.In some situations, objects utilize a resource other than memory, such as a file or a handle to another object that uses system resources, when it is no longer needed.The finalize method will be called before the garbage collector removes the objectOnly one finalize can be defined to a class

3. What is meant by polymorphism in OOP?Polymorphism is the ability of an object to take on many forms. The most common use of

polymorphism in OOP occurs when a parent class reference is used to refer to a child class object.4. Distinguish between public, private and protected?

Public is signifies that the methods or variable can be accessed by elements residing in other classes. Private signifies that the method or variable can only be accessed by other elements of its class. Protected signifies that the methods or variable can only be accessed by elements residing in its class, subclasses in the same package.

5. Why two classes are used to handle Sting in java?The java platform provides two classes, String and StringBuffer, that store and manipulate strings-character data consisting of more than one character. The String class strings for strings whose value will not change. The StringBuffer class provides for strings whose value will be modified; you use string buffers when you know that the value charcter data dynamically.

Part-B1. The employee list for a company contains employee code, name, designation and basic pay. The employee is

given a house rent allowance (HRA) of 10% of the basic pay and dearness allowance (DA) of 75% of the basic pay. The total pay of the employee is calculated as Basic Pay+HRA+DA. Write a class to define the details of the employee. Write a constructor to assign the required initial values. Add a method to calculate HRA, DA and total pay and print them out. Write another class with a main method. Create objects for three different employees and calculate the HRA,DA and total pay.

HRA calculation – 3 marksDa Calculation – 3 marksTotal pay calculation – 3marksConstructor – 3 marksMain method & Object creation – 4 marks

(OR)

Page 3: IT51 Java Programming

2. Explain the following with suitable examplea. Constructor

Definition - 3 marksSyntax - 3 marksExample - 2 marks

b. Passing an object as a method parameter (8)Explanation - 2 marksSyntax - 2 marksExample - 4 marks

3. A mark list contains reg_no. and marks for three subjects sub1,sub2 and sub3. Write a class to define the mark list. Write a constructor to initialize all the variables. Write a method called Result(int minmark) where, minmark indicates the minimum mark for “pass” for each subject. This method will declare a candidate as “Pass”, if the candidate secures marks in each subject greater than or equal to min. Write another overloading method Result(int minmark,int meritmark), where meritmark indicates that a candidate who gets a “Pass” and average of the three subjects equal to or greater than merit is eligible for getting a scholarship. Write another class with main method and try the method for 7 different candidates to determine whether they get “Pass” and also determine whether they are eligible for scholarship.

(16)

Result(int minimark) - 3 marksResult(int minmark,int meritmark) - 3 marksMain class with 7 object - 5 marksConstructor - 3 marksExplanation - 2 marks

(OR)4. List out the basic concept of oops? Explain. (16)

Object – 2 marksClass – 2 marksInheritance – 2marksData Abstraction and Encapsulation – 2marksPolymorphism – 2marksDynamic Binding – 2marksMessage Passing – 2marksExample – 2marks

5. Give brief notes about String class and its methods. (8)

Explanation – 2marksAny five methods with explanation – 6 marks

(OR)6. Write a program to arrange five students name in an alphabetical order. The students name may be given by

a user. (8)

Main class – 2marksMethod to arrange in an order – 4marksDisplay the result – 2marks

Page 4: IT51 Java Programming