??? Too many input arguments.

3 ビュー (過去 30 日間)
Thang Nguyen
Thang Nguyen 2013 年 1 月 16 日
I follow example in Matalb Object Oriented> Hiearchy to create a parent class called DocAsset and child class called DocBond. I included the text of these classes below cause I cannot find how to attach file. When I try to create an instant of the class I got these error messages: >> t = DocBond ??? Too many input arguments.
Error in ==> DocBond>DocBond.DocBond at 12 function obj = DocBond(description,faceValue,yield,currentBondYield)
>> t = DocBond('bond 1',1,2,3) ??? Too many input arguments.
Error in ==> DocBond>DocBond.DocBond at 12 function obj = DocBond(description,faceValue,yield,currentBondYield)
I believe constructor should be able to handle with variant input argument otherwise I have correct number of input.
%========================================
classdef DocAsset
properties
description = '';
currentValue = 0;
end
properties (SetAccess = private)
dateOpen;
type = AssetType.Savings;
end
methods
function obj = DocAsset(description,currentValue,type)
if nargin > 0
a.description = description;
a.dateOpen = date;
a.type = type;
a.currentValue = currentValue;
end
end
function obj = setType(obj,type)
if (type ~= AssetType.Bond || type ~= AssetType.Stock || type ~= AssetType.Savings)
error('Type must be an enum AssetType');
end
obj.Type = type;
end
function disp(obj)
fprintf('Description: %s\nDate: %s\nType: %s\nCurrentValue:%9.2f\n',...
obj.description,obj.dateOpen,obj.type,obj.currentValue);
end
end
end
%========================================
classdef DocBond < DocAsset
properties
faceValue = 0;
yield = 0;
currentBondYield = 0;
end
methods
function obj = DocBond(description,faceValue,yield,currentBondYield)
if nargin ~= 4
description = '';
faceValue = 0;
yield = 0;
currentBondYield = 0;
end
marketValue = DocBond.CalcValue(faceValue,yield,currentBondYield);
obj = obj@DocAsset(description,marketValue,AssetType.Bond);
obj.faceValue = faceValue;
obj.yield = yield;
obj.currentBondYield = currentBondYield;
end
function disp(obj)
disp@DocAsset(obj);
fprintf('Face value of bonds: $%g\nYield: %3.2f%%\n',...
obj.faceValue,obj.yield);
end
end
methods (Static)
function marketValue = CalcValue(faceValue,yield,currentYield)
if currentYield <= 0 || yield <= 0
marketValue = faceValue;
else
marketValue = faceValue*yield/currentYield;
end
end
end
end
%============================
classdef(Enumeration) AssetType
enumeration
bond(0)
stock(1)
savings(2)
end
end
  2 件のコメント
Thang Nguyen
Thang Nguyen 2013 年 1 月 16 日
編集済み: Thang Nguyen 2013 年 1 月 16 日
Hi, I put it here hope you can load it. Let me know if you cannot https://docs.google.com/file/d/0B2xR6sx29-9hRDQ3dVAzTzVYLXM/edit In project, I modified a little bit by using enum instead of string.

サインインしてコメントする。

採用された回答

Thang Nguyen
Thang Nguyen 2013 年 1 月 16 日
I found the answer, because I replaced string by eNum and I cannot use %s to print enum. The issue is error message here is not helpful at all.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConstruct and Work with Object Arrays についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by