Show 40 post(s) from this thread on one page
Page 3 of 4 First 1234 Last
• 11-07-2010, 11:44 PM
curmudgeon
Quote:

Originally Posted by Atia of the julii
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.
• 11-07-2010, 11:54 PM
Atia of the julii
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!)

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;                               }         }```
• 11-08-2010, 12:14 AM
Atia of the julii
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 :)
• 11-08-2010, 02:21 AM
Atia of the julii
My last line says the code is unreachable... Someone please help before I lose my mind :(
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 + "]");```
• 11-08-2010, 02:27 AM
curmudgeon
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
• 11-08-2010, 02:42 AM
Atia of the julii
I've done what you instructed, it will be second nature for me soon, but for now it's all uncharted territory.

Atia
• 11-08-2010, 02:51 AM
curmudgeon
Quote:

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

** sob! **
• 11-08-2010, 02:55 AM
curmudgeon
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.
• 11-08-2010, 10:56 AM
Atia of the julii
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!

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;```
• 11-08-2010, 11:10 AM
JosAH
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:

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-08-2010, 12:29 PM
Atia of the julii
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
• 11-08-2010, 01:01 PM
JosAH
Quote:

Originally Posted by Atia of the julii
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?

kind regards,

Jos
• 11-08-2010, 02:49 PM
Atia of the julii
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

:-)
• 11-08-2010, 03:48 PM
Tolls
Quote:

Originally Posted by Atia of the julii
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.
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:

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.
• 11-08-2010, 07:01 PM
Fubarable
Quote:

Originally Posted by Atia of the julii
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?
• 11-08-2010, 09:17 PM
Atia of the julii
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.
• 11-08-2010, 11:31 PM
Fubarable
• 11-09-2010, 09:52 AM
Tolls
Quote:

Originally Posted by Atia of the julii
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.
• 11-09-2010, 10:02 AM
JosAH
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
• 11-10-2010, 04:57 PM
Atia of the julii
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.
Show 40 post(s) from this thread on one page
Page 3 of 4 First 1234 Last