Chapter 2 of the BlueJ book. Walk through many of the chapters exercises.

TicketMachine.html 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <!-- NewPage -->
  3. <html lang="en">
  4. <head>
  5. <!-- Generated by javadoc (1.8.0_181) on Tue Oct 16 17:24:50 EDT 2018 -->
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7. <title>TicketMachine</title>
  8. <meta name="date" content="2018-10-16">
  9. <link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
  10. <script type="text/javascript" src="script.js"></script>
  11. </head>
  12. <body>
  13. <script type="text/javascript"><!--
  14. try {
  15. if (location.href.indexOf('is-external=true') == -1) {
  16. parent.document.title="TicketMachine";
  17. }
  18. }
  19. catch(err) {
  20. }
  21. //-->
  22. var methods = {"i0":10,"i1":10,"i2":10,"i3":10};
  23. var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]};
  24. var altColor = "altColor";
  25. var rowColor = "rowColor";
  26. var tableTab = "tableTab";
  27. var activeTableTab = "activeTableTab";
  28. </script>
  29. <noscript>
  30. <div>JavaScript is disabled on your browser.</div>
  31. </noscript>
  32. <!-- ======== START OF CLASS DATA ======== -->
  33. <div class="header">
  34. <h2 title="Class TicketMachine" class="title">Class TicketMachine</h2>
  35. </div>
  36. <div class="contentContainer">
  37. <ul class="inheritance">
  38. <li>java.lang.Object</li>
  39. <li>
  40. <ul class="inheritance">
  41. <li>TicketMachine</li>
  42. </ul>
  43. </li>
  44. </ul>
  45. <div class="description">
  46. <ul class="blockList">
  47. <li class="blockList">
  48. <hr>
  49. <br>
  50. <pre>public class <span class="typeNameLabel">TicketMachine</span>
  51. extends java.lang.Object</pre>
  52. <div class="block">TicketMachine models a naive ticket machine that issues
  53. flat-fare tickets.
  54. The price of a ticket is specified via the constructor.
  55. It is a naive machine in the sense that it trusts its users
  56. to insert enough money before trying to print a ticket.
  57. It also assumes that users enter sensible amounts.</div>
  58. <dl>
  59. <dt><span class="simpleTagLabel">Version:</span></dt>
  60. <dd>2008.03.30</dd>
  61. <dt><span class="simpleTagLabel">Author:</span></dt>
  62. <dd>David J. Barnes and Michael Kolling</dd>
  63. </dl>
  64. </li>
  65. </ul>
  66. </div>
  67. <div class="summary">
  68. <ul class="blockList">
  69. <li class="blockList">
  70. <!-- ======== CONSTRUCTOR SUMMARY ======== -->
  71. <ul class="blockList">
  72. <li class="blockList"><a name="constructor.summary">
  73. <!-- -->
  74. </a>
  75. <h3>Constructor Summary</h3>
  76. <table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Constructor Summary table, listing constructors, and an explanation">
  77. <caption><span>Constructors</span><span class="tabEnd">&nbsp;</span></caption>
  78. <tr>
  79. <th class="colOne" scope="col">Constructor and Description</th>
  80. </tr>
  81. <tr class="altColor">
  82. <td class="colOne"><code><span class="memberNameLink"><a href="TicketMachine.html#TicketMachine-int-">TicketMachine</a></span>(int&nbsp;ticketCost)</code>
  83. <div class="block">Create a machine that issues tickets of the given price.</div>
  84. </td>
  85. </tr>
  86. </table>
  87. </li>
  88. </ul>
  89. <!-- ========== METHOD SUMMARY =========== -->
  90. <ul class="blockList">
  91. <li class="blockList"><a name="method.summary">
  92. <!-- -->
  93. </a>
  94. <h3>Method Summary</h3>
  95. <table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation">
  96. <caption><span id="t0" class="activeTableTab"><span>All Methods</span><span class="tabEnd">&nbsp;</span></span><span id="t2" class="tableTab"><span><a href="javascript:show(2);">Instance Methods</a></span><span class="tabEnd">&nbsp;</span></span><span id="t4" class="tableTab"><span><a href="javascript:show(8);">Concrete Methods</a></span><span class="tabEnd">&nbsp;</span></span></caption>
  97. <tr>
  98. <th class="colFirst" scope="col">Modifier and Type</th>
  99. <th class="colLast" scope="col">Method and Description</th>
  100. </tr>
  101. <tr id="i0" class="altColor">
  102. <td class="colFirst"><code>int</code></td>
  103. <td class="colLast"><code><span class="memberNameLink"><a href="TicketMachine.html#getBalance--">getBalance</a></span>()</code>
  104. <div class="block">Return the amount of money already inserted for the
  105. next ticket.</div>
  106. </td>
  107. </tr>
  108. <tr id="i1" class="rowColor">
  109. <td class="colFirst"><code>int</code></td>
  110. <td class="colLast"><code><span class="memberNameLink"><a href="TicketMachine.html#getPrice--">getPrice</a></span>()</code>
  111. <div class="block">Return the price of a ticket.</div>
  112. </td>
  113. </tr>
  114. <tr id="i2" class="altColor">
  115. <td class="colFirst"><code>void</code></td>
  116. <td class="colLast"><code><span class="memberNameLink"><a href="TicketMachine.html#insertMoney-int-">insertMoney</a></span>(int&nbsp;amount)</code>
  117. <div class="block">Receive an amount of money in cents from a customer.</div>
  118. </td>
  119. </tr>
  120. <tr id="i3" class="rowColor">
  121. <td class="colFirst"><code>void</code></td>
  122. <td class="colLast"><code><span class="memberNameLink"><a href="TicketMachine.html#printTicket--">printTicket</a></span>()</code>
  123. <div class="block">Print a ticket.</div>
  124. </td>
  125. </tr>
  126. </table>
  127. <ul class="blockList">
  128. <li class="blockList"><a name="methods.inherited.from.class.java.lang.Object">
  129. <!-- -->
  130. </a>
  131. <h3>Methods inherited from class&nbsp;java.lang.Object</h3>
  132. <code>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</code></li>
  133. </ul>
  134. </li>
  135. </ul>
  136. </li>
  137. </ul>
  138. </div>
  139. <div class="details">
  140. <ul class="blockList">
  141. <li class="blockList">
  142. <!-- ========= CONSTRUCTOR DETAIL ======== -->
  143. <ul class="blockList">
  144. <li class="blockList"><a name="constructor.detail">
  145. <!-- -->
  146. </a>
  147. <h3>Constructor Detail</h3>
  148. <a name="TicketMachine-int-">
  149. <!-- -->
  150. </a>
  151. <ul class="blockListLast">
  152. <li class="blockList">
  153. <h4>TicketMachine</h4>
  154. <pre>public&nbsp;TicketMachine(int&nbsp;ticketCost)</pre>
  155. <div class="block">Create a machine that issues tickets of the given price.
  156. Note that the price must be greater than zero, and there
  157. are no checks to ensure this.</div>
  158. </li>
  159. </ul>
  160. </li>
  161. </ul>
  162. <!-- ============ METHOD DETAIL ========== -->
  163. <ul class="blockList">
  164. <li class="blockList"><a name="method.detail">
  165. <!-- -->
  166. </a>
  167. <h3>Method Detail</h3>
  168. <a name="getBalance--">
  169. <!-- -->
  170. </a>
  171. <ul class="blockList">
  172. <li class="blockList">
  173. <h4>getBalance</h4>
  174. <pre>public&nbsp;int&nbsp;getBalance()</pre>
  175. <div class="block">Return the amount of money already inserted for the
  176. next ticket.</div>
  177. </li>
  178. </ul>
  179. <a name="getPrice--">
  180. <!-- -->
  181. </a>
  182. <ul class="blockList">
  183. <li class="blockList">
  184. <h4>getPrice</h4>
  185. <pre>public&nbsp;int&nbsp;getPrice()</pre>
  186. <div class="block">Return the price of a ticket.</div>
  187. </li>
  188. </ul>
  189. <a name="insertMoney-int-">
  190. <!-- -->
  191. </a>
  192. <ul class="blockList">
  193. <li class="blockList">
  194. <h4>insertMoney</h4>
  195. <pre>public&nbsp;void&nbsp;insertMoney(int&nbsp;amount)</pre>
  196. <div class="block">Receive an amount of money in cents from a customer.</div>
  197. </li>
  198. </ul>
  199. <a name="printTicket--">
  200. <!-- -->
  201. </a>
  202. <ul class="blockListLast">
  203. <li class="blockList">
  204. <h4>printTicket</h4>
  205. <pre>public&nbsp;void&nbsp;printTicket()</pre>
  206. <div class="block">Print a ticket.
  207. Update the total collected and
  208. reduce the balance to zero.</div>
  209. </li>
  210. </ul>
  211. </li>
  212. </ul>
  213. </li>
  214. </ul>
  215. </div>
  216. </div>
  217. <!-- ========= END OF CLASS DATA ========= -->
  218. </body>
  219. </html>