I’m working on a Java Swing application where I need to store the output of if-else conditions in an array and then call this stored array in a different JFrame.
here is the sample code that im working
private void submitButtonActionPerformed(java.awt.event.ActionEvent evt)
ArrayList<Gradeprac> studList = Gradeprac.getStudentList();
DefaultTableModel model = (DefaultTableModel) tblStudents.getModel();
int rowCount = model.getRowCount();
for (int i = 0, row = 0; i < studList.size(); i++)
if (studList.get(i).section.equals(cmbSections.getSelectedItem().toString()))
Object value = model.getValueAt(row, 2);
if (value == null || ((String) value).isEmpty())
value = "NE";
model.setValueAt(value, row, 2);
String grade = convertToGrade(value);
System.out.println("Percentage: " + value + "% - Grade: " + grade);
row++;
private String convertToGrade(Object value)
try
double percentage = Double.parseDouble(value.toString());
int percentageInt = (int) percentage;
if (percentageInt < 100 && percentageInt >= 96.5)
return "1.00";
else if (percentageInt < 97 && percentageInt >= 92.5)
return "1.25";
else if (percentageInt < 93 && percentageInt >= 88.5)
return "1.50";
else if (percentageInt < 89 && percentageInt >= 84.5)
return "1.75";
else if (percentageInt < 85 && percentageInt >= 81.5)
return "2.00";
else if (percentageInt < 82 && percentageInt >= 78.5)
return "2.25";
else if (percentageInt < 79 && percentageInt >= 75.5)
return "2.50";
else if (percentageInt < 76 && percentageInt >= 72.5)
return "2.75";
else if (percentageInt < 73 && percentageInt >= 69.5)
return "3.00";
else if (percentageInt < 70 && percentageInt >= 0)
return "5.00";
else
return "INC";
catch (NumberFormatException e)
return "NE";
thank you
1