• Post Reply Bookmark Topic Watch Topic
  • New Topic

Having trouble fixing code  RSS feed

 
Cory Marcus
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

As a task, I've got some code with errors which needs to be fixed.

I've re-written a small section, but I can't seem to understand the rest.

Can someone please provide a few tips?

The area I'm struggling with is mainly the "this.value" sections.

Regards.

 
Rodion Gork
Ranch Hand
Posts: 47
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The area I'm struggling with is mainly the "this.value" sections

What do you mean by "struggling"? I see only one line containing "this.value" - in constructor. Obviously you just need to have the two sides of assignment swapped in order for this to have any sense - otherwise you are assigning unitialized value to variable which gets destroyed at the very next step.

I'm afraid that if such basic things give you serious trouble, you probably have quite insufficient practice with java. I dare to advice you to try a good book (like Schildt or Horstmann) and some set of small exercises / projects.
 
Cory Marcus
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the assistance Rodion Gork.

Unfortunately, I meant the (whatValue) section.

I had already altered the this.value line.

And I believe the ( ?) part in Println should be + value, or something along those lines.

My code looks like this now:

 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cory Marcus wrote:And I believe the ( ?) part in Println should be + value, or something along those lines.

You really shouldn't be "guessing" about stuff like this.

Have you tried compiling it? If so, what errors do you get? That should go a long way to telling you what you need to do.

I will give you one tip though: What is the type of 'whatValue'?

Winston
 
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
Winston Gutkowski wrote:
Cory Marcus wrote:And I believe the ( ?) part in Println should be + value, or something along those lines.

You really shouldn't be "guessing" about stuff like this.

Have you tried compiling it? If so, what errors do you get? That should go a long way to telling you what you need to do.


To back up a bit, can we conclude that you put a "?" in that section of code because it is not complete (meaning that it is a placeholder)? And that you are looking for help in completing it?

This is an important distinction because the current train of help is assuming that your program is nearly complete, and you are looking for help in "fixing code". If you are looking for help in designing/implementing/completing the code, the type of hints (or the direction of the conversation) will likely be different.

Henry
 
Cory Marcus
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Henry.

The (?) Section is actually how the code was provided to me to fix. I assume I'm meant to insert the correct variable.

However this, and the whatValue section are both areas I'm unsure about.

I'm actually relatively new to Java, and am slowly beginning to understand it, therefore I apologize if some questions and the answers to them seem blatantly obvious.

Regards.
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a problem here:

Think of what is being updated and why. There is also a problem here:

You have started a method but not finished it. As for this method...

...it's hard to know what to do with it because we don't have the code for numbers() and we don't know how printValue() is being called.
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:As for this method...

...it's hard to know what to do with it because we don't have the code for numbers() and we don't know how printValue() is being called.

If you go back to the OP's first post you'll see that it is more than likely there are two methods here, printValue(), and some other missing method name.
 
Guillermo Ishi
Ranch Hand
Posts: 789
C++ Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cory Marcus wrote:Hi.

The area I'm struggling with is mainly the "this.value" sections.



ClassWithErrors(int value) defines a variable named value local to the method. It is being assigned the value of the class or instance variable also named value, that is what "this" makes it refer to, but nothing is being done with the local variable after it is assigned. Also, to use "this" you need an instance, since "this" refers to a certain instance -- so to call ClassWithErrors you will have to do something like this --



Also, in case you were wondering that it is not a contructor, because it has a return type.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!