public Triangle(double s1, double s2, double s3)
{
this.side1=s1;
this.side2=s2;
this.side3=s3;
}
public Isosceles( double EQside, double otherside)
{
super(EQside, otherside); //calls triangle constructor
}
public Equilateral(double side)
{
super(side); //calls isosceles constructor.
}/
Look at all your constructors. You have one triangle constructor, and it takes three parameters. Then in the Isosceles constructor you call super() with two parameters. You made the same mistake in the Equilateral constructor.
jasimp
Senior Poster
3,623 posts since Aug 2007
Reputation Points: 533
Solved Threads: 53
Hope that helps.
It doesn't help because you just threw code at the OP, didn't offer any explanation to what you changed and didn't evenshow what you fixed. You should point the OP in the right direction instead of thrusting code at them.
jasimp
Senior Poster
3,623 posts since Aug 2007
Reputation Points: 533
Solved Threads: 53
If all that code is one Java file than that could be the problem. I separated each class GeometricShape, Triangle, Isosceles, Equilateral, into it's own file and had no trouble running a driver class creating each type of triangle.
jasimp
Senior Poster
3,623 posts since Aug 2007
Reputation Points: 533
Solved Threads: 53
I know this is a beginner question but it is something that I have never had to do before. Is this the correct way to import the other classes?
Why would you do this in your GeometricObject class? Just create a driver class, here's the one I made.
public class Tester {
public static void main(String[] args) {
Triangle tri = new Triangle(56,56,56);
System.out.println(tri.perimeter());
Isosceles iso = new Isosceles(56,56);
System.out.println(iso.perimeter());
}
}
Creating a driver class just tests code from other classes you have built. Your GeometricObject class is an abstract class and has no need to import the other classes because it never uses them. I'm pretty sure that if you keep your Java files in the same folder, say "/Java Code/Geometric" when you compile them the compiler will find all the classes it needs.
jasimp
Senior Poster
3,623 posts since Aug 2007
Reputation Points: 533
Solved Threads: 53
Now referring to your import statements (Although jasimp has already given you the solution for finding the classes you made with "importing" them).
You import the classes and not the .java files, (unlike including the header files in C or C++).
A simple example is show below, here I am including the Hashtable class present in the java.util package. Also observe the second import statement where using the wildcard "*", I am including all the packages present in the java.awt package.
import java.util.Hashtable;
import java.awt.*;
stephen84s
Nearly a Posting Virtuoso
1,443 posts since Jul 2007
Reputation Points: 668
Solved Threads: 154