Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Error (using Eclipse): No enclosing instance of type RightTriangle is accessible

ID: 3650726 • Letter: E

Question

Error (using Eclipse): No enclosing instance of type RightTriangle is accessible. Must qualify the allocation with an enclosing instance of type RightTriangle (e.g. x.new A() where x is an instance of RightTriangle).

Code:
public class RightTriangle {
public static void main(String[] args){

Triangle tri1 = new Triangle();
// Properties
System.out.println(tri1.sideA());
System.out.println(tri1.sideB());
System.out.println(tri1.sideC());

}
class Triangle{
double a;
double b;
double c;

void setSides(double a, double b, double c){
a = sideA();
b = sideB();
c = sideC();
}

double sideA(){
a = 3.0;
return a;
}
double sideB(){
a = 4.0;
return b;
}
double sideC(){
a = 5.0;
return c;
}
double getArea(){
return (b*c)/2;
}
double getRadius(){
return a+b+c;
}
}
}

I've been trying to figure this out, but I can't.
Can someone please help me figure out what I'm doing wrong?

Explanation / Answer

Please rate...

Corrected Program:

===================================================

Save the file with file name RightTriangle.java

===================================================

public class RightTriangle
{
    public static void main(String[] args)
    {

        Triangle tri1 = new Triangle();
        // Properties
        System.out.println("A= "+tri1.sideA());
        System.out.println("B= "+tri1.sideB());
        System.out.println("C= "+tri1.sideC());
        System.out.println("Area= "+tri1.getArea());
    }
}

    class Triangle{
        double a;
        double b;
        double c;

        void setSides(double a, double b, double c){
            a = sideA();
            b = sideB();
            c = sideC();
        }

        double sideA(){
            a = 3.0;
            return a;
        }
        double sideB(){
            b = 4.0;
            return b;
        }
        double sideC(){
            c = 5.0;
            return c;
        }
        double getArea(){
            return (b*c)/2;
        }
        double getRadius(){
            return a+b+c;
        }
    }

======================================================

Sample output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote