Forums Register Login

Help me fix this code, please.

+Pie Number of slices to send: Send
+Pie Number of slices to send: Send
First of all, this code is unreadable. Why is all indentation removed?

Second of all, what is it supposed to do, and what does it not do? http://faq.javaranch.com/java/TellTheDetails
+Pie Number of slices to send: Send

The idea is to get used to file input and output streams.If that makes you angry, sorry, but I could still use some help.

Getting down to buisness, what this code does is, accept a file read it print it and then edit it ,IF THE USER WILLS SO.

The complication probably arises because I wanted to make sure the program does not terminate incase the user plans to input an alphabet incase of an int.

Which is why you'll probably see many do ......whiles.
+Pie Number of slices to send: Send
I can't see anywhere that Rob was getting angry - he was simply trying to tell you what is needed before anyone can even start to help you.

I have reformatted your code so that I can read it. Unfortunately that is about all I have time for today - if I had not needed to make the code readable then I might have had time to look at what the problems are.

Some quick thoughts:
  • This code will not compile. You have told us what you would like the program to do, but you have not told us what your problem is. I can therefore only assume that the problem is that you cannot get it to compile.


  • Regarding compilation:
  • You have variables varfw and varfr that you are using in lines 48, 88 and 108; however they are not in scope at the time you are using them. You have defined them on lines 32 & 33, however they are defined within the try...catch block. That means that as soon as you are past line 37 the variables varfw and varfr no longer exist.
  • Creating a FileWriter (line 33) can potentially throw IOException - you are not catching this or declaring it to be thrown


  • General issues:
  • Variable varfile (line 27) is not used - did you have a purpose for this?
  • Variable gostrng4 (line 63 & line 98) is never read - did you have a purpose for this?
  • There is no point in initializing vstring with a String on line 15 since it is overwritten in line 22. You might as well initialize it to null
  • Same applies to str3 on line 63. str3 is only used when count2 is equal to 1, so you could change the scope to just that block.
  • readLine on line 67 could return a null - you are not handling this
  • Your do...while loop from lines 76 - 99 will only terminate when gostrng is set to true. However you never set gostrng in that loop - it will run forever.
  • Your do...while loop from lines 79 - 86 will only terminate when gostrng3 is set to false. However you never set gostrng3 in that loop - it will run forever.
  • +Pie Number of slices to send: Send
     

    Varun Goenka wrote:If that makes you angry, sorry,


    No need to apologize. As Andrew said, I was not angry. I was just a) stating a lack of indentation which only makes it harder to read, and b) asking for more information.
    You showed up just in time for the waffles! And this tiny ad:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com


    reply
    reply
    This thread has been viewed 971 times.
    Similar Threads
    reading a file, then replacing a string...
    Compare Two Text Files
    Currency Problem + General Advice
    Reading Terminal Input
    Global Array not working
    More...

    All times above are in ranch (not your local) time.
    The current ranch time is
    Mar 28, 2024 16:58:00.