Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Solution yesterday program

class Overload4

public void compare(int x, int y)

System.out.println(Math.max(x,y));

public void compare(char ch1, char ch2)

if((int)ch1>(int)ch2)

System.out.println("High numerical value ="+ch1);

else

System.out.println("High numerical value ="+ch2);

public void compare(String str1, String str2)

if(str1.length()>str2.length())

System.out.println(str1+" is longer string");


else

System.out.println(str2+" is longer string");

}}

1. Design a class to overload a function compute( ) as follows:

i. void compute( int , char ) : to compute the square of the integer argument if the given

character argument is ‘s’ otherwise find its cube.

ii. void compute(double , char) : to compute volume of a cube if the given character

argument is ‘v’ otherwise find its diagonal.

iii. void compute(int, int , char) : to compute area of a rectangle if the given character

argument is ‘a’ otherwise finds its perimeter.

Volume of cube = side3

Diagonal of cube = a√

Area of rectangle = length * breadth

Perimeter of rectangle = 2*(length+breadth)

class Overload5

{
public void compute( int num , char ch)

if (ch=='s')

System.out.println("Square ="+(num*num));

else

System.out.println("Cube ="+(num*num*num));

public void compute(double side, char ch)

if (ch=='v')

System.out.println("Volume of cube ="+(Math.pow(side,3)));

else

System.out.println("Diagonal of cube ="+(side*Math.sqrt(3)));

public void compute(int l, int b, char ch)

if(ch=='a')

System.out.println("Area of rectangle ="+(l*b));

else
System.out.println("Perimeter of rectangle ="+(2*(l+b)));

2. Design a class to overload a function series() as follows:

i. double series(double n) with one double arguments and returns the sum of the series.

sum = ……………….. +

ii. double series (double x, double n) with two double arguments and returns the sum of

the series .

sum =

You might also like