Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用java制作GPA计算器,需要稍加调整才能完成_Java - Fatal编程技术网

用java制作GPA计算器,需要稍加调整才能完成

用java制作GPA计算器,需要稍加调整才能完成,java,Java,好的,我已经做了几乎所有的事情,但是我不明白为什么分数没有转换成相应的数字,并实际计算gpa。如果有人可以尝试修复它,使其正常工作,这将是可怕的!多谢各位 以下是我的代码: import java.util.Scanner; public class StudentGPA { public static void main (String args[]){ //User inputs the number of classes he/she has Scanner input = new

好的,我已经做了几乎所有的事情,但是我不明白为什么分数没有转换成相应的数字,并实际计算gpa。如果有人可以尝试修复它,使其正常工作,这将是可怕的!多谢各位

以下是我的代码:

import java.util.Scanner;

public class StudentGPA {

public static void main (String args[]){

//User inputs the number of classes he/she has
Scanner input = new Scanner (System.in);
System.out.println("Please enter the amount of grades you have");
int classes;
classes = input.nextInt();
String Grade = "";
int totalCredits = 0;
int totalCreditsEarned = 0;
int credits;
double gpa;
double number=0;

//String of if and else statements that set the number to the appropriate GPA
if(Grade.equals("A")){
number = 4.0;
} else if(Grade.equals("A-")){
number = 3.67;
} else if(Grade.equals("B+")){
number = 3.33;
} else if(Grade.equals("B")){
number = 3.0;
} else if(Grade.equals("B-")){
number = 2.67;
} else if(Grade.equals("C+")){
number = 2.33;
} else if(Grade.equals("C")){
number = 2.0;
} else if(Grade.equals("C-")){
number = 1.67;
} else if(Grade.equals("D+")){
number = 1.33;
} else if(Grade.equals("D")){
number = 1.0;
} else if(Grade.equals("D-")){
number = 0.67;
} else if(Grade.equals("F")){
number = 0;
} else {
number = 0; 

//Loop that ends once the student has put information in on all his classes
for(int count = 0; count < classes; count++)
{

//Reads the number of credits each class was
Scanner input2 = new Scanner (System.in);
System.out.println("Please enter the number of credits this class was (A number)");
credits = input2.nextInt();
//reads the letter grade using the String Grade prompt
Scanner input3 = new Scanner(System.in);
System.out.println("Please enter your grade for this class (Capital letters such as A,           B+, C-)");
Grade = input3.next();

//algorithm for finding the GPA
totalCredits += credits;
totalCreditsEarned += (credits * number);
}
//for loop ends

//GPA is calculated for all the students classes
gpa = totalCreditsEarned / totalCredits;

//GPA is printed to the screen
System.out.println(gpa);
}
}
import java.util.Scanner;
公共课学生GPA{
公共静态void main(字符串参数[]){
//用户输入他/她拥有的班级数量
扫描仪输入=新扫描仪(System.in);
System.out.println(“请输入您的分数”);
int类;
classes=input.nextInt();
字符串级别=”;
int totalCredits=0;
int totalCreditsEarned=0;
国际学分;
双gpa;
双数=0;
//将数字设置为相应GPA的if和else语句字符串
如果(等级等于(“A”)){
数字=4.0;
}else if(等级等于(“A-”){
数字=3.67;
}else if(等级等于(“B+”){
数字=3.33;
}否则,如果(等级等于(“B”)){
数字=3.0;
}else if(等级等于(“B-”){
数字=2.67;
}else if(等级等于(“C+”){
数字=2.33;
}否则,如果(等级等于(“C”)){
数字=2.0;
}else if(等级等于(“C-”){
数字=1.67;
}else if(等级等于(“D+”){
数字=1.33;
}否则,如果(等级等于(“D”)){
数字=1.0;
}else if(等级等于(“D-”){
数字=0.67;
}否则,如果(等级等于(“F”)){
数字=0;
}否则{
数字=0;
//循环,一旦学生输入了所有课程的信息,循环就结束了
对于(int count=0;count

}`

简单修复,将if块放入循环中


在使用查找gpa的算法之前,请将if块放入循环中


在查找gpa的算法之前,在if语句之前放置一个断点,以查看字符串是否正确设置。编辑:我看不到你在哪里设置字符串??交叉张贴检查你在daniweb上的帖子,以获取回复:如果代码缩进了一点,pIt也更容易帮助你。在if语句之前放置一个断点,看看你的字符串设置是否正确。编辑:我看不出你在哪里设置字符串??交叉张贴检查你在daniweb上的帖子,以获取回复:如果你的代码缩进了一点,pIt也会更容易帮助你。当我这样做时,它把输入成绩部分搞砸了danieweb帖子也有同样的想法,就个人而言,我创建了一个返回int的方法,并将整个if块放在那里。当我这样做的时候,它把输入成绩部分搞砸了danieweb post的想法是一样的,我个人创建了一个返回int的方法,并将整个if块放在那里。