prompt=input(‘Do you have MATLAB on your computer? (y/n)’,‘s’)
if strcmpi(prompt, ‘y’)
disp(‘Copy the code below and enter it into MATLAB and hit run!’)
elseif strcmpi(prompt, ‘n’)
disp(‘Copy the code below and enter it into command line on Octave’)
else
disp('Error: invalid input. Press any key to terminate script.')
pause
return
end
Do you have MATLAB on your computer?
If yes, copy the code below and enter it into MATLAB and hit run!
If no, copy the code below and enter it into the command line on Octave
%Andrew J Baldassarre %This is a code for helping to budget and plan to pay off student loan %debts %IncomeTarget determines tax based on the 2020-2021 federal tax brackets and rates clc clear var = 5; while var < 100 %federal tax brackets: tb1 = 9875; tb2 = 40125; tb3 = 85525; tb4 = 163300; tb5 = 207350; tb6 = 518400; %federal tax rates: tr1 = 0.1; tr2 = 0.12; tr3 = 0.22; tr4 = 0.24; tr5 = 0.32; tr6 = 0.35; tr7 = 0.37; while var == 5 var = 4; while var == 4 question = input('Do you have student loans? (y/n) ','s'); if strcmpi(question, 'y') var = 2; elseif strcmpi(question, 'n') var = 3; elseif strcmpi(question, 'test') var = 3.5; else disp('Please enter ''y'' or ''n''.'); var = 4; end end % TOGGLE LOAN CALCULATOR ON/OFF while var == 3.5 t = 1; P = 0; rate = 1; loan1 = (P/(12*t)); loan2 = (1+(rate/1200))^(12*t); loan_payment = loan1*loan2; R = randi([0 10000], 1); U = randi([0 1000], 1); E = randi([0 10000], 1); monthly_cost = R+U+E; monthly_net_expense = monthly_cost+loan_payment; Minimum_Income = monthly_net_expense*12; Income_Target = Minimum_Income*(1.25/1000); fprintf('Your annual net income target should be (thousands of USD): %.3f %.3f\n',Income_Target); hourly = Income_Target/(2); disp(' ') var = 0.5; end % TEST SETTINGS while var == 3 t = 1; P = 0; rate = 1; loan1 = (P/(12*t)); loan2 = (1+(rate/1200))^(12*t); loan_payment = loan1*loan2; R = input('What is your average rent payment? '); U = input('What is your average utility bill? '); E = input('What is your other average monthly expenditure (food, recreation, bills, etc)? '); monthly_cost = R+U+E; monthly_net_expense = monthly_cost+loan_payment; Minimum_Income = monthly_net_expense*12; Income_Target = Minimum_Income*(1.25/1000); disp(' ') fprintf('Your annual net income target should be (thousands of USD): %.3f %.3f\n',Income_Target); hourly = Income_Target/(2); disp(' ') var = 1; end % LIVING EXPENSES while var == 2 t = input('How many years to pay off student loan debt? '); P = input('What is the sum of your principle loans? '); rate = input('what is your approximate average interest rate on that debt in percentage (i.e. for 6% write "6")? '); loan1 = (P/(12*t)); loan2 = (1+(rate/1200))^(12*t); loan_payment = loan1*loan2; R = input('What is your average rent payment? '); U = input('What is your average utility bill? '); E = input('What is your other average monthly expenditure (food, recreation, bills, etc)? '); disp(' ') monthly_cost = R+U+E; monthly_net_expense = monthly_cost+loan_payment; Minimum_Income = monthly_net_expense*12; Income_Target = Minimum_Income*(1.25/1000); fprintf('Your annual net income target should be (thousands of USD): %.3f %.3f\n',Income_Target); hourly = Income_Target/(2); disp(' ') var = 1; end % STUDENT LOAN CALCULATOR AND LIVING EXPENSES while var == 1 disp(' ') answer = input('Would you like to know if you make enough? (y/n) ','s'); if strcmpi(answer, 'y') pay_form = input('Is your pay salaried or wage-based? (w/s) ','s'); if strcmpi(pay_form, 'w') Wage = input('What is your hourly wage? '); Hours = input('How many hours a week do you work? '); Weeks = input('How many weeks a year do you work? '); real_income = Weeks*Hours*Wage; elseif strcmpi(pay_form, 's') real_income = input('What is your annual salary? '); else disp('Error: invalid input. Press any key to terminate script.') pause return end ri = real_income; if ri <= tb1 tax = ri*tr1; ti = ri - tax; elseif ri > tb1 && ri <= tb2 tax = tr1*tb1 + tr2*(ri-tb1); ti = ri - tax; elseif ri > tb2 && ri <= tb3 tax = tr1*tb1 + tr2*(tb2-tb1) + tr3*(ri-tb2); ti = ri - tax; elseif ri > tb3 && ri <= tb4 tax = tr1*tb1 + tr2*(tb2-tb1) + tr3*(tb3-tb2) + tr4*(ri-tb3); ti = ri - tax; elseif ri > tb4 && ri <= tb5 tax = tr1*tb1 + tr2*(tb2-tb1) + tr3*(tb3-tb2) + tr4*(tb4-tb3) + tr5*(ri-tb4); ti = ri - tax; elseif ri > tb5 && ri <= tb6 tax = tr1*tb1 + tr2*(tb2-tb1) + tr3*(tb3-tb2) + tr4*(tb4-tb3) + tr5*(tb5-tb4) + tr6*(ri-tb5); ti = ri - tax; else tax = tr1*tb1 + tr2*(tb2-tb1) + tr3*(tb3-tb2) + tr4*(tb4-tb3) + tr5*(tb5-tb4) + tr6*(tb6-tb5) + tr7*(ri-tb6); ti = ri - tax; end effective_tax_rate = 1 - ti/ri; taxed_income = ti; disp(' ') if taxed_income/1000 > Income_Target disp('You are exceeding the necessary target after tax!'); Excess = taxed_income - 1000*Income_Target; disp(' ') fprintf('Excess: %.3f %.3f\n',Excess); elseif taxed_income/1000 < Income_Target disp('You are coming up short of the necessary target after taxes'); Deficit = abs(taxed_income - 1000*Income_Target); disp(' ') fprintf('Deficit: %.2f %.2f\n',Deficit); else disp('You are exactly hitting the necessary target'); disp(' ') end disp(' ') disp(' ') fprintf('Effective Tax Rate: %.2f%% %.2f\n',effective_tax_rate*100); var = 0; elseif strcmpi(answer, 'n') var = 0; else disp('Please enter ''y'' or ''n''.'); var = 1; end end % REAL INCOME CHECK while var == 0.5 Wage = randi([0 100], 1); Hours = randi([0 168], 1); Weeks = randi([0 52], 1); real_income = Weeks*Hours*Wage; ri = real_income; if ri <= tb1 tax = ri*tr1; ti = ri - tax; elseif ri > tb1 && ri <= tb2 tax = tr1*tb1 + tr2*(ri-tb1); ti = ri - tax; elseif ri > tb2 && ri <= tb3 tax = tr1*tb1 + tr2*(tb2-tb1) + tr3*(ri-tb2); ti = ri - tax; elseif ri > tb3 && ri <= tb4 tax = tr1*tb1 + tr2*(tb2-tb1) + tr3*(tb3-tb2) + tr4*(ri-tb3); ti = ri - tax; elseif ri > tb4 && ri <= tb5 tax = tr1*tb1 + tr2*(tb2-tb1) + tr3*(tb3-tb2) + tr4*(tb4-tb3) + tr5*(ri-tb4); ti = ri - tax; elseif ri > tb5 && ri <= tb6 tax = tr1*tb1 + tr2*(tb2-tb1) + tr3*(tb3-tb2) + tr4*(tb4-tb3) + tr5*(tb5-tb4) + tr6*(ri-tb5); ti = ri - tax; else tax = tr1*tb1 + tr2*(tb2-tb1) + tr3*(tb3-tb2) + tr4*(tb4-tb3) + tr5*(tb5-tb4) + tr6*(tb6-tb5) + tr7*(ri-tb6); ti = ri - tax; end effective_tax_rate = 1 - ti/ri; taxed_income = ti; disp(' ') if taxed_income/1000 > Income_Target disp('You are exceeding the necessary target after tax!'); Excess = taxed_income - 1000*Income_Target; disp(' ') fprintf('Excess: %.3f %.3f\n',Excess); elseif taxed_income/1000 < Income_Target disp('You are coming up short of the necessary target after'); Deficit = abs(taxed_income - 1000*Income_Target); disp(' ') fprintf('Deficit: %.2f %.2f\n',Deficit); else disp('You are exactly hitting the necessary target'); disp(' ') end disp(' ') disp(' ') fprintf('Effective Tax Rate: %.2f%% %.2f\n',effective_tax_rate*100); var = 0; end % TEST SETTINGS disp(' ') disp(' ') while var == 0 disp('End Program') var = 1000; end % END PROGRAM end % THINKING PART end