Cannot figure out error messages
Code:
Gpa.java:31: incompatible types
found : boolean
required: double
gpa = scan.hasNextDouble();
^
I don't exactly know why this is, or how to fix it. (I honestly get this error message any time I use scan.hasNext() ) When I change this to scan.nextDouble() I get this when I run my program:
Code:
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:857)
at java.util.Scanner.next(Scanner.java:1478)
at java.util.Scanner.nextDouble(Scanner.java:2404)
at Gpa.main(Gpa.java:31)
And it's at the same (Gpa.java:31) line as where I got the first error. What do I need to do?
Code:
public class Gpa
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
DecimalFormat fmt = new DecimalFormat("0.00");
boolean groupName;
final String SENT = "EndOfGroup";
String stuName;
int groupCount, numGroup;
double groupMin, groupMax, gpaAverage, gpa, groupSum;
while(scan.hasNext())
{
groupName = scan.hasNextLine();
numGroup = 0;
groupSum = 0;
groupCount = 0;
groupMin = 0.0;
groupMax = 4.0;
gpaAverage = 0;
stuName = scan.next();
while(!stuName.equals(SENT))
{
numGroup++;
gpa = scan.nextDouble();
groupSum = groupSum + gpa;
groupCount++;
if(gpa >= groupMin)
{
groupMin = gpa;
}
if(gpa <= groupMax)
{
groupMax = gpa;
}
gpaAverage = groupSum/numGroup;
System.out.print("Student: "+stuName);
System.out.print(" GPA = "+fmt.format(gpa));
stuName = scan.next();
}
System.out.println("Average GPA for this group = "+fmt.format(gpaAverage));
System.out.println("Minimum GPA for this group = "+fmt.format(groupMin));
System.out.println("Maxium GPA for this group = "+fmt.format(groupMax));
}
}