• Post Reply Bookmark Topic Watch Topic
  • New Topic

Fix in Java  RSS feed

 
Richard Teran
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone I hope this finds you well

Please help I want something

I would like to help me with an exercise in java, I'm trying to do,


I have to fix this sentence in java,
And try it in many ways but I do not get it.
I would like you to help me please.







please help me. :D
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

First, your code is not formatted, and hence, difficult to read.

And second, your code, even if formatted, doesn't look valid. It just looks like random lines of code. 


So, what is your issue with it?

Henry
 
Richard Teran
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The exercise is messy and I need to order it to work properly.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Richard Teran wrote:The exercise is messy and I need to order it to work properly.


Seriously?!?!? That is the assignment? Reorder 29 lines of code so that it compiles and run correctly?  I understand ordering a few lines within a method, as you need to develop the logic to organize the code... but this seems more like a jigsaw puzzle, than an assignment designed for learning. What would be the purpose of the homework assignment?

Anyway, I guess I can help a bit. Line 9 and line 22 would likely be the first two lines of the program...

Henry
 
Richard Teran
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In fact if it is a puzzle.
It would be helpful if you could help me with that.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Richard Teran wrote:In fact if it is a puzzle.
It would be helpful if you could help me with that.


Well, when I do a jigsaw puzzle, I generally...

1. Start with the corners and edges.
2. Put the obvious pieces that fit together, and sort it in groups -- either by particular colors or obvious patterns.
3. Fill in the middle. Of course, at this point, your only context is the drawing itself. So, you will have to work it out here.

So... I guess, updated that plan for this, you can...

1. Start with the top and bottom. I already gave you the top in a previous post. The bottom would be the close brace for the class.
2. Put the obvious lines that fit together, and sort it in groups. These are the method definitions, and their close braces; the for/while loops and their close braces. etc.
2a. Sort the groups (and the rest of lines)... into the methods, loops, declarations, assignments, etc.
3. Fill in the code. Of course, at this point, you need to have context (which you haven't mentioned here, meaning what is the program supposed to do?). And unfortunately, like I said already, this is a very silly puzzle.... IMHO, at this point, it would be like programming, but you are completely limited on what you can do. So, you will have to work it out here.

Henry
 
Richard Teran
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I order you the following way.
There is no error, but instead at the time of execution it stays there and is not executed.


 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done getting that far

I managed to decipher the code, which is difficult to read because of the poorly‑chosen variable and method names, as far as line 11. Then it goes to the sqrt method. What does that method do? Will that ever allow the validate method to return true? I only knew it was a validate method because of what you wrote in the comments. And I can't speak Spanish.
 
Junilu Lacar
Sheriff
Posts: 11485
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like the program is trying to implement Newton's method for calculating the roots.

@OP, the end braces have end-of-line comments that tell you which block of code they terminate. You have them all mixed up. Normally, I say that end-of-block comments like that are useless but for this particular exercise, they should probably be considered as important clues for putting that line in its correct place.

Edit: you only have two of the ending braces switched. The other ones are correctly paired to their opening braces.
 
Junilu Lacar
Sheriff
Posts: 11485
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When solving a jigsaw puzzle, it's good to have an idea of what the solved puzzle will look like. The complete picture is usually on the box the puzzle pieces came in. For this problem, the big picture is solving for roots using Newton's method. Do you know what the algorithm for Newton's method is? If not, you need to if you want to solve this problem.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Also, when solving a jigsaw puzzle, it is a good idea to only use the pieces from the box -- throwing in pieces from another puzzle is just a bad idea... 

Anyway, where does the "return 0" pieces come from? They were not in the original puzzle box.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!