473,406 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Almost got it, need just a little help with this java grader program to output correc

This program is supposed to calculate the number of grades entered and also how many a's, b's, c's, d's, and f's are entered. I have the number of grades part right but can't figure out how to fix my code to make it output the correct number of each letter grade. Can someone please look at my code and tell me where I messed up? I appreciate all help I can get. Thanks!

Here is my code:

import java.util.*;

public class Grades
{
public static void main(String[] args )
{
int numberofstudents,score;
double next;
char grade;
String answer;


do
{
System.out.println("Enter scores for all students.");
System.out.println("Enter a negative one after");
System.out.println("you have entered all the scores.");
Scanner keyboard = new Scanner(System.in);

numberofstudents = 0;
score = 0;
grade=0;
next = keyboard.nextDouble();
while (next >=0)
{
numberofstudents++;
next = keyboard.nextDouble();
}
if (numberofstudents > 0)
System.out.println("Total number of grades " + (numberofstudents));



{

numberofstudents = grade;
if (score >= 90){
grade ='A';
numberofstudents++;}
else if (score >= 80){
grade ='B';
numberofstudents++;}
else if (score >= 70){
grade ='C';
numberofstudents++;}
else if (score >= 60){
grade ='D';
numberofstudents++;}
else if (score < 60){
grade ='F';
numberofstudents++;}
}
System.out.println("Number of A's = " + (numberofstudents++));
System.out.println("Number of B's = " + (numberofstudents++));
System.out.println("Number of C's = " + (numberofstudents++));
System.out.println("Number of D's = " + (numberofstudents++));
System.out.println("Number of F's = " + (numberofstudents++));

System.out.println("Want to score another exam?");
System.out.println("Enter y for yes or n for no.");
answer = keyboard.next();
}while (answer.equalsIgnoreCase("y"));
}
}
Nov 2 '06 #1
1 1859
r035198x
13,262 8TB
Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  2.  
  3. public class Grades
  4. {
  5. public static void main(String[] args )
  6. {
  7. int numberofstudents,score;
  8. double next;
  9. char grade;
  10. String answer;
  11.  
  12.  
  13. do
  14. {
  15. System.out.println("Enter scores for all students.");
  16. System.out.println("Enter a negative one after");
  17. System.out.println("you have entered all the scores.");
  18. Scanner keyboard = new Scanner(System.in);
  19.  
  20. numberofstudents = 0;
  21. score = 0;
  22. grade=0;
  23.  
  24. //Or maybe you could an array here
  25. int a = 0;
  26. int b = 0;
  27. int c = 0;
  28. int d = 0;
  29. int f = 0;
  30.  
  31. next = keyboard.nextDouble();
  32. while (next >=0)
  33. {
  34.     numberofstudents++;
  35.     //next = keyboard.nextDouble();
  36.     //numberofstudents = grade;
  37.     //Process the data as it is being entered
  38.     if (next >= 90){
  39.     //grade ='A';
  40.     a++;
  41.     }
  42.     else if (next >= 80){
  43.     //grade ='B';
  44.     b++;
  45.     }
  46.     else if (next >= 70){
  47.     //grade ='C';
  48.     c++;
  49.     }
  50.     else if (next >= 60){
  51.     //grade ='D';
  52.     d++;
  53.     }
  54.     else if (next < 60){
  55.     //grade ='F';
  56.     f++;
  57.     }
  58.     next = keyboard.nextDouble();
  59. }
  60.  
  61. if (numberofstudents > 0) {
  62. System.out.println("Total number of grades " + (numberofstudents));
  63.  
  64.  
  65. System.out.println("Number of A's = " + a);
  66. System.out.println("Number of B's = " + b);
  67. System.out.println("Number of C's = " + c);
  68. System.out.println("Number of D's = " + d);
  69. System.out.println("Number of F's = " + f);
  70. }
  71.  
  72. System.out.println("Want to score another exam?");
  73. System.out.println("Enter y for yes or n for no.");
  74. answer = keyboard.next();
  75. }while (answer.equalsIgnoreCase("y"));
  76. }
  77. }
Nov 3 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Steve Richfield | last post by:
To All, First, some of your replies to me have been posted through DevelopersDex, and these are NOT posted on USENET for the world to see. DevelopersDex appears to be trying to hijack USENET,...
12
by: CII | last post by:
Hi everybody. I've been reading posts a year old about the fibonacci series right on this newsgroup, and while it's not directly games related, I'll share my own notes as well. On another...
1
by: Unebrion | last post by:
Alright im working on a program that prints out user imput in a frame, along with a barcode.. it is like the front of an envelope. Here is the description for the program. This...
0
by: south622 | last post by:
I'm taking a beginning Java course and I'm stuck in week eight of a nine week course. If anyone could help me I would greatly appreciate it. This assignment was due yesterday and each day I go past...
6
by: zaina | last post by:
hi everybody i am nwebie in this forum but i think it is useful for me and the member are helpful my project is about connecting client with the server to start exchanging messages between...
3
by: 100grand | last post by:
Modify the Inventory Program to use a GUI. The GUI should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price...
1
by: brendanmcdonagh | last post by:
Hi all, I have my little message program working until i press a button and then it'll go to actionPerformed method, and stop reading but will keep sending a message which is being received....
8
by: marknvicf | last post by:
I have read a bit about the endian differences, got a couple of jar/libs to help (Android and com.mindprod), but still am not sure how to fix this program that I have (written in JDK 1.4 by someone...
6
by: rahulsengupta895 | last post by:
. #define MIN(a,b) (a<b?a:b) #define MAX(a,b) (a>b?a:b) #include "Video.h" #define NO_HUE -1
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.