Я пытаюсь получить оператор if, else if, else для определения выходных данных, используя математику и значения из объектов.
//Define variables for the output
int courseTuitionv1 = (int)course1.getTotalTuition();
int courseTuitionv2 = (int)course2.getTotalTuition();
//Calulate the differences
int difference = (courseTuitionv2 - courseTuitionv1);
int difference2 = (courseTuitionv1 - courseTuitionv2);
//An if else construct that determines which course costs more or if they are the same and
//displays the corresponding dialog box
if (courseTuitionv2 > courseTuitionv1) {
JOptionPane.showMessageDialog(null, Coursev2 + " tuition exceeds " + Coursev1 + " tuition by $" + difference );
}
else if (courseTuitionv1 > courseTuitionv2) {
JOptionPane.showMessageDialog(null, Coursev1 + " tuition exceeds " + Coursev2 + " tuition by $" + difference2 );
}
else {
JOptionPane.showMessageDialog(null, Coursev1 + " and " + Coursev2 + " have the same tuition." );
следует использовать диалоговое окно, чтобы показать, имеют ли они одинаковую стоимость обучения или стоит одна дороже другой.