Если вы только учитесь работать с двумерными массивами, попробуйте это, так что вам не придется иметь дело с надоедливыми циклами и консолью.
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
public class Junk {
public static void main(String [] args) {
double pay[][] = {{30, 60, 88, 115, 140},
{26, 52, 70, 96, 120},
{24, 46, 67, 89, 110},
{22, 40, 60, 75, 88},
{20, 35, 50, 66,84}};
final JComboBox<Integer> ageCombo = new JComboBox<Integer>(new Integer[] {0, 1, 2, 3, 4});
final JComboBox<Integer> daysCombo = new JComboBox<Integer>(new Integer[] {1, 2, 3, 4, 5});
final JLabel costLabel = new JLabel();
JDialog dialog = new JDialog();
dialog.setLayout(new GridBagLayout());
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.add(new JLabel("Age of Child:"), new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(4, 4, 4, 4), 0, 0));
dialog.add(ageCombo, new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(4, 4, 4, 4), 0, 0));
dialog.add(new JLabel("Number of Days:"), new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(4, 4, 4, 4), 0, 0));
dialog.add(daysCombo, new GridBagConstraints(1, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(4, 4, 4, 4), 0, 0));
dialog.add(costLabel, new GridBagConstraints(0, 2, 2, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(4, 4, 4, 4), 0, 0));
final String costFmt = " Pay is $%.2f";
ItemListener listener = new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
int age = (Integer) ageCombo.getSelectedItem();
int days = (Integer) daysCombo.getSelectedItem() - 1;
costLabel.setText(String.format(costFmt, pay[age][days]));
}
}
};
costLabel.setText(String.format(costFmt, pay[0][0]));
ageCombo.addItemListener(listener);
daysCombo.addItemListener(listener);
dialog.setAlwaysOnTop(true);
dialog.pack();
dialog.setLocationRelativeTo(null);
dialog.setVisible(true);
} // End of main() method.
}