# differ by at most 10-6

Christian Staves

Greenhorn

Posts: 26

posted 6 years ago

1) 10^-6 isn't allowed in Java. Use Math.pow(10, -6) instead.

2) Math.abs takes a number; that == would turn it into a float.

3) you need to check if the difference is at most 10^-6. Difference means subtraction.

With these hints you should be able to work it out.

2) Math.abs takes a number; that == would turn it into a float.

3) you need to check if the difference is at most 10^-6. Difference means subtraction.

With these hints you should be able to work it out.

SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6

How To Ask Questions How To Answer Questions

Campbell Ritchie

Sheriff

Posts: 50171

79

posted 6 years ago

Surely

But it is allowed. It means to take the bitwise XOR of the numbers 10 and -6. Probably not what the original poster intended howeverRob Prime wrote:1) 10^-6 isn't allowed in Java. Use Math.pow(10, -6) instead. . . .

Surely

`1e-6`is a quicker way to express that exponential? And the

`==`operator would return a boolean, which the compiler would notice and complain about.

Christian Staves

Greenhorn

Posts: 26

posted 6 years ago

Ok, so it runs and compiles and the tester works, do you guys see anything I messed up on ? Im pretty sure its correct, I mean it runs...

So after testings, my isSquare method is still broken. Did I not do it correctly?

a tester class (RectangleTester) that creates the following three rectangles.

1. a = 100.0 and b = 200.0

2. a = 100.0 and b = 100.0

3. a = 0.0 and b = 100.0

Could I just do Rectangle myRec1 = new Rectangle( 100.0, 200.0) would these values corrospond to a&b?

Its running for me, do you guys see anything wrong in my code.

Ok, so it runs and compiles and the tester works, do you guys see anything I messed up on ? Im pretty sure its correct, I mean it runs...

So after testings, my isSquare method is still broken. Did I not do it correctly?

a tester class (RectangleTester) that creates the following three rectangles.

1. a = 100.0 and b = 200.0

2. a = 100.0 and b = 100.0

3. a = 0.0 and b = 100.0

Could I just do Rectangle myRec1 = new Rectangle( 100.0, 200.0) would these values corrospond to a&b?

Its running for me, do you guys see anything wrong in my code.

posted 6 years ago

There is one small flaw in that logic. Your professor asked for

Christian Staves wrote:

There is one small flaw in that logic. Your professor asked for

*at most*, you are checking for

*exactly*. Change the == into <=.

SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6

How To Ask Questions How To Answer Questions

Christian Staves

Greenhorn

Posts: 26

posted 6 years ago

I'd write that like this:

You can use the notation "1e-6" which is just a numeric literal that means "10 to the power -6", or "0.000001". No need to call a method (Math.pow()).

Also,

I'd write that like this:

You can use the notation "1e-6" which is just a numeric literal that means "10 to the power -6", or "0.000001". No need to call a method (Math.pow()).

Also,

`if (...) return true; else return false;`is unnecessarily verbose - the expression already returns a boolean value, no need to check that boolean value in an if-statement and then return true or false. Just return the value of the expression directly.

posted 6 years ago

I left the Math.pow because it may be easier to read for beginning programmers. And yes, I admit, initially I forgot all about the E way to declare constants

Jesper Young wrote:You can use the notation "1e-6" which is just a numeric literal that means "10 to the power -6", or "0.000001". No need to call a method (Math.pow()).

I left the Math.pow because it may be easier to read for beginning programmers. And yes, I admit, initially I forgot all about the E way to declare constants

SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6

How To Ask Questions How To Answer Questions