Triangle type issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Laharl
    Recognized Expert Contributor
    • Sep 2007
    • 849

    #16
    Your problem is that you never actually assign triangleType, the string data, to be equal to the return value of triangleType(), the function. So every time you print triangleType the variable, you get null since you never defined it to be anything.

    Make triangleType private and call it as part of your constructor, with a statement like

    [code=java]
    triangleType = triangleType(s1 , s2, s3);
    [/code]
    Last edited by Ganon11; Oct 8 '07, 02:30 AM. Reason: Fixing [CODE] tags.

    Comment

    • lost1
      New Member
      • Oct 2007
      • 14

      #17
      Originally posted by Laharl
      Your problem is that you never actually assign triangleType, the string data, to be equal to the return value of triangleType(), the function. So every time you print triangleType the variable, you get null since you never defined it to be anything.

      Make triangleType private and call it as part of your constructor, with a statement like

      [code=java]
      triangleType = triangleType(s1 , s2, s3);
      [/code]
      I tried changing triangleType to private and I get an error and the same result "null". How do I go about making it private? Yeah, I know you change public to private, but I apparently can't do anything right with this.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #18
        Originally posted by lost1
        I tried changing triangleType to private and I get an error and the same result "null". How do I go about making it private? Yeah, I know you change public to private, but I apparently can't do anything right with this.
        Changing the access modifiers has nothing to do with it.
        Go through your code and dry run it. At each statement write down the values of all the variables.

        Comment

        • howrandom
          New Member
          • Oct 2008
          • 1

          #19
          Originally posted by lost1
          if(side1 == side2 && side2 == side3)
          type = "Equilatera l";

          else if(side1 == side2 && side2 != side3)
          type = "Isoscelese ";

          else if(side1 == side3 && side2 != side3)
          type = "Isoscelese ";

          else if(side1 != side3 && side2 == side3)
          type = "Isoscelese ";

          else
          type = "Scalene";

          return type;
          [/CODE]
          what do != and == mean?

          Comment

          • Nepomuk
            Recognized Expert Specialist
            • Aug 2007
            • 3111

            #20
            Originally posted by howrandom
            what do != and == mean?
            a != b means "a is not equal to b" while "a == b" is the exact opposite. You can however only reliably compare primitive objects (e.g. int, double, boolean,...) with these, not Objects (e.g. String, Thread, Exception,...).

            Just a tip: To compare Objects, you would have to use the equals method. This article shows you how to do that for your own classes.

            Greetings,
            Nepomuk

            Comment

            Working...