B
Booter
Hello all,
I am working on a program that can takes numbers in as grades with a
delimiter of a ",". I have most of the code working but for some
reason I can never get out of the while loop in the code. If anyone
can help it would be greatly appreciated.
*****************CODE**************
import java.util.*;// need scanner
public class Grades
{
public static void main (String[] args)
{
Scanner classGrades = new Scanner(System.in);
Scanner delimiter = new Scanner(System.in);
System.out.print("Welcome to the Grade Calculator Program \n\n"
+ "Please enter the student scores as integers between 0 and
100.\n"
+ "Separate the scores with a comma.\n"
+ "Follow the last student score with a negative number.\n"
+ "Enter the grades here: ");
//declairations for vars needed
int grade = 0;
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int f = 0;
int total = 0;
int low = 0;
int high = 0;
double avg = 0;
double sum = 0;
//set delimiter to a ","
delimiter.useDelimiter(",");
//while loop to go though the input grades
while (delimiter.hasNextInt())
{
System.out.println(grade);
grade = delimiter.nextInt();
if (grade >= 0)
{
System.out.println("test 2");
//assign low and high
if (grade > high)
high = grade;
else if (grade < low)
low = grade;
// assign grades
if (grade >= 90)
{
a++;
sum = sum + grade;
}
else if (grade >= 80 && grade <= 89)
{
b++;
sum = sum + grade;
}
if (grade >= 70 && grade <= 79)
{
c++;
sum = sum + grade;
}
if (grade >= 60 && grade <= 69)
{
d++;
sum = sum + grade;
}
if (grade < 60)
{
f++;
sum = sum + grade;
}
System.out.println(grade);
total++;
}
else
break;
}
avg = sum / total;
System.out.print("\n\n");
System.out.println("Grade Calculations:");
System.out.println("Total number of grades = " + total);
System.out.println("Low score = " + low);
System.out.println("High score = " + high);
System.out.println("Average score = " + avg);
System.out.println("Number of A's = " + a);
System.out.println("Number of B's = " + b);
System.out.println("Number of C's = " + c);
System.out.println("Number of D's = " + d);
System.out.println("Number of F's = " + f);
}
}
I am working on a program that can takes numbers in as grades with a
delimiter of a ",". I have most of the code working but for some
reason I can never get out of the while loop in the code. If anyone
can help it would be greatly appreciated.
*****************CODE**************
import java.util.*;// need scanner
public class Grades
{
public static void main (String[] args)
{
Scanner classGrades = new Scanner(System.in);
Scanner delimiter = new Scanner(System.in);
System.out.print("Welcome to the Grade Calculator Program \n\n"
+ "Please enter the student scores as integers between 0 and
100.\n"
+ "Separate the scores with a comma.\n"
+ "Follow the last student score with a negative number.\n"
+ "Enter the grades here: ");
//declairations for vars needed
int grade = 0;
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int f = 0;
int total = 0;
int low = 0;
int high = 0;
double avg = 0;
double sum = 0;
//set delimiter to a ","
delimiter.useDelimiter(",");
//while loop to go though the input grades
while (delimiter.hasNextInt())
{
System.out.println(grade);
grade = delimiter.nextInt();
if (grade >= 0)
{
System.out.println("test 2");
//assign low and high
if (grade > high)
high = grade;
else if (grade < low)
low = grade;
// assign grades
if (grade >= 90)
{
a++;
sum = sum + grade;
}
else if (grade >= 80 && grade <= 89)
{
b++;
sum = sum + grade;
}
if (grade >= 70 && grade <= 79)
{
c++;
sum = sum + grade;
}
if (grade >= 60 && grade <= 69)
{
d++;
sum = sum + grade;
}
if (grade < 60)
{
f++;
sum = sum + grade;
}
System.out.println(grade);
total++;
}
else
break;
}
avg = sum / total;
System.out.print("\n\n");
System.out.println("Grade Calculations:");
System.out.println("Total number of grades = " + total);
System.out.println("Low score = " + low);
System.out.println("High score = " + high);
System.out.println("Average score = " + avg);
System.out.println("Number of A's = " + a);
System.out.println("Number of B's = " + b);
System.out.println("Number of C's = " + c);
System.out.println("Number of D's = " + d);
System.out.println("Number of F's = " + f);
}
}