import java.util.Scanner; /** * This class implements a flowchart to help the user decided whether * or not they need to file taxes. * * This class illustrates: * - The use of nested conditionals * - The use of private methods * * @author alchambers * @version Fall2015 */ public class TaxHelper{ private Scanner scan; /** * Creates a new tax helper */ public TaxHelper(){ scan = new Scanner(System.in); printWelcomeMessage(); } /** * Helps the user determine whether or not they need to file taxes * This method is 101 lines of code long! */ public void determineFilingStatus(){ boolean isYes = questionAnswer("Are you single? (y/n)"); // Single if(isYes){ isYes = questionAnswer("Are you under 65 years of age?"); askFinalIncomeQuestion(isYes, 8450, 9700); } // Married else{ isYes = questionAnswer("Are you and your spouse both over 65?"); // Over 65 if(isYes){ printTaxStatus(23000); } // At least one person is under 65 else{ isYes = questionAnswer("Are you and your spouse both under 65?"); askFinalIncomeQuestion(isYes, 20600, 21800); } } } /*================================================================ * Below are the private helper methods *================================================================*/ /** * Asks the final question in the flow chart which is always * related to the user's income level */ private void askFinalIncomeQuestion(boolean isYes, int income1, int income2){ if(isYes){ printTaxStatus(income1); } else{ printTaxStatus(income2); } } /** * Prints a question to the screen and then scans and returns * the user's answer */ private boolean questionAnswer(String question){ System.out.println(question); String input = scan.nextLine(); boolean answer = input.equals("y"); return answer; } /** * Prints the final decision based upon income */ private void printTaxStatus(int income){ boolean isYes = questionAnswer("Is your gross income less than $" + income + "?"); // Less than income threshold if(isYes){ System.out.println("No, you do not need to file taxes"); } // More than income threshold else{ System.out.println("Yes, you must file taxes"); } } /** * Prints a welcome message to the user */ private void printWelcomeMessage(){ System.out.println("======================================="); System.out.println("Welcome to the Tax Center!"); System.out.println("We offer non-professional tax help."); System.out.println("Use at your own risk!"); System.out.println("======================================="); System.out.println(); } }