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));
}
}
这是一个任务,我不知道如何解决我的问题。该Double GPA = TotalGrade / ToutalHours;
行出现Incompatible Types
错误。
此外,我应该DecimalFormat df = new DecimalFormat("#0.00”);
在 main 的开头包含该行,但它不起作用。
任何事情都非常有帮助。谢谢