• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

How I get my grade calculator to work properly?

 
Ranch Hand
Posts: 105
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, so I have to create a grade calculator for my computer science class where the user can input as many grades as they want, then it will calculate the average for them and the equivalent letter grade. I have manage to let it allow me to input as many grades as I want, however, the prompt that says, "Enter grade number 1,2,3, or 4, etc." does not count up. The entire time it says enter grade number 1. Thats not my only problem, however. I also cannot get the part of my program that calculates the grade correct. If only one grade is put it, it will say the average is half of that. If too many are put in, it will give an average of well over 100%, even when no values over 100% are put in. I realy need help with fixing this ASAP. Here is my code:

 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Every time you enter the while loop, what will counter be?
 
David Vach
Ranch Hand
Posts: 105
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The counter will be the the number identifying how many grades are put in. For example, "Enter grade number 1: 97 percent, next line, enter grade number 2:_". The counter will function both to identify to the user how many grades they have entered and it will be used to calculate the average. The average, as of right now, does not calculate correctly at all.
 
David Vach
Ranch Hand
Posts: 105
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I realized that the code up there may be a little outdated. I fixed some minor spelling problems and made it a tiny clearer. Here is the code:

 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:
Every time you enter the while loop, what will counter be?


Look at the actual code.  What will counter be in line five every time you enter the loop?
 
David Vach
Ranch Hand
Posts: 105
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The counter will only stay as 1 every time you enter the loop. I tried to create a for loop to fix that, but it only screwed up the rest of the code.
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Move counter = 1; above the while loop.
 
David Vach
Ranch Hand
Posts: 105
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes! Now that works. However, it still seems to be calculating my averages wrong. I will post a even further updated version of my code.
 
David Vach
Ranch Hand
Posts: 105
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the most current version of my code:


 
David Vach
Ranch Hand
Posts: 105
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Disregard that last question. I figured it out. However, the sequence does not end at the break; command. Any ideas on that?
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see a break in the code.
 
David Vach
Ranch Hand
Posts: 105
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, I guess I had already removed it. I replaced it at the end of each with System.exit(0);, however I wanted it to have a break command there in order for it to just end the program, not exit it. But when I replace the exit(0); statement with break, the end of the code plays, but it does not end the program. It just continues having me enter grades.
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You've got two while (YoN.equalsIgnoreCase("start")) loops -- one at line 49 and one at line 86.
 
David Vach
Ranch Hand
Posts: 105
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, but where would I put a break in order for it to end the while statements?
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your code has more serious problems than where to put a break.  It has repeated code and while loops that don't terminate.  Why don't you take a few minutes and write down in English or pseudocode how you'd like the program to work.  Break the code up into tasks.  Each task should probably be a method.  Get all your code out of the main() method.  See MainIsAPain (that's a link).  Start with something like this:

 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the Beginning Java forum, we don't post complete solutions.  First, we are NotACodeMill (that's a link).  Second, we are here to guide the OP and help them learn.  We appreciate the effort and the urge to help, but please post only code snippets as illustration of your advice.
 
Greenhorn
Posts: 11
Eclipse IDE Objective C Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:In the Beginning Java forum, we don't post complete solutions.  First, we are NotACodeMill (that's a link).  Second, we are here to guide the OP and help them learn.  We appreciate the effort and the urge to help, but please post only code snippets as illustration of your advice.



I understand and respect it, but that post does not mean I am not trying to help them learning. I was trying to show where the issue was. And one thing that I believe is important on each topic that is raised is provide the final solution or the final understanding on the issue, so, not only the person that raised the issue , but all others that google it can learn.

I hope it helps the next moderation,
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Final solutions can be posted by the OP, but not anyone else.  Please note that at the stated policy of this forum is:

We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.

 
It's a beautiful day in this neighborhood - Fred Rogers. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic