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.

Page 1 of 2 12 LastLast
Results 1 to 25 of 29

Thread: PLEASE HELP!!!!!!

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    17
    My Mood
    Inspired
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default PLEASE HELP!!!!!!

    I am new to java and really need help!!!!
    I need to create a:
    1. class triangle with a method to find the area of a triangle using three sides, only if they form a valid triangle.Otherwise display a message "Triangle cannot be formed".
    2. class shapes having three functions with my the same name findArea(), but difference in arguments list to find area of circle, square and rectangle.
    3. class to compute the profit or loss percentage based on the cost price and selling price of an item.


    Thank You,
    Regards Matt.

    I need these for my java project. PS:im only 13 yrs old .
    Please Help.

  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: PLEASE HELP!!!!!!

    What have you tried and where are you stuck? Suggested reading:
    How to Program - stuck on homework
    Help yourself get help

  3. The Following User Says Thank You to copeg For This Useful Post:

    haibhailie (January 30th, 2012)

  4. #3
    Junior Member
    Join Date
    Jan 2012
    Posts
    17
    My Mood
    Inspired
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: PLEASE HELP!!!!!!

    Well, im not getting stuck...lol
    i dont know how to do them for i was absent when the explanation was going on sir.

  5. #4
    Junior Member
    Join Date
    Jan 2012
    Posts
    17
    My Mood
    Inspired
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: PLEASE HELP!!!!!!

    i do only small projects without the args etc.
    only like
    public static void diplay findResult(int n,int x)
    {
    /then like/ double a,b,c;
    /and then just system.out.println ...
    thats it.
    thank you

  6. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: PLEASE HELP!!!!!!

    For future reference, you're going to want to provide more meaningful titles. We know you need help- what do you need help with? What have you tried? A title lets people know what's in the thread, so they know to click on questions they can answer. Keeping it generic and saying "need help", not to mention shouting at us, will actually decrease your chances of getting help.

    That being said, simply saying "I wasn't there for the explanation" is not good enough. What do the basic tutorials and google tell you? Where exactly are you stuck? Where is your SSCCE?

    I recommend you read the link in my signature on asking questions the smart way, as well as this: http://www.javaprogrammingforums.com...e-posting.html
    Last edited by KevinWorkman; January 30th, 2012 at 11:54 AM.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. The Following User Says Thank You to KevinWorkman For This Useful Post:

    haibhailie (January 30th, 2012)

  8. #6
    Junior Member
    Join Date
    Jan 2012
    Posts
    17
    My Mood
    Inspired
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: PLEASE HELP!!!!!!

    thank you,
    i hadent seen that.

  9. #7
    Junior Member
    Join Date
    Jan 2012
    Posts
    17
    My Mood
    Inspired
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: PLEASE HELP!!!!!!

    i did the class triangle but am not getting the boolean part of it. I have got the part where find the area, but have not got where it tells us to say "triangle cannot be formed".
    My script until now is:

    class Triangle
    {
    public static void findArea(int a,int b, int c)
    {
    double x=a*b*c/2;
    double area= Math.sqrt(x*x-a*x-b*x-c);
    System.out.println("Area="+area);
    }
    }

  10. #8
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: PLEASE HELP!!!!!!

    Well, how would you do this without a computer?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  11. #9
    Junior Member
    Join Date
    Jan 2012
    Posts
    17
    My Mood
    Inspired
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: PLEASE HELP!!!!!!

    uhm, maybe just putting in the required things needed, and if it meets up, just give the area, and if it doesnt, say triangle cannot be formed....not quite get wht u mean though...

  12. #10
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: PLEASE HELP!!!!!!

    I mean, given three numbers, how do you determine whether or not they can form a triangle? When can't three sides form a triangle?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  13. #11
    Junior Member
    Join Date
    Jan 2012
    Posts
    17
    My Mood
    Inspired
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: PLEASE HELP!!!!!!

    when a+b<c
    b+c<a and a+c<b, triangle cannot be formed.

    but if instead of these, we use:a+b>c
    b+c>a and a+c>b
    ittl work.

  14. #12
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: PLEASE HELP!!!!!!

    Okay, so now that you've stated those, you can begin translating that to pseudocode and finally into actual Java.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  15. #13
    Junior Member
    Join Date
    Jan 2012
    Posts
    17
    My Mood
    Inspired
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: PLEASE HELP!!!!!!

    when two sides are greater than the other, a triangle can be formed. when they are not, it cannot.

  16. #14
    Junior Member
    Join Date
    Jan 2012
    Posts
    17
    My Mood
    Inspired
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: PLEASE HELP!!!!!!

    i havent actually learnt that if statement and boolean literal, thats wht i need help in.

  17. #15
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: PLEASE HELP!!!!!!

    Then that's a great place to start your google search. The first result here is to the basic tutorials, which I actually already told you to take a look at: https://www.google.com/search?q=java+if+statement
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  18. The Following User Says Thank You to KevinWorkman For This Useful Post:

    haibhailie (January 30th, 2012)

  19. #16
    Junior Member
    Join Date
    Jan 2012
    Posts
    17
    My Mood
    Inspired
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: PLEASE HELP!!!!!!

    omg...ty sooo much!!!! i got it!!!!! yay!!!

  20. #17
    Junior Member
    Join Date
    Jan 2012
    Posts
    17
    My Mood
    Inspired
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: PLEASE HELP!!!!!!

    ok, yh i didnt quite get it lol...

    my program:
    class Triangle
    {
    public static void findArea(int a,int b, int c)
    {
    if a+b>c,a+c>b,b+c>a
    {
    double x=a*b*c/2;
    double area= Math.sqrt(x*x-a*x-b*x-c);
    System.out.println("Area="+area);
    }
    {
    if a+b<c,a+c<b,b+c<a
    {
    System.out.print("Triangle cannot be formed");

    }
    }

    the error is on if a+b>c,a+c>b,b+c>a and it says "(' unexpected..

  21. #18
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: PLEASE HELP!!!!!!

    What syntax are you attempting to use? An if statement requires (parenthesis) around the expression, and you can't just throw a comma in. Did you read the basic tutorials at all, or just skim them?

    I suggest you do this in smaller steps. Write a separate test program that ONLY consists of an if statement with a single boolean expression. Run it. Does that work? If so, then try to write an if statement with compound expressions. Does that work? If so, try to implement it in your actual project. If not, post the SSCCE here.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  22. #19
    Junior Member
    Join Date
    Jan 2012
    Posts
    17
    My Mood
    Inspired
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: PLEASE HELP!!!!!!

    i got a script:

    class Triangle
    {
    public static void findArea(int a,int b, int c)
    {
    if (a+b>c);
    {
    double x=a*b*c/2;
    double area= Math.sqrt(x*x-a*x-b*x-c);
    System.out.println("Area="+area);
    }
    {
    elseif (a+c>b);
    {
    double x=a*b*c/2;
    double area= Math.sqrt(x*x-a*x-b*x-c);
    System.out.println("Area="+area);

    }
    elseif (b+c>a);
    {
    double x=a*b*c/2;
    double area= Math.sqrt(x*x-a*x-b*x-c);
    System.out.println("Area="+area);
    }

    elseif (a+b<c);
    {
    System.out.println("Triangle cannot be formed");
    }
    elseif (a+c<b);
    {
    System.out.println("Triangle cannot be formed");
    }
    elseif (b+c<a);
    {
    System.out.println("Triangle cannot be formed");
    }
    }
    }


    and the error is at the last curly bracket, it says reached end of file while parsing....
    Last edited by haibhailie; January 30th, 2012 at 01:18 PM. Reason: highliting

  23. #20
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: PLEASE HELP!!!!!!

    Well, you've got quite a few syntax errors there, and you haven't used the highlight tags, so I can't really tell which closing bracket lines up with which opening bracket. Make sure that they match up how you expect, and also, if statements shouldn't end with a semicolon.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  24. #21
    Junior Member
    Join Date
    Jan 2012
    Posts
    17
    My Mood
    Inspired
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: PLEASE HELP!!!!!!

    class Triangle
    {
    public static void findArea(int a,int b, int c)
    {
    if (a+b>c);
    {
    double x=a*b*c/2;
    double area= Math.sqrt(x*x-a*x-b*x-c);
    System.out.println("Area="+area);
    }

    if (a+c>b);
    {
    double x=a*b*c/2;
    double area= Math.sqrt(x*x-a*x-b*x-c);
    System.out.println("Area="+area);

    }
    if (b+c>a);
    {
    double x=a*b*c/2;
    double area= Math.sqrt(x*x-a*x-b*x-c);
    System.out.println("Area="+area);
    }

    if (a+b<c);
    {
    System.out.println("Triangle cannot be formed");
    }
    if (a+c<b);
    {
    System.out.println("Triangle cannot be formed");
    }
    if (b+c<a);
    {
    System.out.println("Triangle cannot be formed");
    }
    }
    }




    my final script, finally compiled and worked ^^ tysm kevin workman!!!!

  25. #22
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: PLEASE HELP!!!!!!

    Are you sure that works? You're still ending all of your if statements with a semicolon. And you still haven't used the highlight tags.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  26. #23
    Junior Member
    Join Date
    Jan 2012
    Posts
    16
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default Re: PLEASE HELP!!!!!!

    As Kevin said u still lack of some syntax; like for example think about joining some if, and put multiple conditions, u have two comands: "||" = or , "&&" = and, these are some of them, and cotting KevinWormand, watch out for the semicolons.

  27. #24
    Junior Member
    Join Date
    Jan 2012
    Posts
    17
    My Mood
    Inspired
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: PLEASE HELP!!!!!!

    I am now doing the 3rd question...
    my script till now is:
    class ProfitAndLoss
    {
    public static void findResult(int sp,int cp);
    {
    if (sp>cp);
    {
    double profit=sp-cp;
    double profit%=(profit/cp)*100;
    System.out.println("Profit Percent="+profit%);
    }
    if (cp>sp);
    { double loss,loss%;
    loss=cp-sp;
    loss%=(loss/cp)*100;
    System.out.println("Loss Percent="+loss%);
    }
    }
    }

    There is an error where i underlined it....really confusing and the error says ";"expected.....
    ong im going crazzzy!!!!
    Last edited by haibhailie; January 31st, 2012 at 09:28 AM.

  28. #25
    Junior Member
    Join Date
    Jan 2012
    Posts
    17
    My Mood
    Inspired
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: PLEASE HELP!!!!!!

    and wht are highlinght tags????

Page 1 of 2 12 LastLast