{"id":896,"date":"2023-09-02T12:50:53","date_gmt":"2023-09-02T10:50:53","guid":{"rendered":"https:\/\/oopm.org\/?page_id=896"},"modified":"2024-10-28T16:17:52","modified_gmt":"2024-10-28T15:17:52","slug":"3-2-using-the-three-account-objects","status":"publish","type":"page","link":"https:\/\/oopm.org\/?page_id=896","title":{"rendered":"3.2 Using the three account objects"},"content":{"rendered":"<div class=\"pdfprnt-buttons pdfprnt-buttons-page pdfprnt-top-right\"><a href=\"https:\/\/oopm.org\/index.php?rest_route=wpv2pages896&print=pdf\" class=\"pdfprnt-button pdfprnt-button-pdf\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/oopm.org\/wp-content\/plugins\/pdf-print\/images\/pdf.png\" alt=\"image_pdf\" title=\"View PDF\" \/><\/a><a href=\"https:\/\/oopm.org\/index.php?rest_route=wpv2pages896&print=print\" class=\"pdfprnt-button pdfprnt-button-print\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/oopm.org\/wp-content\/plugins\/pdf-print\/images\/print.png\" alt=\"image_print\" title=\"Print Content\" \/><\/a><\/div>\n<p class=\"wp-block-paragraph\">In this section, we describe a clerk that perform activities that involve all three account objects.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>anotherClerk: <strong>obj<\/strong>\n   handle:\n      newBalance: <strong>var<\/strong> float\n      newBalance := account_1010.deposit(200)\n      newBalance := account_1022.deposit(300)\n      newBalance := account_1025.deposit(400)\n      newBalance := account_2022.withdraw(50)\n      account_1010.addInterest<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">As with the clerk in section <script>mkRef(\"The first program\");<\/script>, this clerk invokes methods in the three <code>Account<\/code> objects.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We may assemble the clerk, class <code>Account<\/code> and the declarations of the three <code>Account<\/code> objects in a <code>microBank<\/code> object:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>microBank: <strong>obj<\/strong>\n   anotherClerk: <strong>obj<\/strong>\n      handle:\n         newBalance: <strong>var<\/strong> float\n         newBalance := account_1010.deposit(200)\n         -\"-\n   <strong>class<\/strong> Account:\n      -\"-\n   account_1010: <strong>obj<\/strong> Account(\"John Smith\")\n   account_1022: <strong>obj<\/strong> Account(\"Liza Jones\")\n   account_1025: <strong>obj<\/strong> Account(\"Tina Turner\")\n   anotherClerk.handle<\/code><\/pre>\n\n\n\n<p class=\"has-normal-font-size wp-block-paragraph\">The <code>microBank<\/code> description is another example of a complete program that may be compiled and executed by a computer &#8211; assuming that a qBeta compiler exists for the computer.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Comments<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To improve readability of programs, it is possible to add comments in the form of text that explains the program, or elements of the program. In general, it is important that the code in a program is understandable as it is, but sometimes it is necessary to add an explanation to help the reader.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A comment has the form:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-- This is a comment<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Everything from the <code>'--'<\/code> to the end-of-line is ignored by the compiler and has no influence on the execution of the program. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the next example we have added a comment to the <code>microBank<\/code> example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>microBank: <strong>obj<\/strong>\n   -- This program is an example of a program that demonstrates the use of class Account\n   -- The objects anotherClerk, account_1010, account_1022, and account_1025\n   -- only play the role of demonstrating how class Account may be used\n   -- Author: Donald Duck\n   anotherClerk: <strong>obj<\/strong>\n      -\"-\n   <strong>class<\/strong> Account:\n      -\"-\n   account_1010: <strong>obj<\/strong> Account(\"John Smith\")\n   account_1022: <strong>obj<\/strong> Account(\"Liza Jones\")\n   account_1025: <strong>obj<\/strong> Account(\"Tina Turner\")\n   anotherClerk.handle<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It is good practice to describe at the start of a program what it is supposed to model\/do and include the name(s) of authors, and possible other information such as dates.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For program elements like class <code>Account<\/code> one may also write a comment explaining the intension of this class. We may e.g. write: &#8211;<code>- This class is supposed to represent\/model a bank account<\/code>. However, such a comment does not say more than the name <code>Account<\/code>, so we recommend leaving it out. There are other situations where it may be necessary to explain the intension of a class. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There are many different ways of writing comments and people do not necessarily agree about how to do this. We gradually introduce the style of comments that we recommend during the subsequent chapters of this book.<\/p>\n<div style=\"display:flex; gap:10px;justify-content:center\" class=\"wps-pgfw-pdf-generate-icon__wrapper-frontend\">\n\t\t<a  href=\"https:\/\/oopm.org?action=genpdf&amp;id=896\" class=\"pgfw-single-pdf-download-button\" ><img src=\"https:\/\/oopm.org\/wp-content\/plugins\/pdf-generator-for-wp\/admin\/src\/images\/PDF_Tray.svg\" title=\"Generate PDF\" style=\"width:auto; height:45px;\"><\/a>\n\t\t<\/div>","protected":false},"excerpt":{"rendered":"<p>In this section, we describe a clerk that perform activities that involve all three account objects. As with the clerk in section , this clerk invokes methods in the three Account objects. We may assemble the clerk, class Account and the declarations of the three Account objects in a microBank object: The microBank description is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":231,"menu_order":2,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-896","page","type-page","status-publish","hentry"],"mb":[],"mfb_rest_fields":["title","gutenberg_elementor_mode"],"_links":{"self":[{"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/896","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=896"}],"version-history":[{"count":27,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/896\/revisions"}],"predecessor-version":[{"id":8887,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/896\/revisions\/8887"}],"up":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/231"}],"wp:attachment":[{"href":"https:\/\/oopm.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=896"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}