Asssignment 214
Asssignment 214
ASSIGNMENT 4
Session 4
1) Write a method named div() that takes two arguments of either integer or float type
and returns their division either as int or as float depending upon its arguments data
type.
2) Write a class rectangle that has two constructors(with two arguments and one
argument) to create objects as rectangle or square. It has a method called area() that
returns the area of the corresponding object.
3) Write a class Calculator that has the following members:
a) Two int: opp1 & opp2
b) Four methods:
Add(), Subtract(),Multiply() & Divide()
The functions will return the result of the corresponding operation into opp1 and
opp2 variables
Take user’s choice .
Session 6
1) Modify the class you created in Session 4 questi on 2. Overload area() function by
passing two arguments and returns a new object that has the area equals to the area of
its argument.
2) Create a class Fruit which is abstract in nature. Try to create an object of the class and
see the compiler’s response.
3) Create a class Winamp that has a final method called play(). Again create another
derived class called WinampNextgen from Winamp and try to override the play()
method. See the compiler’s output.
Session 7
1) Create a package and place the Calculator class o f Session 4 question 4 into that
package.
a) Use the instance of that class within another class from a different package.
b) Write a class that inherits the above Calculator class to override the method
divide() so that the devisor cannot be zero.
i) Place the class in the same package.
ii) Place it in a different package
Test the above class with different access specifiers.
Session 8
Write a method that will display the products with their corresponding ID
3. Take a int[][] of length 4 * 4 and display its conten ts in a 4*4 matrix format.
4. Accept a word and find out the length of the word and display it using array.
5. Write a program to add two 2D matrix using 2D arrays and store the added matrix in
a third 2D array an display the content.