Leon finkel

Greenhorn

Posts: 6

posted 8 months ago

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:

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:

posted 8 months ago

- 1

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.

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.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

Leon finkel

Greenhorn

Posts: 6

posted 8 months ago

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 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

Leon finkel

Greenhorn

Posts: 6

posted 8 months ago

how can i rewrite so it wiil be more correctly?

Maybe use the "NOT !" boolean?

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?

Leon finkel

Greenhorn

Posts: 6

posted 8 months ago

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.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

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.

posted 8 months ago

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.

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.

Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.

It is sorta covered in the JavaRanch Style Guide. |