Matlab. You should save money for retirement from your very first paycheck. Luck
ID: 3666953 • Letter: M
Question
Matlab.
You should save money for retirement from your very first paycheck. Luckily, your company has a 401k (retirement savings plan) that will allow you to put a certain percentage of your salary (myContributionPercentage) aside in an investment account to grow tax-deferred until retirement.
Your contribution can not exceed $18000 per year.
50% of your contribution will be matched by your company up to 6% of your salary.
Write a function with the header:
function [totalContribution] = my401kCalculator(salary, myContributionPercentage)
Which calculates how much money you will save per year in the 401k based on the percentage of your salary you set aside in the 401k. If your contribution exceeds $18000, the function should return $18000.
Test Cases:
>> my401kCalculator(30000,.07)
ans =
3000
>> my401kCalculator(30000,.3)
ans =
9900
>> my401kCalculator(30000,.75)
The contribution limit for your salary is 60.0%
ans =
18900
Explanation / Answer
function Tfunction5(~,~)
initialInvestement = fix(get(h1, 'Value'));
yearlyStockIncreaseRate = round(get(h2, 'Value'),1);
yearsInvestement = fix(get(h3, 'Value'));
monthlyContribution = fix(get(h4, 'Value'));
Sum = initialInvestement;
for month = 1:1:yearsInvestement*12
Sum = Sum + monthlyContribution + (Sum + monthlyContribution)*yearlyStockIncreaseRate*0.01/12;
end
uicontrol('style', 'text', 'position', [270 220 250 25],...
'string', sprintf('%15.5f',Sum)) ;
end
end