• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

are triangles congruent?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, i`m a begginer in java.
i need to write a program using only the main metod to calculate if triangles are congruent,
using boolean if triangles are congruent it will give me true
else it give me faulse.

please if someone can help me with the writing i will Appreciate

i wrote my own code but i got stuck and i cant undestand why?

here the code:

 
Marshal
Posts: 8863
637
Mac OS X VI Editor BSD Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Indentation
2. Formatting

3. You can't check equality with a single '=', to evaluate boolean type you need to use '==' (without single quotes).

Have you learned about how to define and use methods yet?
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Floating point values are not precise.  If you ever try adding 0.01 to itself 10 times, you might be surprised when you print out the final sum...

You'll might have the same issue when you calculate your square roots and compare them - i'm not sure.

this statement is attrocious, even if it were written correctly:



it is not obvious at ALL what you are trying to do here. I'm guessing you're trying to prove the two triangles are congruent with the SSS theorem. However, I think your logic is flawed..

Let AB = 3, BC = 3, AC = 3.

Let DE = 3, DF = 5, DF = 3

so now, AB == DE is true,  AC == DE true , and BC == DE is true.  Your boolean will evaluate to true, but clearly the triangles are not congruent.
 
Leon finkel
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:1. Indentation
2. Formatting

3. You can't check equality with a single '=', to evaluate boolean type you need to use '==' (without single quotes).

Have you learned about how to define and use methods yet?



i only started few days ago, what do you mean by methods?
any way i was told to create this program using only main method.

i didn`t fully understand about Indentation, if you can give me any tips it will ba Awesome
 
Liutauras Vilda
Marshal
Posts: 8863
637
Mac OS X VI Editor BSD Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Indentaion bad (your way)

Indendation good


Formatting bad (your way)

Formatting good
 
Leon finkel
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

fred rosenberger wrote:Floating point values are not precise.  If you ever try adding 0.01 to itself 10 times, you might be surprised when you print out the final sum...

You'll might have the same issue when you calculate your square roots and compare them - i'm not sure.

this statement is attrocious, even if it were written correctly:



it is not obvious at ALL what you are trying to do here. I'm guessing you're trying to prove the two triangles are congruent with the SSS theorem. However, I think your logic is flawed..

Let AB = 3, BC = 3, AC = 3.

Let DE = 3, DF = 5, DF = 3

so now, AB == DE is true,  AC == DE true , and BC == DE is true.  Your boolean will evaluate to true, but clearly the triangles are not congruent.



how can i rewrite so it wiil be more correctly?
Maybe use the "NOT !" boolean?
 
Liutauras Vilda
Marshal
Posts: 8863
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you can't get indentation and formatting right, or worse, don't want to - need to consider if you want to continue.
Other tasks are way more complex and way more complicated. Indentation and formatting are the easiest things you can assure are correct in your code.
 
Leon finkel
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you Liutauras Vilda

i will repair it, if you have more tips it will help
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Leon finkel wrote:
how can i rewrite so it wiil be more correctly?
Maybe use the "NOT !" boolean?


Maybe...but guessing it the worst way to write code. There are millions of ways to code this incorrectly, so if you guess, you're going to be spending a lot of time coding wrong guesses, and may never find a correct one.

Writing code is about 90% thinking, and 10% typing.  So the best advice would be to turn off your computer.  Get some paper and a few pencils.  An eraser is a very handy tool. Start writing out how YOU, personally, would proove two triangles are congruent.  Write out every single step.

Then, show that list to a 10year old. See if they can follow your instructions. If not, revise them, making each step simpler and simpler (and probably creating more steps as you go).

Once you can do that, THEN you can start writing the code.
 
Saloon Keeper
Posts: 10732
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have two thoughts on your code.

1) If you are taking int's as input and want to compare lengths precisely you should be able to do it using only integer arithmetic. Something like
and then compare the squared values to see if they are the same. Using int's has the drawback of not being able to specify arbitrary orientation, ie rotated at any angle. This would probably suffice for your assignment.

2) You can use doubles for both your input and your calculations. That will solve the arbitrary rotation problem but introduce the problem of comparing two doubles for "equality" while taking rounding errors into account. This is an advanced topic.
reply
    Bookmark Topic Watch Topic
  • New Topic