Page 3 of 4 FirstFirst 1234 LastLast
Results 41 to 60 of 68
  1. #41
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    Quote Originally Posted by Atia of the julii View Post
    Curmudgeon, I understand that 4+2=6 and the base is 10 so the total of the non-base sides would have to equal 10 for it to be a triangle.
    Not quite. If the total = 10, then the two short sticks will lay directly on top of the base when they connect, and the resulting "triangle" will have no area. You'll have a line segment but not a true triangle. To get a true triangle with area, the two short segments added together must be greater than 10. Can you visualize why this is so?

    In fact to generalize for any two segments of the triangle, added together they must be greater than the third.

  2. #42
    Join Date
    Nov 2010
    Posts
    87
    Rep Power
    0

    Default

    Ah now I do feel stupid, what was I thinking?! I get it, and have reversed my true and false statements, hopefully atleast that part is now correct.

    The only error I have coming up on eclipse is on line 20 Line 20 ' else continue;} '
    It's saying insert '}' to finish block but I do this an the error remains, any ideas?

    I don't know if you saw the original question at the start of this topic (it's been so long I can barely remember what I'm trying to do myself :P) but I am trying to output the simple table of

    A B C AREA
    * * * *
    * * * *

    when I run the program, I am hoping and praying I have done all I needed to do now... do I just need to add System.out.println's at the end?

    (No doubt it won't be that easy!)

    Java Code:
    public class TriangleArea {
    
    	public static void main( String[] args )
    	{}
    		
    		int a;
    		int b;
    		int c;
    		boolean isTriangle;{
    		if ( (a+ b <= c) & (b + c <= a) & (a + c <= b) )
    		{isTriangle = false;}
    		else
    		{isTriangle = true;}
    		{
    		   for (a= 1; a <= 20; a++) {
    			   for (b= a; b <= 20; b++) {
    			      for ( c= b; c <= 20; c++){
    			      
    			    	  if ((a < b+c) && (b < a+c) && (c < a+b)) break;
    			    	  else continue;}
    			    		  
    			      
    			      
    			      }
    			         public static double area(double a, double b, double c){
    				    	   double s = Math.sqrt( (a + b + c) / 2 ) ;
    				    	   s = s * (s - a) * ( s - b ) * (s - c );
    				    	   return s;
    			      }
    	}

  3. #43
    Join Date
    Nov 2010
    Posts
    87
    Rep Power
    0

    Default

    Ok I no longer have any errors in the code above and I can run it but nothing is yet printed. Can someone help me to input the code for it to display the table roughly like this with results.

    *******************************************
    * a * b * c * area *
    *******************************************
    * 1 * 1 * 1 * … *
    * 1 * 2 * 2 * … *
    * 1 * 3 * 3 * … *
    * 1 * 4 * 4 * … *

    Thanks :)

  4. #44
    Join Date
    Nov 2010
    Posts
    87
    Rep Power
    0

    Default

    My last line says the code is unreachable... Someone please help before I lose my mind :(
    Java Code:
    public class TriangleArea
     {
    public static void main( String[] args )
    	{}
    		
    	int a;
    	int b;
    	int c;
    	boolean isTriangle;
    {
    	if ( (a+ b <= c) & (b + c <= a) & (a + c <= b) )
    {
            isTriangle = false;
    }
    		else
    		{
    isTriangle = true;
                     }
    		{
              for (a= 1; a <= 20; a++)
    {
              for (b= a; b <= 20; b++)
     {
    	 for ( c= b; c <= 20; c++)
    {
    			      
    	 if ((a < b+c) && (b < a+c) && (c < a+b)) break;
    			    	 
     else continue;}}}}
    			      }
            public static double area(double a, double b, double c)
    {
    	 double s = Math.sqrt( (a + b + c) / 2 ) ;
    
    	 double area = s * (s - a) * ( s - b ) * (s - c );
    				    	 
               return  area;
    				    	 
                  System.out.println(a + " [" + b + "] " + "| " + c + " [" + area + "]");
    Last edited by Atia of the julii; 11-08-2010 at 02:39 AM.

  5. #45
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    For the love of all things good, please edit that code above and fix the indentations. No one can tell if code is in the proper location with your creative indentation. To see how to properly indent, please read a guide on this such as this one: Java Style Guide: Home Page

  6. #46
    Join Date
    Nov 2010
    Posts
    87
    Rep Power
    0

    Default

    I've done what you instructed, it will be second nature for me soon, but for now it's all uncharted territory.

    Please help me finish this horrible thing :)

    Atia

  7. #47
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    Quote Originally Posted by Atia of the julii View Post
    I've done what you instructed, it will be second nature for me soon, but for now it's all uncharted territory.
    ** sob! **

  8. #48
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    I can at least see that you've got a line of code after a return statement, so the compiler is rightfully complaining that that line will never be reached.

    But still, that code is so terribly formatted that it should be taken out back and shot just to put it and us out of misery.

  9. #49
    Join Date
    Nov 2010
    Posts
    87
    Rep Power
    0

    Default

    Curmudgeon, you're not being very helpful just telling me how bad you think my formatting is, I have tried to clean it up and now I need actual serious help with the code itself because it's not working. I will make it look pretty when it works!

    Java Code:
    public class TriangleArea
     {
    public static void main( String[] args )
    	{}
    		
    	int a;
    	int b;
    	int c;
            int area;
    	boolean isTriangle;
    {
    	if ( (a+ b <= c) & (b + c <= a) & (a + c <= b) )
    {
            isTriangle = false;
    }
    		else
    		{
    isTriangle = true;
                     }
    		{
              for (a= 1; a <= 20; a++)
    {
              for (b= a; b <= 20; b++)
     {
    	 for ( c= b; c <= 20; c++)
    {
    			      
    	 if ((a < b+c) && (b < a+c) && (c < a+b)) break;
    			    	 
     else continue;}}}}
    
    System.out.println(a + " [" + b + "] " + "| " + c + " [" + area + "]");
    			      }
            public static double area(double a, double b, double c)
    {
    	 double s = Math.sqrt( (a + b + c) / 2 ) ;
    
    	 double area = s * (s - a) * ( s - b ) * (s - c );
    				    	 
               return  area;

  10. #50
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default

    This is going to be story without end; the OP doesn't even know Java's basic syntax and I strongly advise to study at least a few tutorials first before attempting to code anything at all. The way it is going now are just random tries where the OP hopes for the best without any knowledge. I'll give this code away hoping that the OP at least studies it and learns something from it; I left out all comments and I'm not going to spoonfeed the OP again.

    kind regards,

    Jos

    the code:

    Java Code:
    public class T {
    	
    	private static boolean lengthConstraint(int a, int b, int c) {
    
    		return a+b+c <= 20;
    	}
    	
    	private static boolean triangleConstraint(int a, int b, int c) {
    		
    		return a+b > c && a+c > b && b+c > a;
    	}
    	
    	private static double area(int a, int b, int c) {
    		
    		double s= (a+b+c)/2.0;
    		
    		return Math.sqrt(s*(s-a)*(s-b)*(s-c));
    	}
    	
    	public static void main(String[] args) {
    		
    		for (int a= 1; a <= 20; a++) {
    			for (int b= a; b <= 20; b++) {
    				for (int c= b; c <= 20; c++) {
    					if (!lengthConstraint(a, b, c)) break;
    					if (!triangleConstraint(a, b, c)) continue;
    					System.out.println(a+" "+b+" "+c+" "+area(a, b, c));
    				}
    			}
    		}
    	}
    }

  11. #51
    Join Date
    Nov 2010
    Posts
    87
    Rep Power
    0

    Default

    Jos,

    I am incredibly grateful, I will definitely invest in some better text books and start at the beginning again! I thought I was doing quite well but this has taught me i'm far from it! I will study this code in depth and try some similar exercises and reference this.

    Thankyou to everyone who helped me, especially you Jos! I'm hoping I can help others soon on here (not1 laugh at that)

    Atia x

  12. #52
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Atia of the julii View Post
    Jos,

    I am incredibly grateful, I will definitely invest in some better text books and start at the beginning again! I thought I was doing quite well but this has taught me i'm far from it! I will study this code in depth and try some similar exercises and reference this.
    Good; try to answer the following questions as well:

    - why did I break out of the inner loop completely when the length constraint was violated?

    - why did I simply continue the next loop pass when the triangle constraint was violated?

    - why are there no equivalent triangles generated, i.e. if 1, 2, 3 is generated, why isn't, say, 3, 2, 1 generated?

    - why are those constraints implemented as boolean methods?

    - why are all those methods static?

    - why is main a public method and why did I make the other methods private?

    - why is 's' in the area method of type double while a, b and c are of type int?

    - can you improve the printout? My version doesn't neatly allign the columns.

    - can you write the same code without all those little methods? What does all your code in the main( ... ) method look like? A mess?

    - why are all those constraint tests actually necessary?

    No need to supply all the answers here (I already know the answers ;-) but feel free to ask questions here.

    kind regards,

    Jos

  13. #53
    Join Date
    Nov 2010
    Posts
    87
    Rep Power
    0

    Default

    Jos, by far one of the most helpful people i've ever come across on the internet!

    Thanks for listing the questions, they'll really help if I go through it logically

    :-)

  14. #54
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Quote Originally Posted by Atia of the julii View Post
    Curmudgeon, you're not being very helpful just telling me how bad you think my formatting is, I have tried to clean it up and now I need actual serious help with the code itself because it's not working. I will make it look pretty when it works!
    It's not about making it pretty, though.
    It's about making it readable.
    That's why we hve (fairly) standardised formatting rules (give or take)...
    If I format your code from this post the "normal" way I think you might see your problem:

    Java Code:
    public class TriangleArea {
        public static void main( String[] args ) {
        }
    
        int a;
        int b;
        int c;
        int area;
        boolean isTriangle;
    
        {
            if ( (a+ b <= c) & (b + c <= a) & (a + c <= b) ) {
                isTriangle = false;
            } else {
                isTriangle = true;
             }
        {
        for (a= 1; a <= 20; a++) {
            for (b= a; b <= 20; b++)
        {
        for ( c= b; c <= 20; c++) {
            if ((a < b+c) && (b < a+c) && (c < a+b)) break;
            else continue;
        }
    }
    }
    }
    
        System.out.println(a + " [" + b + "] " + "| " + c + " [" + area + "]");
        public static double area(double a, double b, double c) {
            double s = Math.sqrt( (a + b + c) / 2 ) ;
            double area = s * (s - a) * ( s - b ) * (s - c );
            return  area;
    As you can see, lining everything up the way it should be, with brackets where they should be, indented properly, it's clear that the above is a mess.

  15. #55
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Atia of the julii View Post
    Curmudgeon, you're not being very helpful just telling me how bad you think my formatting is, I have tried to clean it up and now I need actual serious help with the code itself because it's not working. I will make it look pretty when it works!
    If you are asking unpaid volunteers free help, don't you think it's in your best interest to make it easy for other's to understand your code and help you?

  16. #56
    Join Date
    Nov 2010
    Posts
    87
    Rep Power
    0

    Default

    Absolutely I do, which is why I listened to Curmudgeon the first time, went back and edited all of my code to make it much easier to read. His response was to tell me yet again how awful it was and how it should be taken somewhere and shot (Knowing full well how inexperienced I am).

    Between that and mocking me for not being good enough at maths, it seems clear to me that this user is someone who would rather mock, patronise and insult a beginner who is struggling than actually offer any real help. Especially when there are fantastic individuals like JosAH who do not condescend or judge but in fact take the time to truly help people.

  17. #57
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Please re-read the link he gave you though because your formatting is still way off, enough that it makes it difficult to understand your code.

  18. #58
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Quote Originally Posted by Atia of the julii View Post
    Absolutely I do, which is why I listened to Curmudgeon the first time, went back and edited all of my code to make it much easier to read. His response was to tell me yet again how awful it was and how it should be taken somewhere and shot (Knowing full well how inexperienced I am).

    Between that and mocking me for not being good enough at maths, it seems clear to me that this user is someone who would rather mock, patronise and insult a beginner who is struggling than actually offer any real help. Especially when there are fantastic individuals like JosAH who do not condescend or judge but in fact take the time to truly help people.
    He's not called curmudgeon for nothing, you know...;)

    Besides, as Fubarable says, if you had actually read his link on how to format Java code then you would see that your second attempt was no better.

    SOmething you would also see from the code I posted. Formatted code helps you as much as us. For starters you can see which brackets match and which don't.

  19. #59
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default

    I wasn't really being nice actually; I foresaw a replay of another thread that took more than 120 replies and the OP didn't know basic Java syntax either despite his protests. I didn't want all the agony and irritation again so I bluntly spoonfed this op hoping that the op would learn something from it.

    In my experience a step by step approach only works here when the individual steps are so small that the entire thread will bore the repliers to death and the thread itself dies. This forum is not a school; some people really have to study the (sub) basics before they can even attempt to code something; my opinion is to be over and done with those threads by simply supplying the complete answer (or by ignoring the thread).

    So, as a matter of fact, I was trying to be nice to everyone ;-)

    kind regards,

    Jos

  20. #60
    Join Date
    Nov 2010
    Posts
    87
    Rep Power
    0

    Default

    For the record, i'm a 'she' not a 'he' and as much as I am grateful for all of the help I have received, (as I have repeatedly said) this is all going too far. There are sadly some very unfriendly individuals on this forum who like to drag things on for dramatic effect, perhaps because they don't have much going on outside of this forum.

    Jos, I am a 26 year old woman who treats people with kindness and respect, I should not have to login to this forum to read on multiple posts how you have 'spoonfed' me over and over, how 'agonising' and 'irritating' I am and how I am 'boring people to death'. I am eternally sorry for sincerely thanking you for your help, it is quite clear to me from reading your post that you are terrified of 'moderator' Fubarable... the word sycophant comes to mind. Also, referring to me in the third person every 2 seconds (OP, OP...OP) is incredibly rude but that seems to be the theme for some of you.

    I am far too insulted to use this forum ever again you will be delighted to know but a friendly suggestion to a couple of you.... try and get out into the real world now and then and learn how to speak to people in a dignified manner.

    Please don't bother to write more derogatory things about me, I shall not be back to read it.

Page 3 of 4 FirstFirst 1234 LastLast

Similar Threads

  1. Replies: 0
    Last Post: 08-11-2010, 09:19 AM
  2. Laptop Help
    By Lil_Aziz1 in forum Forum Lobby
    Replies: 9
    Last Post: 08-08-2010, 06:04 PM
  3. Access Macaddress on laptop
    By dhaivat in forum AWT / Swing
    Replies: 0
    Last Post: 07-11-2010, 03:49 PM
  4. AWT: Painting buttons and text areas in a canvas
    By chappa in forum AWT / Swing
    Replies: 6
    Last Post: 01-09-2010, 03:37 PM
  5. text areas, printstream, and "\n"
    By diggitydoggz in forum New To Java
    Replies: 10
    Last Post: 12-26-2008, 05:03 PM

Posting Permissions

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