I am a Java newbie and have been working on this program for about a month. Java has been very challenging, but I am enjoying learning. My issue starts with line 49 or 50 I think. I would like my program to be able to recognize that the minimum # of CUs could be < than 12 if the student only has 6 CUs left until graduation, but I also need it to recognize if I enter a letter or negative number which I somehow managed to do at the top of the code. I tried to pull this off with sum == sum which isn't giving me the desired output. I tried to reuse code from my lines 15-38 cause I know that part of the program responds correctly when I try to enter a letter or negative number, but I obviously was not implementing the loop correctly when I tried to put it on line 57 because the program runs but doesn't produce anything when it gets to that point. In summary, I would appreciate some assistance getting my code to realize that a student may not have the minimum CUs left (12) and may need < than that to graduate, but also not accept negative number or letters as input. Any feedback on the code formatting would be appreciated as well.
You wrote quite a lot lines of code. Some code fragments are good, some - not. What I'd suggest you is, to write down the steps in english, where each step suppose to describe a single small task. After you clearly identify these steps/tasks - create a method for each task in order to accomplish that. Then, would be pretty easy to identify, which parts doesn't give you a wanted result.
Your issues actually starts a bit earlier than from the line 49, so, to know how to fix them, I'd encourage you clearly identify the steps your program are intended to do. If you want, try to write down over here, so it would help everyone to understand your program idea.
Thank you everyone for the feedback. I took everyone's advice and reevaluated what I had done. sum == sum will ALWAYS be true so that had to go and as I wrote the project down step by step, I could see where I went wrong. Here is what I came up with. Now I am closer to getting the output I am looking for. My only issue now is that if I student enters 0 CUs as the first input (because I am using 0 to tell the program I am done with those inputs and to sum the numbers entered) it is still showing that they have 1 term to complete, which is not correct. I believe that I can fix this by implementing something similar as I did here: Any feedback would be appreciated. I just wanted everyone to know where I was at since you guys took time out to offer me feedback. Thanks again!
This project is a graduation planner that a student would use to see how long it would take to graduate and how much money it would cost. Below is the complete code:
I am looking at the code, and it looks very complicated, it seems for a quite simple problem.
As I mentioned above, I encourage you to simplify all that logic by dividing your program into small pieces of code and making methods from them.
1. By making an assumption this code is correct, it is being repeated in your program at least twice. So, it means it requires to become a single method, which accomplish the single task.
2. Iterate loop simply while "true" is not a good practice, as it doesn't give you a clue, in which circumstances it would stop. Look what you have inside body of "while" loop. Might would work to add a condition in a while loop, like "while (input != exitCode)" where exitCode is equal 0? Moreover, in this case probably would work better do-while loop. Have you read about it? Check here (<- link)
3. This should become a method also, with a meaning name, so you could look at it, and have an understanding, what is meant to do. In addition, variable "CUs" doesn't say much, I'd pick something with more meaning.
4. This code could become a method also. Maybe "defineCreditsPerTerm" or something, you know better what is meant to do.
5. Even this code could become a method, like "printStudiesStatistics" or something similar.
Hopefully you got the idea. Anyone who ever would look to your code, looking only at the method declaration, could have a clue, what program is meant to do. In this way would be the way easier to notice, where the program flow goes wrong, which method produces wrong results and many more advantages.
And this program finally should become something similar to:
It is just an example. Best luck.