matchbox.xhtml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!--
  3. h t t :: / / t /
  4. h t t :: // // t //
  5. h ttttt ttttt ppppp sssss // // y y sssss ttttt //
  6. hhhh t t p p s // // y y s t //
  7. h hh t t ppppp sssss // // yyyyy sssss t //
  8. h h t t p s :: / / y .. s t .. /
  9. h h t t p sssss :: / / yyyyy .. sssss t .. /
  10. <https://y.st./>
  11. Copyright © 2017 Alex Yst <mailto:copyright@y.st>
  12. This program is free software: you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation, either version 3 of the License, or
  15. (at your option) any later version.
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. GNU General Public License for more details.
  20. You should have received a copy of the GNU General Public License
  21. along with this program. If not, see <https://www.gnu.org./licenses/>.
  22. -->
  23. <!DOCTYPE html>
  24. <html xmlns="http://www.w3.org/1999/xhtml">
  25. <head>
  26. <base href="https://y.st./en/coursework/CS1102/matchbox.xhtml" />
  27. <title>package matchbox; &lt;https://y.st./en/coursework/CS1102/matchbox.xhtml&gt;</title>
  28. <link rel="icon" type="image/png" href="/link/CC_BY-SA_4.0/y.st./icon.png" />
  29. <link rel="stylesheet" type="text/css" href="/link/basic.css" />
  30. <link rel="stylesheet" type="text/css" href="/link/site-specific.css" />
  31. <script type="text/javascript" src="/script/javascript.js" />
  32. <meta name="viewport" content="width=device-width" />
  33. </head>
  34. <body>
  35. <nav>
  36. <p>
  37. <a href="/en/">Home</a> |
  38. <a href="/en/a/about.xhtml">About</a> |
  39. <a href="/en/a/contact.xhtml">Contact</a> |
  40. <a href="/a/canary.txt">Canary</a> |
  41. <a href="/en/URI_research/"><abbr title="Uniform Resource Identifier">URI</abbr> research</a> |
  42. <a href="/en/opinion/">Opinions</a> |
  43. <a href="/en/coursework/">Coursework</a> |
  44. <a href="/en/law/">Law</a> |
  45. <a href="/en/a/links.xhtml">Links</a> |
  46. <a href="/en/coursework/CS1102/matchbox.xhtml.asc">{this page}.asc</a>
  47. </p>
  48. <hr/>
  49. <p>
  50. <a href="/en/coursework/BUS1101/" title="Principles of Business Management">BUS 1101</a> |
  51. <span class="hyperlink_unavailable" title="Basic Accounting">BUS 1102</span> |
  52. <span class="hyperlink_unavailable" title="Principles of Marketing">BUS 2201</span> |
  53. <span class="hyperlink_unavailable" title="Multinational Management">BUS 2207</span> |
  54. <span class="hyperlink_unavailable" title="Business and Society">BUS 3306</span> |
  55. <a href="/en/coursework/CS1101/" title="Programming Fundamentals">CS 1101</a> |
  56. <a href="/en/coursework/CS1102/" title="Programming 1">CS 1102</a> |
  57. <a href="/en/coursework/CS1103/" title="Programming 2">CS 1103</a> |
  58. <span class="hyperlink_unavailable" title="Computer Systems">CS 1104</span> |
  59. <a href="/en/coursework/CS2203/" title="Databases 1">CS 2203</a> |
  60. <span class="hyperlink_unavailable" title="Communications and Networking">CS 2204</span> |
  61. <a href="/en/coursework/CS2205/" title="Web Programming 1">CS 2205</a> |
  62. <a href="/en/coursework/CS2301/" title="Operating Systems 1">CS 2301</a> |
  63. <span class="hyperlink_unavailable" title="Software Engineering 1">CS 2401</span> |
  64. <span class="hyperlink_unavailable" title="Data Structures">CS 3303</span> |
  65. <span class="hyperlink_unavailable" title="Analysis of Algorithms">CS 3304</span> |
  66. <span class="hyperlink_unavailable" title="Web Programming 2">CS 3305</span> |
  67. <span class="hyperlink_unavailable" title="Databases 2">CS 3306</span> |
  68. <span class="hyperlink_unavailable" title="Operating Systems 2">CS 3307</span> |
  69. <span class="hyperlink_unavailable" title="Information Retrieval">CS 3308</span> |
  70. <span class="hyperlink_unavailable" title="Comparative Programming Languages">CS 4402</span> |
  71. <span class="hyperlink_unavailable" title="Software Engineering 2">CS 4403</span> |
  72. <span class="hyperlink_unavailable" title="Advanced Networking and Data Security">CS 4404</span> |
  73. <span class="hyperlink_unavailable" title="Mobile Applications">CS 4405</span> |
  74. <span class="hyperlink_unavailable" title="Computer Graphics">CS 4406</span> |
  75. <span class="hyperlink_unavailable" title="Data Mining and Machine Learning">CS 4407</span> |
  76. <span class="hyperlink_unavailable" title="Artificial Intelligence">CS 4408</span> |
  77. <span class="hyperlink_unavailable" title="English Composition 2">ENGL 1102</span> |
  78. <span class="hyperlink_unavailable" title="World Literature">ENGL 1405</span> |
  79. <span class="hyperlink_unavailable" title="Introduction to Environmental Science">ENVS 1301</span> |
  80. <a href="/en/coursework/HIST1421/" title="Greek and Roman Civilization">HIST 1421</a> |
  81. <span class="hyperlink_unavailable" title="College Algebra">MATH 1201</span> |
  82. <span class="hyperlink_unavailable" title="Calculus">MATH 1211</span> |
  83. <span class="hyperlink_unavailable" title="Introduction to Statistics">MATH 1280</span> |
  84. <span class="hyperlink_unavailable" title="Discrete Mathematics">MATH 1302</span> |
  85. <span class="hyperlink_unavailable" title="Introduction to Philosophy">PHIL 1402</span> |
  86. <a href="/en/coursework/PHIL1404/" title="Ethics and Social Responsibility">PHIL 1404</a> |
  87. <a href="/en/coursework/POLS1503/" title="Globalization">POLS 1503</a> |
  88. <span class="hyperlink_unavailable" title="Introduction to Psychology">PSYC 1504</span> |
  89. <a href="/en/coursework/UNIV1001/" title="Online Education Strategies">UNIV 1001</a>
  90. </p>
  91. <hr/>
  92. <p>
  93. <a href="/en/coursework/CS1102/GravityCalculator.java.xhtml" title="GravityCalculator.java">Unit 1</a> |
  94. <a href="/en/coursework/CS1102/SnakeEyesCount.java.xhtml" title="SnakeEyesCount.java">Unit 2</a> |
  95. <a href="/en/coursework/CS1102/Unit3.java.xhtml" title="Unit3.java">Unit 3</a> |
  96. <a href="/en/coursework/CS1102/firstsubroutines.java.xhtml" title="firstsubroutines.java">Unit 4</a> |
  97. <a href="/en/coursework/CS1102/Unit5.java.xhtml" title="Unit5.java">Unit 5</a> |
  98. <a href="/en/coursework/CS1102/payrollsystem.xhtml" title="package payrollsystem;">Unit 7</a> |
  99. <a href="/en/coursework/CS1102/matchbox.xhtml" title="package matchbox;">Unit 6</a> |
  100. <a href="/en/coursework/CS1102/Unit7.java.xhtml" title="Unit7.java">Unit 7</a>
  101. </p>
  102. <hr/>
  103. </nav>
  104. <header>
  105. <h1><code>package matchbox;</code></h1>
  106. <p>Written in <span title="Programming 1">CS 1102</span> of <a href="http://www.uopeople.edu/">University of the People</a>, finalised on 2017-05-17</p>
  107. </header>
  108. <h2>Source code:</h2>
  109. <h3>Box.java</h3>
  110. <p>
  111. (provided by assignment directions)
  112. </p>
  113. <h3>MatchBox.java</h3>
  114. <blockquote>
  115. <pre><code>/*
  116. * Copyright (C) 2017 Alex Yst
  117. *
  118. * This program is free software: you can redistribute it and/or modify
  119. * it under the terms of the GNU General Public License as published by
  120. * the Free Software Foundation, either version 3 of the License, or
  121. * (at your option) any later version.
  122. *
  123. * This program is distributed in the hope that it will be useful,
  124. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  125. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  126. * GNU General Public License for more details.
  127. *
  128. * You should have received a copy of the GNU General Public License
  129. * along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.
  130. */
  131. package matchbox;
  132. /**
  133. * A simple volume-/weight-calculation class
  134. *
  135. * @author Alex Yst
  136. */
  137. public class MatchBox extends Box {
  138. public double weight;
  139. /**
  140. * Outputs the dimentions, weight, and volume of the box
  141. *
  142. * The assignment required that calculateWeight() output the calculated weight
  143. * and the parent&apos;s getVolume() method already outputs the volume. We might as
  144. * well just delegate to those methods to output their respective parts of our
  145. * information.
  146. */
  147. @Override
  148. public void getVolume() {
  149. System.out.println(&quot;width of MatchBox is &quot; + this.width);
  150. System.out.println(&quot;height of MatchBox is &quot; + this.height);
  151. System.out.println(&quot;depth of MatchBox is &quot; + this.depth);
  152. this.calculateWeight();
  153. super.getVolume();
  154. }
  155. /**
  156. * calculateWeight()
  157. *
  158. * This method outputs the weight and sets the weight property to match. It
  159. * assumes a density of 0.03611.
  160. */
  161. public void calculateWeight() {
  162. this.weight = this.depth * this.height * this.width * 0.03611;
  163. System.out.println(&quot;weight of MatchBox is &quot; + this.weight);
  164. }
  165. /**
  166. * Constructor
  167. *
  168. * I thought I read that in Java, if no constructor was provided, the parent&apos;s
  169. * constructor would be called. However, NetBeans doesn&apos;t seem to allow that.
  170. * Either I misread or a constructor must be manually defined in the child
  171. * class. This constructor simply calls the parent&apos;s constructor, because that
  172. * constructor does everything we need it to.
  173. *
  174. * @param width The box width
  175. * @param height The box height
  176. * @param depth The box depth
  177. */
  178. public MatchBox(double width, double height, double depth) {
  179. super(width, height, depth);
  180. }
  181. }</code></pre>
  182. </blockquote>
  183. <h3>main.java</h3>
  184. <blockquote>
  185. <pre><code>/*
  186. * Copyright (C) 2017 Alex Yst
  187. *
  188. * This program is free software: you can redistribute it and/or modify
  189. * it under the terms of the GNU General Public License as published by
  190. * the Free Software Foundation, either version 3 of the License, or
  191. * (at your option) any later version.
  192. *
  193. * This program is distributed in the hope that it will be useful,
  194. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  195. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  196. * GNU General Public License for more details.
  197. *
  198. * You should have received a copy of the GNU General Public License
  199. * along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.
  200. */
  201. package matchbox;
  202. /**
  203. * Alex Yst&apos;s CS 1102 (Programming 1) Unit 6 submission
  204. *
  205. * For this assignment, we were required to define MatchBox.getVolume() to
  206. * output all the statistics. What this means is that for the main() method of
  207. * this class to output all the statistics, all we have to do is have it call
  208. * the other class&apos; getVolume() method. We have to create a new instance of the
  209. * MatchBox class for this, but we don&apos;t even have to store it in a variable.
  210. * All we have to do is call the getVolume() method of our new object and we&apos;re
  211. * done. A simple one-liner will sufice.
  212. *
  213. * @author Alex Yst
  214. */
  215. public class main {
  216. public static void main(String[] arguments) {
  217. new MatchBox(5, 10, 3).getVolume();
  218. }
  219. }</code></pre>
  220. </blockquote>
  221. <h2>Output:</h2>
  222. <blockquote>
  223. <pre>run:
  224. width of MatchBox is 5.0
  225. height of MatchBox is 10.0
  226. depth of MatchBox is 3.0
  227. weight of MatchBox is 5.4165
  228. Volume is : 150.0
  229. BUILD SUCCESSFUL (total time: 0 seconds)</pre>
  230. </blockquote>
  231. <hr/>
  232. <p>
  233. Copyright © 2017 Alex Yst;
  234. You may modify and/or redistribute this document under the terms of the <a rel="license" href="/license/gpl-3.0-standalone.xhtml"><abbr title="GNU&apos;s Not Unix">GNU</abbr> <abbr title="General Public License version Three or later">GPLv3+</abbr></a>.
  235. If for some reason you would prefer to modify and/or distribute this document under other free copyleft terms, please ask me via email.
  236. My address is in the source comments near the top of this document.
  237. This license also applies to embedded content such as images.
  238. For more information on that, see <a href="/en/a/licensing.xhtml">licensing</a>.
  239. </p>
  240. <p>
  241. <abbr title="World Wide Web Consortium">W3C</abbr> standards are important.
  242. This document conforms to the <a href="https://validator.w3.org./nu/?doc=https%3A%2F%2Fy.st.%2Fen%2Fcoursework%2FCS1102%2Fmatchbox.xhtml"><abbr title="Extensible Hypertext Markup Language">XHTML</abbr> 5.1</a> specification and uses style sheets that conform to the <a href="http://jigsaw.w3.org./css-validator/validator?uri=https%3A%2F%2Fy.st.%2Fen%2Fcoursework%2FCS1102%2Fmatchbox.xhtml"><abbr title="Cascading Style Sheets">CSS</abbr>3</a> specification.
  243. </p>
  244. </body>
  245. </html>