I know this question has been asked before, but I've tried the solution scannername.hasNextInt()
and it still doesn't work. Under CalculateGPA
the error is thrown after the line "enter marks for subject1". RegisterStudent
only takes in subject names and their credits.
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);
}
}
My main class:
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);
}
}
}