import java.util.ArrayList; import java.util.Scanner; /** * Console user interface for decision support application. * * @author Dr. Jody Paul * @version 4 April 2006 */ public class ConsoleUserInterface extends UserInterface { public ArrayList getChoices() { ArrayList alchoice = new ArrayList(); Scanner sc = new Scanner(System.in); System.out.print("Please enter one of the alternatives" + " that you are considering: "); String alternative = sc.nextLine(); while (alternative != null && !("".equals(alternative))) { alchoice.add(new Choice(alternative)); System.out.print("Please enter another alternative " + "(blank if all have been entered): "); alternative = sc.nextLine(); } return alchoice; } public ArrayList getCharacteristics() { ArrayList alchar = new ArrayList(); Scanner sc = new Scanner(System.in); System.out.print("Please enter one factor that would influence your choice" + " among alternatives: "); String characteristic = sc.nextLine(); while (characteristic != null && !("".equals(characteristic))) { alchar.add(new Characteristic(characteristic)); System.out.print("Please enter another attribute " + "(blank if all have been entered): "); characteristic = sc.nextLine(); } return alchar; } public void getCharacteristicRankings(ArrayList alc, int standard) { Scanner sc = new Scanner(System.in); int firstAttribute = 0; alc.get(firstAttribute).setRank(standard); System.out.print("\nAssume that " + alc.get(firstAttribute).getName() + " has an importance of " + standard + ",\n" + " and that higher values are more important.\n"); for (int i = firstAttribute + 1; i < alc.size(); i++) { System.out.print(" How important is " + alc.get(i).getName() + "? "); String importance = sc.nextLine(); if (importance == null || "".equals(importance)) { alc.get(i).setRank(standard); } else { alc.get(i).setRank(new Integer(importance)); } } } public double[][] getCrossRankings(ArrayList choices, ArrayList characteristics, int standard) { Scanner sc = new Scanner(System.in); double[][] crossRankings = new double[choices.size()][characteristics.size()]; for (int i = 0; i < characteristics.size(); i++) { int firstChoice = 0; crossRankings[firstChoice][i] = standard; System.out.println("\n\nConsidering " + characteristics.get(i).getName() + " only..."); System.out.println(" if " + choices.get(firstChoice).getName() + " has a value of " + standard + "... "); for (int j = firstChoice + 1; j < choices.size(); j++) { System.out.print(" ...what value would you associate with " + choices.get(j).getName() + ": "); String rank = sc.nextLine(); 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; } System.out.print("\n\n================\nPreferred choice: "); System.out.println(preferredChoice.getName()); System.out.println("-----"); for (Choice c : choices) { System.out.println(c.getName() + " == " + c.getFinalScore()); } } }