sup ya'll, i've been doing this Triangle class homework for a couple of days and have ended up having to change how i am attacking it like 2wice but anyway. i've hit the last wall i think i can hit. this code is all wrong & i don't even know why. i should know, but the semester is almost up & i'm fragged. please help with any hints tips, etc. i don't want you guys to do it for me but instead show me my many errors & a path to make the program work. please...

thanx
>>!?!

import javax.swing.JOptionPane;

public class Triangle extends GeometricObject

{
	//get the sides first
        double side;
	double side1 = 1.0;
	double side2 = 1.0;
	double side3 = 1.0;
	double[] numbers = new double[];

  public Triangle()
{
}

public static void main(String[] args) {
    
    
    String Str1 = JOptionPane.showInputDialog("Enter side 1");
    double side1 = Double.parsedouble(Str1);
    String Str2 = JOptionPane.showInputDialog("Enter side 2");
    double side2 = Double.parsedouble(Str2); 
    String Str3 = JOptionPane.showInputDialog("Enter side 3");
    double side3 = Double.parsedouble(Str3);
     
    
    Triangle t = new Triangle();
    
    
    JOptionPane.showMessageDialog(null, result );
    }

  public Triangle(double side1, double side2, double side3)
  {
   this.side1 = side1;
   this.side2 = side2;
   this.side3 = side3;
	}


 //get the area
  public double getArea()
    {
    return radius * radius * Math.PI;
    }

  //get the perimeter
  public double getPerimeter()
    {
   return 2 * radius * Math.PI;
    }

public String toString()
  {
   return "Triangle: side1 = " + side1 + "side 2 = " + side2 + "side 3 = " + side3;
   }


public String getType()
  {
    if(side[1] == side[2] | side[1] == side [3] | side[2] == side[3])
     {
      if(side[1] == side[2] & side[2] == side[3]) type = "Equilateral";
      else type = "Isosceles";
       } 
    else
      {
    type = "Scalene";
    }
    return type;
  }
}

Well for starters you are calculating the area and perimeter of a circle rather than a triangle. Not that you are actually calling these methods though.

Also your OR and AND statements in the if-statement in your getType() method needs || and && rather than | and &. And you need to initialise the variable 'type' before you use it.

Your call to the constructor for Triangle needs three double paramenters.

thanx darkagn & masijade...now i have the below code & i've cleared out a couple more errors but still won't compile or run (obviously)...

Guidance? tips?

import javax.swing.JOptionPane;

public class Triangle extends GeometricObject

{
	//get the sides first
        double side;
	double side1 = 1.0;
	double side2 = 1.0;
	double side3 = 1.0;
        double type;
        
        public String Str1;
        public String Str2;
        public String Str3;
        
  public Triangle()
{
}

public static void main(String[] args) {
    
    
    String Str1 = JOptionPane.showInputDialog("Enter side 1");
    double side1 = Double.parsedouble(Str1);
    
    String Str2 = JOptionPane.showInputDialog("Enter side 2");
    double side2 = Double.parsedouble(Str2); 
    
    String Str3 = JOptionPane.showInputDialog("Enter side 3");
    double side3 = Double.parsedouble(Str3);
        
    Triangle T = new Triangle();
    
    
    JOptionPane.showMessageDialog(null, result );
    }

  public Triangle(double side1, double side2, double side3)
  {
   this.side1 = side1;
   this.side2 = side2;
   this.side3 = side3;
	}

  //get side 1
    public double getSide1()
    {
        return side1;
    }
    
  //get side 2
    public double getSide2()
    {
        return side2;
    }
    
  //get side 3
    public double getSide3()
    {
        return side3;
    }

 //get the area
  public double getArea()
    {
    return .5 * side1 * side2;
    }

  //get the perimeter
  public double getPerimeter()
    {
   return side1 + side2 + side3;
    }

public String toString()
  {
   return "Triangle: side1 = " + side1 + "side 2 = " + side2 + "side 3 = " + side3;
   }


public String getType()
  {
    if(side1 == side2 || side1 == side3 || side2 == side3)
     {
      if(side1 == side2 && side2 == side3) type = "Equilateral";
      else type = "Isosceles";
       } 
    else
      {
    type = "Scalene";
    }
    return type;
  }
}

You still haven't initialised the variable 'type' before you use it in the getType() method.

The line:

Triangle t = new Triangle();

is calling the wrong constructor (I think). Add three double parameters to this call.

well...the NetBeans is giving me <identifier>expected on this code below:

String "type";

and the same thing in the cmd about line #12 with the <identifier> expected at the String "type"; part

import javax.swing.JOptionPane;

public class Triangle extends GeometricObject

{
	//get the sides first
        double side;
	double side1 = 1.0;
	double side2 = 1.0;
	double side3 = 1.0;
        
        String "type";
        
        public String Str1;
        public String Str2;
        public String Str3;
        
  public static void main(String[] args) {
    
    
    String Str1 = JOptionPane.showInputDialog("Enter side 

1");
    double side1 = Double.parsedouble(Str1);
    
    String Str2 = JOptionPane.showInputDialog("Enter side 

2");
    double side2 = Double.parsedouble(Str2); 
    
    String Str3 = JOptionPane.showInputDialog("Enter side 

3");
    double side3 = Double.parsedouble(Str3);
        
    JOptionPane.showMessageDialog(null, result );
    }
  
  public Triangle()
{
          Triangle T = new Triangle();
}

  public Triangle(double side1, double side2, double side3)
  {
   this.side1 = side1;
   this.side2 = side2;
   this.side3 = side3;
	}

  //get side 1
    public double getSide1()
    {
        return side1;
    }
    
  //get side 2
    public double getSide2()
    {
        return side2;
    }
    
  //get side 3
    public double getSide3()
    {
        return side3;
    }

 //get the area
  public double getArea()
    {
    return .5 * side1 * side2;
    }

  //get the perimeter
  public double getPerimeter()
    {
   return side1 + side2 + side3;
    }

public String toString()
  {
   return "Triangle: side1 = " + side1 + "side 2 = " + side2 + 

"side 3 = " + side3;
   }


public String getType()
  {
    if(side1 == side2 || side1 == side3 || side2 == side3)
     {
      if(side1 == side2 && side2 == side3) type = 

"Equilateral";
      else type = "Isosceles";
       } 
    else
      {
    type = "Scalene";
    }
    return type;
  }
}

Ok I don't want to give it away, but the line

String "type";

is not how you initialise a String. And it is in the wrong method.

You have moved the line

Triangle T = new Triangle();

from where it should be to the wrong place. I sugeested earlier that you need to modify this line, not move it.

I think I've got the Triangle line down but I've been following a couple different examples in the book but still no dice. this is what i currently have...

import javax.swing.JOptionPane;

public class Triangle extends GeometricObject

{
	//get the sides first
        double side;
	double side1 = 1.0;
	double side2 = 1.0;
	double side3 = 1.0;
        
        //Strings
        public String Str1;
        public String Str2;
        public String Str3;

        // Turn the strings entered to the double
public class ConvertStringToDouble {        
  public static void main(String[] args) {
        
    String Str1 = JOptionPane.showInputDialog("Enter side 1");
    double side1 = Double.parseDouble(Str1);
    
    String Str2 = JOptionPane.showInputDialog("Enter side 2");
    double side2 = Double.parseDouble(Str2); 
    
    String Str3 = JOptionPane.showInputDialog("Enter side 3");
    double side3 = Double.parseDouble(Str3);
    
    JOptionPane.showMessageDialog(null, result );
    }

  public Triangle()
{
   Triangle T = new Triangle();
}

  public Triangle(double side1, double side2, double side3)
  {
   this.side1 = side1;
   this.side2 = side2;
   this.side3 = side3;
  }

  //get side 1
    public double getSide1()
    {
        return side1;
    }
    
  //get side 2
    public double getSide2()
    {
        return side2;
    }
    
  //get side 3
    public double getSide3()
    {
        return side3;
    }

 //get the area
  public double getArea()
    {
    return .5 * side1 * side2;
    }

  //get the perimeter
  public double getPerimeter()
    {
   return side1 + side2 + side3;
    }

public String toString()
  {
   return "Triangle: side1 = " + side1 + "side 2 = " + side2 + "side 3 = " + side3;
   }

public String getType()

String "type";

  {
    if(side1 == side2 || side1 == side3 || side2 == side3)
     {
      if(side1 == side2 && side2 == side3) type = "Equilateral";
      else type = "Isosceles";
       } 
    else
      {
    type = "Scalene";
    }
    return type;
  }
}

i know it probably sucks but i'm drowning & the last Final & class is tonight. any other hints?

First of all you don't instantiate the Triangle inside the main
The getArea() is totally wrong. The formula you are using is only for triangles with 90 degrees.
The Double.parseDouble throws a NumberFormatException. Use try-catch
And you don't declare type inside getType()

This article has been dead for over six months. Start a new discussion instead.