我之前已经问过这个问题,但我已经尝试过解决方案scannername.hasNextInt()
但它仍然无效。在CalculateGPA
下,在“为subject1输入标记”行之后抛出错误。 RegisterStudent
仅接受主题名称及其学分。
class CalculateGPA {
RegisterStudent s;
int scoreSum=0;
CalculateGPA(RegisterStudent std){
s=std;
System.out.println("\nIn calculate\n");
}
void findGPA() throws NumberFormatException,InvalidGPAException {
Scanner sc =new Scanner(System.in);
int marks1,marks2,marks3;
String result;
System.out.println("\nEnter the marks for "+s.subject1);
if(sc.hasNext()){
marks1=sc.nextInt();
result=findGrade(marks1);
System.out.println(s.subject1+" "+result);
}
}
我的主要课程:
public class all {
public static void main(String args[]){
RegisterStudent s1=new RegisterStudent();
//RegisterStudent s2=new RegisterStudent();
s1.getBranch("ISE");
s1.getName("Saniya");
try{
s1.register();
}
catch(CreditLimitException e){
System.out.println(e);
}
CalculateGPA cal=new CalculateGPA(s1);
try{
cal.findGPA();
}
catch(NumberFormatException e){
System.out.println(e);
}
catch(InvalidGPAException e){
System.out.println(e);
}
}
}