Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Need Help with code ...beginner

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need Help with code ...beginner

    Hello, I have tried everything and my code won't do what it needs to can someone explain this to me D:!?

    Write a Java program that computes the area of a scalene triangle. Use the input dialog box to get the sides a, b, and c of the scalene triangle and compute the area using the following equation;
    Area = (s (s – a) (s - b) (s – c) )1/2 where s=(a+b+c)/2
    Your program must check that none of the length of the sides (a,b,c) is <= 0 and s > a and s > b and s > c. The output must be displayed in the message dialog box. (hint: you may use math class methods if needed).

    and heres what I have....


    import javax.swing.JOptionPane;

    public class Assignment3
    {
    public static void main(String[] args)
    {
    double sideA;
    double sideB;
    double sideC;
    double s;
    double Area;
    String input;

    input =
    JOptionPane.showInputDialog("Enter side A"); //input box for side A
    sideA = Double.parseDouble (input);

    input =
    JOptionPane.showInputDialog("Enter side B"); //input box for side B
    sideB = Double.parseDouble (input);

    input =
    JOptionPane.showInputDialog("Enter side C"); //input box for side C
    sideC = Double.parseDouble (input);


    s = (sideA + sideB + sideC) / 2; //finds what s is = to

    JOptionPane.showMessageDialog (null, "s is equal to " + s);



    Area = Math.pow (s*(s - sideA)*(s - sideB)*(s - sideC),1/2); //finds the area


    JOptionPane.showMessageDialog (null,"Area is equal to " + Area);

    //checks to see the each side is less then or equal to 0

    if (sideA <= 0)

    JOptionPane.showMessageDialog (null, " A is less then 0");

    if (sideB <= 0)

    JOptionPane.showMessageDialog (null, " B is less then 0");

    if (sideC <= 0)

    JOptionPane.showMessageDialog (null, "C is less then 0");


    System.exit(0);
    }
    }


  2. #2
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Need Help with code ...beginner

    Are you getting errors (post them!), or do you not know how to continue? Please be specific in the description of your problem.
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need Help with code ...beginner

    I think I got it right...we'll see when i get my grade back XD


    import javax.swing.JOptionPane;

    public class Assignment3
    {
    public static void main(String[] args)
    {
    double sideA;
    double sideB;
    double sideC;
    double s;
    double Area;
    String input;


    input =
    JOptionPane.showInputDialog("Enter side A"); //input box for side A
    sideA = Double.parseDouble (input);

    input =
    JOptionPane.showInputDialog("Enter side B"); //input box for side B
    sideB = Double.parseDouble (input);

    input =
    JOptionPane.showInputDialog("Enter side C"); //input box for side C
    sideC = Double.parseDouble (input);

    //calculates s
    s = (sideA + sideB + sideC) / 2; //finds what s is = to

    JOptionPane.showMessageDialog (null, "s is equal to " + s);

    //checks to see that each side is less then s
    if (s > sideA && s > sideB && s > sideC)
    {
    JOptionPane.showMessageDialog (null, " All sides are less then s");
    }
    else
    {
    JOptionPane.showMessageDialog (null, " All sides are not less then s");
    }


    //calculates area
    Area = Math.sqrt (s*(s - sideA)*(s - sideB)*(s - sideC)); //finds the area


    JOptionPane.showMessageDialog (null,"Area is equal to " + Area);

    //checks to see that each side is less then or equal to 0
    if (sideA <= 0 && sideB <= 0 && sideC <= 0)
    {
    JOptionPane.showMessageDialog (null, " All sides are less then 0");
    }
    else
    {
    JOptionPane.showMessageDialog (null, " All sides are not less then 0");
    }



    System.exit(0);
    }
    }

  4. #4
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Need Help with code ...beginner

    Don't you want to check if ANY of the sides are less than zero BEFORE you calculate the area?
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

Similar Threads

  1. Beginner for Java, need help with this code I wrote
    By SilentNite17 in forum What's Wrong With My Code?
    Replies: 30
    Last Post: February 14th, 2012, 08:01 PM
  2. (beginner) if else code.
    By dumb1101 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 16th, 2012, 02:47 AM
  3. [SOLVED] What's wrong with my code?? (Total beginner)
    By TheProf in forum What's Wrong With My Code?
    Replies: 10
    Last Post: January 6th, 2012, 02:41 PM
  4. Please held. What is wrong with my code? I am a beginner ;)
    By mvonb17 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 30th, 2011, 05:33 PM
  5. Beginner - Help with my code.
    By eddross in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 12th, 2010, 09:30 AM