I am having an issue whereby whenever input validation is incorrect it breaks out of my current loop and continues with the next method can anyone help me so that when condition is false it re-asks for the same input until it meets the condition. Here's my source code for my method class
public class Student {
public int gradePt;
public int i;
public int credSum = 0;
public double gradeCredSum = 0;
public double gpa;
String [] moduleName;
String [] moduleGrade;
int [] moduleCred ;
Module[] modules;
public void createModules(){
getModuleNo();
modules = new Module[i];
moduleName = new String[i];
moduleGrade = new String[i];
moduleCred = new int[i];
getModule();
getGrade();
getCred();
for (int j = 0; j < modules.length; j++) {
modules[j] = new Module(moduleName[j],moduleCred[j],moduleGrade[j]);
}
}
public void getModuleNo(){
do{
String input = JOptionPane.showInputDialog(null,
"How many modules did you take?","Input");
int a = Integer.parseInt(input);
if (a<1 || a>8){
JOptionPane.showMessageDialog(null,
"Invalid input please enter a number greater than 0",
"Error",JOptionPane.ERROR_MESSAGE);
break;
} i = a;
}while(i<1 || i>8);
}
public void getModule(){
for (int i=0;i<moduleName.length;i++){
String input = JOptionPane.showInputDialog(null,
"Enter the name of module #"+(i+1));
moduleName[i] = input;
if (input == ""){
JOptionPane.showMessageDialog(null,
"Invalid input, module name cannot be blank","Error",JOptionPane.ERROR_MESSAGE);
break;
}
}
}
public void getGrade(){
for (int i=0;i<moduleGrade.length;i++){
String input = JOptionPane.showInputDialog(null,
"Enter grade (A,B,C,D,F) for module #"+(i+1));
moduleGrade[i] = input;
if (!"A".equals(input) && !"B".equals(input) && !"C".equals(input) && !"D".equals(input) &&
!"F".equals(input) && !"a".equals(input) && !"b".equals(input) && input!="c" &&
!"d".equals(input) && !"f".equals(input)){
JOptionPane.showMessageDialog(null,
"Invalid input!"+"\n"+"Please enter A,B,C,D or F","Error",JOptionPane.ERROR_MESSAGE);
break;
}
moduleGrade[i] = input;
}
}
public void getCred(){
for (int i=0;i<moduleCred.length;i++){
String input = JOptionPane.showInputDialog(null,
"Enter credit units for module #"+(i+1));
moduleCred[i] = Integer.parseInt(input);
if (moduleCred[i]<1 || moduleCred[i]>8){
JOptionPane.showMessageDialog(null,
"Invalid input!"+"\n"+"Please enter a number form 1 to 8","Error",JOptionPane.ERROR_MESSAGE);
break;
}
}
}