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.

4 Years
Discussion Span
Last Post by JamesCherrill

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;
    public double areaofcircle(double radius,int Circumference)
        radius = a;
        Circumference = b;
        System.out.println("Enter Radius:" + radius);
        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();
        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);

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;
This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.