Results 1 to 9 of 9

Thread: Triangle

  1. #1
    jkswebsite is offline Member
    Join Date
    Nov 2007
    Posts
    12
    Rep Power
    0

    Default Triangle

    blah blah blah blah
    Last edited by jkswebsite; 03-23-2011 at 09:39 AM.

  2. #2
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    8

    Default

    You've got pretty detailed instructions - there shouldn't be much confusion on your part, break out the old algebra/trig book and get started. I mean, you've even got a runner class that implies the output you're supposed to receive.. think about this for a second, how difficult can this be?

    Btw, thanks for the message - but you're better off posting a thread such as you did here and chances are you'll get more responses, unless I was the only one you messaged. I'm not interested in doing other people's work, but I am interested in helping others learn the language. Your problem is not a Java problem, but a motivational problem. Why do you believe you can't do this?
    Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
    Want to voice your opinion on your IDE/Editor of choice? Vote now!
    Got a little Capt'n in you? (drink responsibly)

  3. #3
    jkswebsite is offline Member
    Join Date
    Nov 2007
    Posts
    12
    Rep Power
    0

    Default

    I don't really understand much java. I just need to hear what format to put it in..

    (if statement..etc.)
    Last edited by jkswebsite; 01-14-2008 at 12:33 AM.

  4. #4
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    8

    Default

    Then start here.
    Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
    Want to voice your opinion on your IDE/Editor of choice? Vote now!
    Got a little Capt'n in you? (drink responsibly)

  5. #5
    jkswebsite is offline Member
    Join Date
    Nov 2007
    Posts
    12
    Rep Power
    0

    Default

    this is the most recent code I have. I'M SO CLOSE!

    /**
    * Class triangle
    */

    public class Triangle {

    private int a;
    private int b;
    private int c;

    /**
    * Default constructor that creates an equilateral Triangle with side length
    * 1.0
    */

    public Triangle() {
    a = (int) 1;
    b = (int) 1;
    c = (int) 1;
    }

    /**
    * Another constructor that takes three int parameters that will be the
    * three side lengths. It must validate the three parameters that they can
    * actually form a triangle. (recall from Geometry: the sum of any two sides
    * of a triangle must be greater than the third side) The constructor must
    * throw an IllegalArgumentException if the parameters are invalid.
    * @return
    *
    * @return
    */

    public Triangle(int d, int e, int f) {
    if (d + e > f && e + f > d && f + e > d) {
    a = d;
    b = e;
    c = f;
    } else {
    throw new IllegalArgumentException("cannot form a triangle with values "+ a +","+ b +","+ c);
    }


    }

    /**
    * Method called getLongestSide that takes no parameters and returns the
    * value of the longest side length. (i.e. the greatest of a,b, and c)
    */

    public int longestSide() {
    if (a >= b && a >= c)
    return a;
    else if (b >= a && b >= c)
    return b;
    else
    return c;
    }

    /**
    * Method called isRightTriangle that takes no parameters and returns true
    * if the Triangle, (whose sides are a,b, and c) form a right triangle and
    * returns false otherwise. (hint: use Pythagorean Theorem and recall the
    * longest side is the hypotenuse)
    */

    public boolean isRightTriangle() {
    if (a * a + b * b == c * c)
    return true;
    else
    return false;
    }

    /**
    * Method called scalar that takes an int parameter and converts this
    * Triangle to a similar Triangle by multiplying each side length by the
    * parameter.
    */

    public void scalar(int i) {
    a = a * i;
    b = b * i;
    c = c * i;
    }

    /**
    * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    * BONUS! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    *
    */

    {
    /**
    * Method called isCongruentTo that takes a Triangle parameter and
    * returns true if all three 'corresponding' sides are equal, and
    * returns false otherwise. (example: 3,4,5 is congruent to 3,5,4 but
    * not congruent to 3,3,5)
    */

    // INSERT CODE HERE
    }

    {
    /**
    * Write a method called area that returns the area of this Triangle
    */

    // INSERT CODE HERE
    }

    }
    this is the output I get:

    1
    5
    6
    false
    true
    false
    10
    50
    60
    false
    true
    false

    this is the output you're SUPPOSED to get:

    1
    5
    6
    false
    true
    false
    10
    50
    60
    false
    true
    false
    Exception in thread "main" java.lang.IllegalArgumentException: cannot form a tri
    angle with values 3,9,4
    Triangle t4 = new Triangle(3,9,4);
    the problem is my t4 in my TriangleRunner.java class isn't being read for some reason.

    any ideas?
    Last edited by jkswebsite; 01-14-2008 at 02:15 AM.

  6. #6
    jkswebsite is offline Member
    Join Date
    Nov 2007
    Posts
    12
    Rep Power
    0

    Default

    I Got It!!!! Thanks!!

  7. #7
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    8

    Default

    I haven't read over your final result, but I'll assume that you got it correct and are satisfied with your work. Congratulations on figuring it out and I hope that maybe you learned that this can be fun, if not now maybe you will in the near future. :) Aren't you glad you figured it? Deriving the solution for oneself is typically found to be more fun than acquiring the solution from someone else.

    Cheers
    Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
    Want to voice your opinion on your IDE/Editor of choice? Vote now!
    Got a little Capt'n in you? (drink responsibly)

  8. #8
    jalpa is offline Member
    Join Date
    Jan 2009
    Posts
    2
    Rep Power
    0

    Smile

    hiiii all....
    I am new to this community ....n java too....
    I m so eager too learn it.....:)

  9. #9
    jalpa is offline Member
    Join Date
    Jan 2009
    Posts
    2
    Rep Power
    0

    Question

    Which of the following are true with respect to swings?

    1) They are the part of awt package.
    2) Swings are extended from the package container.
    3) They are the part of javax package.
    4) Each swing component has a separate jar file.


    I think 2,3 but not sure whether 2 is correct or not

Similar Threads

  1. change the square to triangle java
    By anotsu in forum New To Java
    Replies: 3
    Last Post: 07-09-2009, 11:17 AM
  2. Replies: 0
    Last Post: 04-12-2008, 08:39 PM
  3. Making triangle
    By banie in forum New To Java
    Replies: 4
    Last Post: 02-02-2008, 11:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •