define a class containing overloaded method which calculate are of square circle and rectangle depending on the type and numbers of arguments passed. If the number of argument passed to the are is one ,then the area of the cicle and suare should be displayed,however if it is 2 then rectangle should be displayed.

just need an illustration to get me started.

There are vast numbers of sample programs on the web. Do you expect someone here to write one just for you, or to do a Google search for you?
There are lots of people here who will help you, if, and only if, you show that you are trying.

``````//dnt knw if this is how it should be done.
package calculate;
import java.util.Scanner;
public class Area {
double a;
int b;
int x;
{
Circumference = b;
System.out.println("Enter Circumference" + Circumference);
System.out.println("Area of Circle is:");
double result = a * b;
return result;

}
public int areaofsquare(int x,int b)
{
int result =  x * b;
return result;

}
public int areaofrectangle(int x,int b)
{
int c = x * b;
return c;
}

public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
Area a = new Area();
a.areaofcircle(3.14,2);
double result = sc.nextDouble();
System.out.println("Area Of square is:");
a.areaofsquare(2, 2);
System.out.println("Area Of Rectangle is:");
a.areaofrectangle(2, 2);
}
}
``````

How do i make it return the args using if else?

OK, that's a good start.
You need to decide whether the methods work by prompting for input, or accept values as parameters. Right now it's a bit of a mixture.
Similarly do they print the result or return it?
In general its more flexible to define your methods as taking the values from parameters and returning the answer. That way you can use them from code that prompts the user and displays the results on the console, or use exactly the same methods in a full GUI version.

How do i make it return the args using if else?

do you mean like this example?

``````int largerOf(int a, int b) {
if (a>b) return a
else return b;
}
``````
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.