/* Lesley Hogan * June 30th 2006 * ProblemSolver.java * What will be the purpose of your geek-gift? * CS 101 HW J3: * http://www.cs.virginia.edu/~asb/teaching/cs101-spring06/hws/hwj3/index.html */ package net.bunnie.uva.cs101; import java.util.*; public class ProblemSolver { public static void main(String args[]) { System.out.println("How good is your gift? Let's find out!"); // declarations final String[] QUESTION = {"Does it use electricity?", "Can you build with it?", "Is it weird?", "Does it glow?", "Is it Chernobyl blue?", "Is it red and/or green?", "Can you zap people with it?", "Does it vibrate?", "Does it include heavy water as a component?", "Will it create fear in the populace?"}; //int num = QUESTIONS.length; String[] answer = new String[QUESTION.length]; int i; for(i = 0; i < answer.length; i++) { answer[i] = new String(); } YesNoExtractor e = new YesNoExtractor(); //ask initial question and subsequent question answer[0] = String.valueOf(e.askUser(QUESTION[0])); if (answer[0].equals("true")) { answer[3] = String.valueOf(e.askUser(QUESTION[3])); } else { answer[1] = String.valueOf(e.askUser(QUESTION[1])); if (answer[1].equals("true")) { printResult(2); } } //ask some more questions, 2 more answers we can get rid of // we need some of these answers for later if (answer[1].equals("false")) { answer[2] = String.valueOf(e.askUser(QUESTION[2])); if (answer[2].equals("false")) { printResult(3); } } else if (answer[3].equals("true")) { answer[4] = String.valueOf(e.askUser(QUESTION[4])); if (answer[4].equals("false")) { answer[5] = String.valueOf(e.askUser(QUESTION[5])); if (answer[5].equals("false")) { printResult(0); } } } else { answer[6] = String.valueOf(e.askUser(QUESTION[6])); } //these questions have answers that you can get to multiple ways //and the question asked in the previous if is used in the next if if (answer[2].equals("true") || answer[6].equals("false")) { answer[7] = String.valueOf(e.askUser(QUESTION[7])); if (answer[7].equals("false")) { printResult(4); } } if (answer[4].equals("true") || answer[7].equals("true")) { answer[8] = String.valueOf(e.askUser(QUESTION[8])); if (answer[8].equals("false")) { printResult(6); } } if (answer[8].equals("true") || answer[6].equals("true")) { answer[9] = String.valueOf(e.askUser(QUESTION[9])); if (answer[9].equals("true")) { printResult(5); } } //could just print result, but why not check if (answer[9].equals("false") || answer[5].equals("true")) { printResult(1); } } static void printResult(int result) { final String[] RESULT = {"Rethink the color and start over", "It'll be used for Xmas lights. You watch.", "Your next gift will be made from lego or play-doh.", "It'll be regifted. Just saying.", "It'll be stripped for its parts.", "Now that's a gift! You will be thanked and worshipped for years to come.", "It'll become her or his only light source.",}; System.out.println(RESULT[result]); System.exit(0); } }