unit uHouseCheckXXXX;

interface

uses Classes, SysUtils;

type THouseCheckXXXX = class
  private
    fServices : String;
    fNumDays : integer;
  public
    constructor Create(iNumber : integer; sServ : String);
    function toString : String;
    procedure extendDays(iDays : integer);
    function getTotalCost : real;
    function isServiceNeeded(cServ : char) : boolean;
    function getServicesForDay(iDay : integer) : String;
end;

implementation

{ THouseCheck }

constructor THouseCheckXXXX.Create(iNumber: integer; sServ: String);
begin
  fNumDays := iNumber;
  fServices := sServ;
end;

procedure THouseCheckXXXX.extendDays(iDays: integer);
begin
  inc(fNumDays, iDays);
end;

function THouseCheckXXXX.getServicesForDay(iDay: integer): String;
var
  sServStr : String;
begin
  sServStr := '';

  if isServiceNeeded('A') then
    sServStr := sServStr + 'Feed pets' + #9;
  if (isServiceNeeded('C') AND (iDay MOD 2 = 0)) then
    sServStr := sServStr + 'Check windows and doors ' + #9;
  if (isServiceNeeded('P') AND (iDay MOD 3 = 0)) then
    sServStr := sServStr + 'Empty post box';

  if sServStr = '' then
    sServStr := 'No services for the day';

  Result := sServStr;
end;

function THouseCheckXXXX.getTotalCost: real;
var
  rTotalCost : real;
begin
  rTotalCost := 0;

  if isServiceNeeded('A') then
		rTotalCost := rTotalCost + fNumDays * 5;
	if isServiceNeeded('C') then
    rTotalCost := rTotalCost + fNumDays DIV 2 * 6;
	if isServiceNeeded('P') then
    rTotalCost := rTotalCost + fNumDays DIV 3 * 4;

  Result := rTotalCost;
end;

function THouseCheckXXXX.isServiceNeeded(cServ: char): boolean;
begin
  if (Pos(cServ, fServices) > 0) then
    Result := true
  else
    Result := false;
end;

function THouseCheckXXXX.toString: String;
var
  i : integer;
  sStr : String;
begin
  sStr := '';

  for i := 1 to fNumDays do
    begin
      sStr := sStr + IntToStr(i) + #9 + getServicesForDay(i) + #13;
    end;

  Result := sStr;
end;

end.
