unit TTyreUnit;

interface

uses SysUtils;

  type TTyre = class(TObject)
    private
      fTID : String;
      fsBrand : String;
      fsModel : String;
      fsSize : String;
      fsType : String;
      frDiameter : Real;
      frTreadWear : Real;
      frWeight : Real;
      fsWidths : String;
      fIsDirectional : Boolean;
      fIsAsymetrical : Boolean;
                                      //275/35R18
    public
      constructor create;
      constructor setData(
        TID : String;
        sBrand : String;
        sModel : String;
        sSize : String;   // mm
        sType : String;
        rDiameter : Real;   // inches
        rTreadWear : Real;  //
        rWeight : Real;     // pounds
        sWidths : String;   // inches
        IsDirectional : Boolean;
        IsAsymetrical : Boolean);

     function getSizeStr:String;
     function toStr: String;         //275/35R18
     function getTireWidth : Real;
     function getRelTireHeight : Real;
     function getRimSize : Real;
     function getTreadWearDesc : String;



  end;



implementation

{ TTire }

constructor TTyre.create;
begin
        fTID  := '';
        fsBrand := '';
        fsModel := '';
        fsSize := '';
        fsType  :='';
        frDiameter := 0;
        frTreadWear := 0;
        frWeight := 0;
        fsWidths := '';
        fIsDirectional := false;
        fIsAsymetrical := false;
end;

constructor TTyre.setData(TID, sBrand, sModel, sSize, sType: String;
  rDiameter, rTreadWear, rWeight: Real; sWidths: String; IsDirectional,
  IsAsymetrical: Boolean);
begin
        fTID  :=TID;
        fsBrand := sBrand;
        fsModel := sModel;
        fsSize := sSize;
        fsType  :=sType;
        frDiameter := rDiameter;
        frTreadWear := rTreadWear;
        frWeight := rWeight;
        fsWidths := sWidths;
        fIsDirectional := IsDirectional;
        fIsAsymetrical := IsAsymetrical;

end;

function TTyre.getRelTireHeight: Real;
  var
    sW , sP , temp : String;
    rH : Real;
    cPos : Integer;
begin
 // 225/45R15
   temp :=  fsSize;
   cPos :=  Pos('/',temp);
   sW := copy(temp,1,cPos-1);
   delete(temp,1,cPos);
   cPos :=  pos('R',temp);
   sP := copy(temp,1,cPos-1);

   rH := StrToFloat(sW) * (StrToFloat(sP) / 100);
   Result := rH;

end;

function TTyre.getRimSize: Real;
  var
    sW , sP , temp : String;
    rH : Real;
    cPos : Integer;
begin
   temp :=  fsSize;
   cPos :=  Pos('R',temp);

   Result := StrToFloat(copy(fsSize,cPos+1,2));

end;

function TTyre.getSizeStr: String;
begin
    Result := fsSize;
end;

function TTyre.getTireWidth: Real;
  var
    sW , sP , temp : String;
    rH : Real;
    cPos : Integer;
begin
   temp :=  fsSize;
   cPos :=  Pos('/',temp);

   Result := StrToFloat(copy(fsSize,1,cPos-1));
end;

function TTyre.toStr: String;
begin
   Result := 'ID = ' + fTID + ' Brand: ' + fsBrand + ' Size: ' + fsSize;
end;


function TTyre.getTreadWearDesc : String;
var
  Wear : Real;
  sTemp : String;
begin
  Wear :=  frTreadWear * 100;
  sTemp := 'Tread wear  [' + FloatToStrF(frTreadWear,ffFixed,4,0) + ']';
  sTemp := STemp + #13 + 'Approximately : ' + FloatToStrF(Wear,ffFixed,8,0) + ' to ';
  sTemp := STemp +  FloatToStrF(Wear + 10000 ,ffFixed,8,0) + ' kilometres of wear ';
  Result := sTemp;
end;

end.
