Hi can someone help me with my code. I needed to display the grade point average for percentage grades input by user. I keep getting errors and not sure what I have done wrong.
#
import java.util.Scanner;
public class GradePoint2
{
public void addPoints()
{
int grade, total, count;
double average;
total = 0;
count = 0;
Scanner input = new Scanner (System.in);
System.out.print("Enter grade (-1 to quit): ");
int inputGrade = input.nextInt();
while (inputGrade != -1)
{
if (inputGrade >= 0 && inputGrade <= 100)
System.out.printf("Point is: %d\n", returnPoints(inputGrade));
else
System.out.println("Invalid input.");
System.out.print("Enter grade (-1 to quit): ");
inputGrade = input.nextInt();
total += grade;
++count;
}
}
public int returnPoints(int grade)
{
if (grade >=90)
return 4;
else if (grade >=80)
return 3;
else if (grade >= 70)
return 2;
else if (grade >= 60)
return 1;
else
return 0;
}
average = total / count;
System.out.printf("\nThe GPA is : " + average );
}