unit Zins1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls;

type
  TZins = class (TObject)
    Kapital,
    Prozent,
    Zinsen: Single;
    constructor Create;
    procedure SetKapital (Txt: String);
    procedure SetProzent (Txt: String);
    procedure SetZinsen  (Txt: String);
    function  GetKapital: String;
    function  GetProzent: String;
    function  GetZinsen:  String;
  end;

  TForm1 = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    Label1: TLabel;
    Button1: TButton;
    Button2: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private-Deklarationen }
    procedure SetZero;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  Zins : TZins;
  Modus: Integer;

implementation

{$R *.DFM}

constructor TZins.Create;
begin
  inherited Create;
end;

procedure TZins.SetKapital (Txt: String);
begin
  Kapital := StrToFloat (Txt);
end;

procedure TZins.SetProzent (Txt: String);
begin
  Prozent := StrToFloat (Txt);
end;

procedure TZins.SetZinsen (Txt: String);
begin
  Zinsen := StrToFloat (Txt);
end;

function TZins.GetKapital: String;
begin
  Kapital := Zinsen * 100 / Prozent;
  GetKapital := FloatToStrF(Kapital,ffNumber,8,2);
end;

function TZins.GetProzent: String;
begin
  Prozent := Zinsen * 100 / Kapital;
  GetProzent := FloatToStrF(Prozent,ffNumber,8,2);
end;

function TZins.GetZinsen:  String;
begin
  Zinsen := Kapital * Prozent / 100;
  GetZinsen := FloatToStrF(Zinsen,ffNumber,8,2);
end;

procedure TForm1.SetZero;
begin
  Zins.Kapital := 0;
  Zins.Prozent := 0;
  Zins.Zinsen  := 0;
  Edit1.Text := '0';
  Edit2.Text := '0';
  Edit3.Text := '0';
  Modus := 0;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Zins := TZins.Create;
  SetZero;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  SetZero;
  Label1.Caption :=
    'Setze nur die gesuchte Größe auf null!';
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Label1.Caption := 'Das ist das Ergebnis';
  Zins.SetKapital (Edit1.Text);
  if Edit1.Text = '0' then inc (Modus);
  Zins.SetProzent (Edit2.Text);
  if Edit2.Text = '0' then inc (Modus,10);
  Zins.SetZinsen (Edit3.Text);
  if Edit3.Text = '0' then inc (Modus,100);
  case Modus of
    1  : Edit1.Text := Zins.GetKapital;
    10 : Edit2.Text := Zins.GetProzent;
    100: Edit3.Text := Zins.GetZinsen;
    else
      Label1.Caption := 'Keine oder zu viele Nullen!';
  end;
  Modus := 0;
end;

end.
