please i dont know how you could help me am working on my final year project and this is the topic my supervisor choose for me pls can i get some help on this or sources that could help? am so so confused will be happy if i could get a reply soon. thank in advance

Output of this section of the code is
0 8 8 8
0 8 8
While the values in print statement are correct. The value printed on the jpanel using g.drawString
is not correct. The g.drawString method prints 0 in the graphics panel instead of 8. The value in indexOfBlock1
is 8 and value in indexOfBlock is 0. Value in val3 is also same as value in indexOfBlock1. But if
I print it through g.drawString then it shows value as 0.</pre>

I give print statements before and after drawString command. the values printed are correct in the print statements. But the value is not correct in the drawstring statement that occurs between the print statement.
I do not know how to check for code overwrites in java or any other language. Is there a debugger for java? can you point out where to look for help in identifying code overwrite errors.

The print statements suggest that the value is correct at the point you call drawString. So the only conclusion must be that some other code is overwriting it elsewhere. However, with such a small code sample in your question it is impossible to guess anything more. If you are using Netbeans or Eclipse as your IDE then I think they both support interactive debugging (Eclipse definitely does). If not then you can use jdb - The Java Debugger[^].

The fact is I do not know how to use jdb or debugger to spot code overwrite errors. I tried looking on the web, I could not find any. Do you or someone know how to use gbd to spot code overwrite errors? or guide me to a document or example where it is done?

Sorry, but it is impossible to teach you debugging in a technical form. It is a technique that you really need to learn for yourself, either from online tutorials, or by attending a training course. Time spent learning now will assist you in your future efforts. I already gave you a link to the online documentation, so you can start with that.

I just found out that you can't have global variables in C#. I think they are supported in other languages like C, C++, Python and maybe Visual Basic.Net.

The program I want to convert to C# has a lot of variables that need to be used in other parts of the program such as procedures. I know you can add variables within the curly brackets for a procedure but in many cases the procedure needs to know about a lot of the variables to function and give a result and the same procedures are used many times in the code. I could use classes but I don't think you can have use the same variable in more than one class.

You are right, you cannot have global variables, and for good reasons. If a procedure needs access to variables then they should either be declared at the class level (and accessed through the get/set mechanism), or passed in from the calling process(es). Don't try to work round this by hacks, you will just end up down a blind alley, or worse, a buggy application.

Also, please use the correct forum for your questions; this one is for Java not C#.

The use of get/set is to hide the actual variables from the outside users, it has nothing to do with global variables. What you really should be doing is finding how to move all the variables inside the classes that require them.

If you need to pass that many variables then you need to look at the design of your classes. For example, you have a number of variables referring to a Room, so why not just pass a Room object that contains all those values?

In your reply you wrote
If you need to pass that many variables then you need to look at the design of your classes. For example, you have a number of variables referring to a Room, so why not just pass a Room object that contains all those values?

Can you please provide a quick example to make sure that I fully understand your suggestion.

As I have mentioned a number of times, you need to study some good learning materials and reference guides, for example, the two publications I previously recommended. Object Oriented Programming is all about the use of classes to encapsulate the properties and methods required to manipulate an object. If you still don't fully understand that then you will struggle with any programming task.