解决方案 »
- 继承TWinControl实现控件异常
- 关于图片打印问题,向各位请教
- 如何还原数据库最好
- 因为我现在没有工具书,只有靠大家帮忙啊。问题很简单。
- 我在安装已编译的dcu文件(没有pas文件),通过install into a new companent或exist companent安装,怎么老是报错:未找到*.pas文件,请问
- 如何从一幅bmp图片中截取一个椭圆形的部分,然后另存为一幅图片
- 如何将 ADODataSet 和 ADOQuery 设置为可更新和可插入?
- 各位大侠把各类数据库的访问速度,以及各种引擎的速度做个测试对比吧?也算是个总结!
- 求救!!
- SQL查询速度的问题?
- 请问大虾们,这个C怎么转成delphi?谢谢!
- listview选中多行拖动如何实现?
为负时则还款 为正则无还款
SysUtils,
Classes;type
TPhase = class
private
FNeedPay: Integer;
FActualPaid: Integer;
public
constructor Create(const needpay: Integer);
property NeedPay: Integer read FNeedPay write FNeedPay;
property ActualPaid: Integer read FActualPaid write FActualPaid;
end; TPhaseList = class(TList)
private
public
constructor Create(const payperphase, phaseamount: Integer);
procedure Clear(); override;
function Pay(const paid, phase: Integer): Boolean;
procedure Print();
end;{ TPhase }constructor TPhase.Create(const needpay: Integer);
begin
FNeedPay := needpay;
end;{ TPhaseList }procedure TPhaseList.Clear;
var
i: Integer;
begin
for i := 0 to Count - 1 do
begin
TObject(Items[i]).Free;
end;
inherited;
end;constructor TPhaseList.Create(const payperphase, phaseamount: Integer);
var
i: Integer;
begin
inherited Create();
for i := 1 to phaseamount do
begin
Add(TPhase.Create(payperphase));
end;
end;
var
PhaseList: TPhaseList;function TPhaseList.Pay(const paid, phase: Integer): Boolean;
var
i: Integer;
totalpaid: Integer;
begin
Result := False;
if (phase < 1) or (phase > Count) then
Exit;
totalpaid := paid;
with TPhase(Items[phase - 1]) do
begin
ActualPaid := paid;
totalpaid := totalpaid - NeedPay;
end;
for i := phase to Count - 1 do
begin
with TPhase(Items[i]) do
begin
totalpaid := totalpaid - NeedPay;
if totalpaid >= 0 then
begin
NeedPay := 0;
end
else
begin
NeedPay := -totalpaid;
Break;
end;
end;
end;
Result := totalpaid <= 0;
end;procedure TPhaseList.Print();
var
i: Integer;
begin
Writeln('期数'#9'当期应还金额'#9'实际还款金额');
for i := 0 to Count - 1 do
begin
with TPhase(Items[i]) do
begin
Writeln(Format('%d'#9'%d'#9#9'%d',[i+1, NeedPay, ActualPaid]));
end;
end;
end;begin
PhaseList := TPhaseList.Create(200, 10); //10期 每期200
PhaseList.Print();
PhaseList.Pay(500, 1); //第一期还了500
PhaseList.Print();
PhaseList.Pay(400, 6); //第六期还了400
PhaseList.Print();
PhaseList.Pay(200, 9); //第六期还了400
PhaseList.Print();
end.