所以即时创建一个gpa计算器,它需要4个类(或者更多,如果我想要的话)并计算字母等级和gpa权重。 我将如何使用相同的方法4次,每次添加不同的输入变量。 例如,第一次呼叫(等级)的第一个输入是80。 如果我再次调用它并输入90,我希望它存储初始80并添加90等等所以我可以计算gpa。
这是我的代码
import java.util.*;
public class GpaCalculator{
public static void main(String[] args) {
{
System.out.println("Please enter your name>>>");
Scanner stringinputs = new Scanner(System.in);
String name = stringinputs.nextLine();
GreatGrader();
System.out.println();
System.out.println(name);
}
}
public static void GreatGrader(){
Scanner stringinput = new Scanner(System.in);
System.out.println("Please enter your course>>>");
String Course1 = stringinput.nextLine();
System.out.println("What is the weight of this class? Normal, Honors, or AP?>>>");
String weight = stringinput.nextLine();
System.out.println("What is your grade in the class?>>>");
String grade = stringinput.nextLine();
double gpa = 0;
if (weight.equalsIgnoreCase("honors"))
gpa = gpa + 1;
else if (weight.equalsIgnoreCase("Ap"))
gpa = gpa + 1.5;
else if (weight.equalsIgnoreCase("normal"));
String letter;
Scanner in = new Scanner(System.in);
int grades = in.nextInt();
if (grades >= 96)
{ gpa = 4.5;
letter = "A";}
else if (grades >= 92)
{ gpa = 4.0;
letter = "A";}
else if (grades >=88 )
{ gpa = 3.5;
letter = "B"; }
else if (grades >= 84 )
{ gpa = 3.0;
letter = "B";}
else if (grades >=76 )
{ gpa = 2.5;
letter = "C";}
else if (grades >= 72)
{gpa = 1.5;
letter = "C";}
else if (grades>=68)
{ gpa = 1.0;
letter = "D";}
else if (grades <=67)
{ gpa = 0;
letter = "F";
}
}
}