import java.util.Scanner; /** * An application to help determine whether you need to file taxes * * This class illustrates: * - Why helper methods should be private (instead of public) * - How private methods can help reduce the amount of repetition in your code * thereby making your code shorter, more readable, and easier to modify/extend/maintain. * * @author alchambers * @version sp19 */ public class BetterTaxHelper{ private static void printGreeting(){ 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("Please type \"yes\" or \"no\" for each question"); System.out.println("======================================="); System.out.println(); } private static boolean isYes(String question, Scanner input){ System.out.println("Are you married? (yes/no)"); String answer = input.nextLine(); return answer.equals("yes"); } private static void makeFinalDecision(int income, Scanner input){ String incomeQuestion = "Is your combined gross income more than $" + income; if(isYes(incomeQuestion, input)){ System.out.println("Yes, you must file taxes"); } else{ System.out.println("No, you do not need to file taxes"); } } // This main method is now 26 lines long! public static void main(String[] args){ printGreeting(); Scanner input = new Scanner(System.in); if(isYes("Are you married?", input)){ if(isYes("Are you and your spouse both over 65?", input)){ makeFinalDecision(30000, input); } else{ if(isYes("Is one of you over 65?", input)){ makeFinalDecision(27000, input); } else{ makeFinalDecision(25000, input); } } } else{ if(isYes("Are you over 65 years of age?", input)){ makeFinalDecision(27000, input); } else{ makeFinalDecision(24500, input); } } } }