function tax = fedTax2019(agi,varargin)
%
%
%
BracketsSingle =   [ 9700     .1;
                     39475    .12;
	             84201    .22;
		     160726   .24;
		     204100   .32;
		     510300   .35;
		     510301   .37];
%		 
BracketsMarried =  [ 19400     .1;
                     78950    .12;
		     168400   .22;
	             321450   .24;
		     408200   .32;
		     612350   .35;
		     612351   .37];

if( agi < 0 )
  fprintf('Agi must be > 0.\n');
  return
end

if( nargin == 1 ) 
  status = 'S'; 
else
  status = varargin{1};
end
		   
if( strcmpi(status, 'M') )
  brackets = BracketsMarried;
  fprintf('\nMarital status = married.\n');
else
  fprintf('\nMarital status = single.\n');
  brackets = BracketsSingle;
end

tax = 0;
i = 1;
while( agi > brackets(i,1) )
  if( i == 1 )
    tax = tax + brackets(i,1)*brackets(i,2);
  else
    tax = tax + (brackets(i,1)-brackets(i-1,1))*brackets(i,2);
  end
  i = i+1;  
  if( i > ( length(brackets) -1 ) )
    break;
  end
end
tax = tax + (agi - brackets(i-1,1) )*brackets(i,2);

fprintf('\nEffective Fed Tax Rate = %.2f%%\n\n',tax/agi*100)

return
