Professional Documents
Culture Documents
Assignment#2
by
Dr. Syed Noman Hasany
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.
Question 2(g): Write a JAVA program to create a rectangular array containing a
multiplication table from 2 * 1 up to 11* 12. Output the table as 11 columns with the
numeric values right-aligned in columns. (The first line of output will be the column
headings, the first column with no heading, then the numbers 2 to 11 for the remaining
columns. The first item in each of the succeeding lines is the row heading, which ranges
from 2 to 11.)
Question 2(h): Define a class for rectangle objects defined by two points, the top-left and
bottom-right corners of the rectangle. Include a constructor to copy a rectangle, a method
to return a rectangle object that encloses the current object and the rectangle passed as an
argument, and a method to display the defining points of a rectangle. Test the class by
creating four rectangles and combining these cumulatively to end up with a rectangle
enclosing them all. Output the defining points of all the rectangles you create.
Question 2(k): Define a class, tkgWeight, to represent a weight in tons, kilograms, and
grams, and include a similar range of methods and constructors as in Question 2(j).
Demonstrate this class by creating and combining some class objects.
Question 2(m): What are the differences between the String and StringBuffer objects?
Clearly state using a table, on one to one basis. Create a program that illustrates the
difference.
Question 2(n): Write a currency class that will store hidden information in rupees and
paisas. The class must have the facility to initialize currency to zero or to values given
through arguments at object creation. Write method that will add two currency objects
and store the result in 3rd object. Make sure to round paisas to rupees (1 rupee=100
paisas). Also use this statement where required. Also write a method that will convert
currency in rupees and paisa into dollar (1 $= 85 rupees).
Write another class containing main method. Create and initialize 3 instances of currency
class making use of both constructors. Then add 2 currency objects and receive the result
in 3rd object. Finally display all 3 objects.
Question 2(p): Write a JAVA program that will store information of EmployeeID using
1D integer array, EmployeeName, EmployeeDesignation and AppointmentData using 2D
String array, Salary using 1D float array for each employee. The program should take
information of 5 employees through command line input. The program should be able to
sort the data accordingly to Salary in descending order and finally display all employees
record.
Question 2(q): Write a JAVA program demonstrating the use of Method overloading in
a useful way other than the Square methods.
Question 2(r): Write a JAVA program that prints the output of System.getProperty()
method with at least 5 different parameters you find interesting. Discuss how these
parameters can help you?
Question 2(s): Write a Shape class, and make Circle, Square, and Triangle a subclass in
JAVA. Determine where fields and methods from the original classes would be in the
new super/sub class hierarchy. Write a constructor for all 4 classes (Shape, Circle,
Square, Triangle). Assuming all issues could be worked out with private fields, 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.
------------------------------------------------------XXX-------------------------------------------------------------------