Java: Incompatible Types

Posted by user2922081 on Stack Overflow See other posts from Stack Overflow or by user2922081
Published on 2013-10-26T03:29:30Z Indexed on 2013/10/26 3:54 UTC
Read the original article Hit count: 89

Filed under:
import java.text.*;
import java.util.*;
public class Proj3 {
    public static void main(String[]args){
     // DecimalFormat df = new DecimalFormat("#0.00”);
     Scanner s = new Scanner(System.in);
     int TotalHours = 0;
     int TotalGrade = 0;

     System.out.print("How many courses did you take? ");
     int Courses = Integer.parseInt(s.nextLine());
     System.out.println("");

     int CourseNumber = Courses - (Courses - 1);
     while (Courses > 0){
         System.out.print("Course (" + CourseNumber +"): How many hours? ");
         int Hours = Integer.parseInt(s.nextLine());
         TotalHours = TotalHours + Hours;

         System.out.print("Course (" + CourseNumber +"): Letter grade? ");
         char Grade = s.nextLine().charAt(0);

         if (Grade == 'A'){
             TotalGrade = TotalGrade + (4 * Hours);
            }
         if (Grade == 'B'){
             TotalGrade = TotalGrade + (3 * Hours);
            }
         if (Grade == 'C'){
             TotalGrade = TotalGrade + (2 * Hours);
            }
         if (Grade == 'D'){
             TotalGrade = TotalGrade + (1 * Hours);
            }

         Courses = Courses - 1;
         CourseNumber = CourseNumber + 1;
        }
     Double GPA = TotalGrade / TotalHours;
     System.out.println(df.format(GPA));

    }
}

This is for an assignment and I don't know how to fix my problem. The Double GPA = TotalGrade / ToutalHours; line is coming up with the Incompatible Types error.

Also I'm supposed to include the DecimalFormat df = new DecimalFormat("#0.00”);line at the beginning of the main but its not working.

Anything is very helpful. Thanks

© Stack Overflow or respective owner

Related posts about java