import java.util.ArrayList; import javax.swing.JOptionPane; /** * Graphical user interface for decision support application. * * @author Dr. Jody Paul * @version 4 April 2006 */ public class GraphicalUserInterface extends UserInterface { public ArrayList getChoices() { ArrayList alchoice = new ArrayList(); String alternative = JOptionPane.showInputDialog( "Please enter one of the alternatives" + " that you are considering. (Cancel to quit.)"); while (alternative != null && !("".equals(alternative))) { alchoice.add(new Choice(alternative)); alternative = JOptionPane.showInputDialog( "Please enter another alternative. (Leave blank if all have been entered.)"); } return alchoice; } public ArrayList getCharacteristics() { ArrayList alchar = new ArrayList(); String characteristic = JOptionPane.showInputDialog( "Please enter one factor that would influence your choice\n" + "among alternatives. (Cancel to quit.)"); while (characteristic != null && !("".equals(characteristic))) { alchar.add(new Characteristic(characteristic)); characteristic = JOptionPane.showInputDialog( "Please enter another attribute. (Leave blank if all have been entered.)"); } return alchar; } public void getCharacteristicRankings(ArrayList alc, int standard) { int lastAttribute = alc.size() - 1; for (int i = 0; i < lastAttribute; i++) { String importance = JOptionPane.showInputDialog( "If " + alc.get(lastAttribute).getName() + " has an importance of " + standard + ",
" + "how important is " + alc.get(i).getName() + "?"); if (importance == null || "".equals(importance)) { alc.get(i).setRank(standard); } else { alc.get(i).setRank(new Integer(importance)); } } alc.get(lastAttribute).setRank(standard); } public double[][] getCrossRankings(ArrayList choices, ArrayList characteristics, int standard) { double[][] crossRankings = new double[choices.size()][characteristics.size()]; for (int i = 0; i < characteristics.size(); i++) { int firstChoice = 0; crossRankings[firstChoice][i] = standard; for (int j = firstChoice + 1; j < choices.size(); j++) { String rank = JOptionPane.showInputDialog( "Considering " + characteristics.get(i).getName() + " only,
" + "if " + choices.get(firstChoice).getName() + " has a value of " + standard + " " + ",
" + "what value would you associate with " + choices.get(j).getName() + "
(a higher value is more desirable)?"); if (rank == null || "".equals(rank)) { crossRankings[j][i] = standard; } else { crossRankings[j][i] = new Integer(rank); } } } return crossRankings; } public void showResults(ArrayList choices) { Choice preferredChoice = choices.get(0); int max = 0; for (Choice c : choices) { if (max < c.getFinalScore()) max = c.getFinalScore(); } for (Choice c : choices) { if (max == c.getFinalScore()) preferredChoice = c; } String s = "Preferred choice: "; s += preferredChoice.getName(); s += "\n-----\n"; for (Choice c : choices) { s += c.getName() + " == " + c.getFinalScore() + "\n"; } JOptionPane.showMessageDialog(null, s, "Decider Results", JOptionPane.INFORMATION_MESSAGE); } }