import java.util.*;
import java.io.*;
public class stundentGrade {
public static void main(String args [])throws IOException{
BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));
int a=0, b=0,c=0,d=0,f=0, totalNumber=0; //declaration of initialization
stars(); //method to call and print stars
System.out.println("Enter a list of Exam scores from 0-100" );
System.out.println("use a negative number if you'r done with your list");
stars();//method to call and print stars
for (int grade=0; grade>=0 ;totalNumber++)
{
try
{
grade=Integer.parseInt(dataIn.readLine());//Handles the Exam score
if(grade>=90 && grade <=100)
a++;
else if(grade >= 80 && <= 89)
b++;
else if(grade >= 70 && <= 79)
c++;
else if(grade >= 60 && <= 69)
d++;
else if(grade >= 0 && <= 59)
f++;
else if(grade > 100)
{
System.out.println("Invalid grade!");//Error message
totalNumber--;//remove the invalid grade
}
}
catch(NumberFormatException e)
{
System.out.println("Invalid Imput! Please enter your score in number format"); // error message
totalNumber--;//remove the invalid input
continue;
}
}
System.out.println();
System.out.println(" Total number of grade: " + (totalNumber-1));
System.out.println(" A grades: "+ a);
System.out.println(" B grades: "+ b);
System.out.println(" C grades: "+ c);
System.out.println(" D grades: "+ d);
System.out.println(" F grades: "+ f);
}
public static void stars()
{
System.out.println("***************************************");
}
}
Wandaga1
0
Newbie Poster
Recommended Answers
Jump to PostWhy do you think anything is wrong with it? If you have an error, or incorrect results, then share that info with us, don't expect us to guess!
Jump to Postit doesn't handle negative grades...
Jump to PostYou have to implement what happens if the grade is less than 0. Currently there is nothing and it just won't do anything about it
Jump to PostI guess many eyes on the same code help discovering all of issues in your code.
You need to redesign your logic here. What are different reasons to pick between a for-loop and do-while loop? One distinct reason is that a for-loop should be used with a pre-defined minimum/maximum value …
All 14 Replies
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
JeffGrigg
commented:
Good question. ;->
+6
Wandaga1
commented:
yes you are right, but i read that if incase we have problem with code we just need to post´. but seeing the code was enought to analys the problem
+0
jwenting
1,889
duckman
Team Colleague
JeffGrigg
commented:
Yes; that's what we needed to know.
+6
Slavi
94
Master Poster
Featured Poster
JeffGrigg
commented:
Yes; exactly!
+6
Akansha Jain
-6
Newbie Poster
JamesCherrill
commented:
Makes no sense. Loop IS needed
+0
Wandaga1
commented:
because is king of evaluation process, which need to have four loops. or do you have an idea on how to get it in shotcut?
+0
Taywin
312
Posting Virtuoso
Wandaga1
0
Newbie Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
Wandaga1
0
Newbie Poster
Wandaga1
0
Newbie Poster
Wandaga1
0
Newbie Poster
stultuske
1,116
Posting Maven
Featured Poster
henryz_box
0
Junior Poster in Training
Wandaga1
0
Newbie Poster
Taywin
312
Posting Virtuoso
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.