MATLAB Object-Oriented Programming

(Joyce) #1
title(stg,'FontSize',10)
end

Create an Assets Array

These statements create a heterogeneous array by concatenating the Stocks, Bonds,
and Cash objects. Calling the makeReport and pie methods creates the output shown.

s = financial.Stocks('Acme Motor Company',100,string('A'));
b = financial.Bonds('3 Month T',700,0.3);
c(1) = financial.Cash('Bank Account',500);
c(2) = financial.Cash('Gold',500);
assetArray = [s,b,c];
makeReport(assetArray)
pie(assetArray)

Description Type Value
____________________ ______ ______

'Acme Motor Company' Stocks 1232.5
'3 Month T' Bonds 807.69
'Bank Account' Cash 500
'Gold' Cash 500

20 Designing Related Classes

Free download pdf