I am currently working on a Triangle related object class, and I am having trouble with my static method.
For the homework assignment, my professor specifically wants this
A static method isTriangle() that accepts 3 double values as lengths of sides and returns true if the given sides can form a triangle, otherwise returns false. [help: sides s1, s2 and s3 can form a triangle IF s1 < s2 + s3 and s2 < s1 + s3 and s3 < s1 + s2].
What I currently have is:
package Homework;
import java.util.Scanner;
public class Triangle {
Scanner scan1 = new Scanner(System.in);
private double side1;
private double side2;
private double side3;
public Triangle(double s1, double s2, double s3) {
this.side1 = s1;
this.side2 = s2;
this.side3 = s3;
}
public static boolean isTriangle(Triangle verify) {
return (side1 < side2 + side3 && side2 < side1 + side3 && side3 < side1 + side2);
}
}
This is the error message I am getting:
Cannot make a static reference to the non-static field.
isTrianglehas nothing to do with the proposed in the whole exercice.Triangleobjectverify, then you should useverify.side1etc.