473,569 Members | 2,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

16 New Member
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 numberofstudent s,score;
double next;
char grade;
String answer;


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

numberofstudent s = 0;
score = 0;
grade=0;
next = keyboard.nextDo uble();
while (next >=0)
{
numberofstudent s++;
next = keyboard.nextDo uble();
}
if (numberofstuden ts > 0)
System.out.prin tln("Total number of grades " + (numberofstuden ts));



{

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

System.out.prin tln("Want to score another exam?");
System.out.prin tln("Enter y for yes or n for no.");
answer = keyboard.next() ;
}while (answer.equalsI gnoreCase("y")) ;
}
}
Nov 2 '06 #1
1 1882
r035198x
13,262 MVP
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
3801
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, though there may be some more benign explanation that escapes me. If you want the world to see your replies, then you should post them directly to...
12
2687
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 newsgroup there is an ongoing discussion about the famous fibonacci sequences, and a fine program written by a poster got my attention so just for fun I...
1
3118
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 part just explains a check digit.. i think this part in my program is alright These barcodes actually have four parts: a tall line as the first...
0
7099
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 the due date 10% of the grade is taken off. I think I'm coming down with the flu and my brain is just not processing this assignment. Here is the...
6
2971
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 them. to be more clear we process this purpose we serve this to the student in the university. how?? student will send a message that contains his...
3
4465
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 of each unit, and the value of the inventory of that product. In addition, the GUI should display the value of the entire inventory, the additional...
1
1240
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. Obviously, this is because the send is in the actionperformed method but the read is in the main method. Anyone offer any solutions to getting my program...
8
9975
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 else who is not here anymore). I have some complicated structures in this program that I don't know how to fix. I have fixed DataInputStream and...
6
6767
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
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7618
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8132
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7678
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6286
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5222
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
944
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.