Divya Teja
Divya Teja

Reputation: 23

Not even a error nor the program is running in eclipse

Hello every one I trying to build a basic program of finding the area and perimeter of a triangle. I am pretty new to eclipse. The compiler doesn't run or show errors for this program but runs the program which was previously run. The code of my program is :

import java.util.Scanner;
public class Solution 
{
    public static void main()
    {
        Scanner input=new Scanner(System.in);
        double b,h,o,t;
        System.out.println("Enter the length of base");
        b=input.nextDouble();
        System.out.println("Enter the length of heigth");
        h=input.nextDouble();
        System.out.println("Enter the length of sideOne");
        o=input.nextDouble();
        System.out.println("Enter the length of sideTwo");
        t=input.nextDouble();
        input.close();

        Attributes Val= new Attributes();
        Val.setbase(b);
        Val.setheight(h);
        Val.setsideOne(o);
        Val.setsideTwo(t);

        double result=Val.area();
        System.out.println("the area of triangle is:"+result);
        result=Val.peri();
        System.out.println("the perimeter of triangle is:"+result);

    }
}

The other class is

public class Attributes 
{
    private double base,height,sideOne,sideTwo;

    public double area()
    {
        double area=this.base*this.height/2;
        return area;
    }

    public double peri()
    {
        double peri=base+sideOne+sideTwo;
        return peri;
    }

    public double getbase()
    {
        return this.base;
    }
    public double getheight()
    {
        return this.height;
    }
    public double getsideOne()
    {
        return this.sideOne;
    }
    public double getsideTwo()
    {
        return this.sideTwo;
    }
    public void setbase(double base)
    {
        this.base=base;
    }
    public void setheight(double height)
    {
        this.height=height;
    }
    public void setsideOne(double sideOne)
    {
        this.sideOne=sideOne;
    }
    public void setsideTwo(double sideTwo)
    {
        this.sideTwo=sideTwo;
    }
}

Could you help me with the issue and suggest me if any errors are present in the program. Thanks in advance. :)

Upvotes: 0

Views: 78

Answers (1)

Akash Thakare
Akash Thakare

Reputation: 23012

You have not declared the main method properly. As execution of program starts from the main method, make sure you are running the class which contains proper declaration of a main method.

Your main method should be like this:

public static void main(String args[]) {
    // Starting point of application
}

See for instance the wiki at c2.com for more information.

Upvotes: 2

Related Questions