You are on page 1of 3

Object Oriented Programming

Dr. Syed Noman Hasany

Instructions To Be Followed Strictly:
• All questions must be handwritten.
• Case sensitivity errors in the programs will be considered.
• Copy question before each solution with the same naming convention mentioned
in the assignment.
• Use index page and put page numbers on each page.
• Use separate sheet for the title of Assignment.
• ‘i’ and ‘l’ are not used in naming questions, so do not panic.
• The assignment should be submitted on 7/4/11 and 9/4/11 by section C and D in
the previous green and black color files respectively.

Question 2(a): Did equal to and less than comparison can be applied to enum datatypes
and enum variables? Check with equalsTo() method.

Question 2(b): Write a JAVA program that initializes a string array with four names.
Hint: Use compareTo() method to sort the string array.

Question 2(c): Write a JAVA program that generates a random sequence of capital
letters that does not include vowels. Use appropriate print message.

Question 2(d): Does JAVA support explicit casting between char and primitive
numerical datatypes? Support your answer with example code and result.

Question 2(e): Write 3 (2(e1), 2(e2), 2(e3)) JAVA programs that initializes a 2D array of
varying length to store the pattern. Write a nested for loop that processes array to print
the pattern.
@ ****** *****
@@ ?????? $$$$
@@@ **** ***
@@@@ ???? $$
@@@@@ ** *
@@@@@@ ??

Question 2(f): Define an array of ten String elements each containing an arbitrary string
of the form “month/day/year”; for example,”01/29/11” or “12/5/01”. Analyze each
element in the array and output the date represented in the form 29th January 2011.

to multiply and divide an object by an integer value. and millimeters. and a method to display the defining points of a rectangle. tkgWeight. Include a constructor to copy a rectangle. the top-left and bottom-right corners of the rectangle. Question 2(j): Define a class. which create an object with the length set to zero. The class must have the facility to initialize currency to zero or to values given through arguments at object creation. the first column with no heading. Question 2(p): Write a JAVA program that will store information of EmployeeID using 1D integer array. Output the table as 11 columns with the numeric values right-aligned in columns. Include constructors that accept three arguments—meters. (The first line of output will be the column headings. and no arguments. then the numbers 2 to 11 for the remaining columns.) Question 2(h): Define a class for rectangle objects defined by two points. The program should take . Demonstrate this class by creating and combining some class objects. Finally display all 3 objects. which ranges from 2 to 11. and millimeters. a method to return a rectangle object that encloses the current object and the rectangle passed as an argument. each stored as integers. Write another class containing main method. one integer argument in millimeters. Question 2(k): Define a class. kilograms. one double argument in centimeters. EmployeeName. centimeters. to represent a weight in tons. Test the class by creating four rectangles and combining these cumulatively to end up with a rectangle enclosing them all. Create a program that illustrates the difference. Include methods to add and subtract objects. to calculate an area resulting from the product of two objects. EmployeeDesignation and AppointmentData using 2D String array. Output the defining points of all the rectangles you create. Salary using 1D float array for each employee. Question 2(m): What are the differences between the String and StringBuffer objects? Clearly state using a table. on one to one basis. and include a similar range of methods and constructors as in Question 2(j). and to compare objects (returning 0 if the lengths ar equal. Also use this statement where required. 1 if first length is greater and 2 if the second one is greater). Then add 2 currency objects and receive the result in 3rd object. to represent a length measured in meters. Make sure to round paisas to rupees (1 rupee=100 paisas).Question 2(g): Write a JAVA program to create a rectangular array containing a multiplication table from 2 * 1 up to 11* 12. Write method that will add two currency objects and store the result in 3rd object. Check the class by creating some objects and testing the class operations. Create and initialize 3 instances of currency class making use of both constructors. The first item in each of the succeeding lines is the row heading. centimeters. and grams. Question 2(n): Write a currency class that will store hidden information in rupees and paisas. mcmLength. Also write a method that will convert currency in rupees and paisa into dollar (1 $= 85 rupees).

Circle. The program should be able to sort the data accordingly to Salary in descending order and finally display all employees record. Discuss how these parameters can help you? Question 2(s): Write a Shape class. Write a constructor for all 4 classes (Shape. and make Circle. ------------------------------------------------------XXX------------------------------------------------------------------- . Question 2(r): Write a JAVA program that prints the output of System.information of 5 employees through command line input. Square. Assuming all issues could be worked out with private fields. and Triangle a subclass in JAVA.getProperty() method with at least 5 different parameters you find interesting. Determine where fields and methods from the original classes would be in the new super/sub class hierarchy. Square. Question 2(q): Write a JAVA program demonstrating the use of Method overloading in a useful way other than the Square methods. what methods would be appropriate for Shape and what methods for the subclasses for each class? Write a main method to demonstrate the usage of the classes. Triangle).