├── .gitignore
├── LICENSE
├── README.md
├── UML_Distilled_ A Brief Guide to the Standard Object Modeling Language-Addison-Wesley Professional.pdf
├── assignments
├── Assignment 1.pdf
├── Assignment 2.pdf
└── Assignment 3.pdf
├── lecture_slides
├── VideoStoreExampleCode
│ ├── VideoStore1-Start
│ │ └── src
│ │ │ ├── Customer.java
│ │ │ ├── Movie.java
│ │ │ ├── Rental.java
│ │ │ └── TestVideoStore.java
│ ├── VideoStore2-AmountFor
│ │ └── src
│ │ │ ├── Customer.java
│ │ │ ├── Movie.java
│ │ │ ├── Rental.java
│ │ │ └── TestVideoStore.java
│ ├── VideoStore3-GetCharge
│ │ └── src
│ │ │ ├── Customer.java
│ │ │ ├── Movie.java
│ │ │ ├── Rental.java
│ │ │ └── TestVideoStore.java
│ ├── VideoStore4-getTotals
│ │ └── src
│ │ │ ├── Customer.java
│ │ │ ├── Movie.java
│ │ │ ├── Rental.java
│ │ │ └── TestVideoStore.java
│ ├── VideoStore5-HTMLStatement
│ │ └── src
│ │ │ ├── Customer.java
│ │ │ ├── Movie.java
│ │ │ ├── Rental.java
│ │ │ └── TestVideoStore.java
│ ├── VideoStore6-ChargeInMovie
│ │ └── src
│ │ │ ├── Customer.java
│ │ │ ├── Movie.java
│ │ │ ├── Rental.java
│ │ │ └── TestVideoStore.java
│ ├── VideoStore7-PriceClass
│ │ └── src
│ │ │ ├── ChildrensPrice.java
│ │ │ ├── Customer.java
│ │ │ ├── Movie.java
│ │ │ ├── NewReleasePrice.java
│ │ │ ├── Price.java
│ │ │ ├── RegularPrice.java
│ │ │ ├── Rental.java
│ │ │ └── TestVideoStore.java
│ └── VideoStore8-ReplaceSwitchWithPolymorphism
│ │ └── src
│ │ ├── ChildrensPrice.java
│ │ ├── Customer.java
│ │ ├── Movie.java
│ │ ├── NewReleasePrice.java
│ │ ├── Price.java
│ │ ├── RegularPrice.java
│ │ ├── Rental.java
│ │ └── TestVideoStore.java
├── W10_FIT2099 Abstraction.pdf
├── W10_FIT2099 Using Abstraction in Java.pdf
├── W11_FIT2099 Code Smells.pdf
├── W11_FIT2099 Refactoring.pdf
├── W12_FIT2099 Review.pdf
├── W1_Introduction to Object-Orientation.pdf
├── W1_Introduction to Unit 2019 S1.pdf
├── W2_Java Fundamentals.pdf
├── W3_UML Diagrams.pdf
├── W4_Excerpt_from_Absolute_Java.pdf
├── W4_Privacy Leaks.pdf
├── W5_Commenting_how and why.pdf
├── W5_Intro to JavaDoc.pdf
├── W6_CofojaDemo
│ ├── .classpath
│ ├── .factorypath
│ ├── .project
│ ├── .settings
│ │ ├── org.eclipse.jdt.apt.core.prefs
│ │ └── org.eclipse.jdt.core.prefs
│ ├── bin
│ │ ├── BankAccount.class
│ │ ├── ContractsDemo.class
│ │ ├── MeansCofoja.class
│ │ ├── MeansExceptionAssertion.class
│ │ └── OverdraftAccount.class
│ ├── lib
│ │ └── cofoja.asm-1.3-20160207.jar
│ └── src
│ │ ├── BankAccount.java
│ │ ├── ContractsDemo.java
│ │ ├── MeansCofoja.java
│ │ ├── MeansExceptionAssertion.java
│ │ └── OverdraftAccount.java
├── W6_FIT2099_DesignByContract 1.pdf
├── W6_FIT2099_DesignByContract 2.pdf
├── W6_SetDemo
│ └── src
│ │ ├── ArraySet.java
│ │ ├── Driver.java
│ │ ├── HashSet.java
│ │ └── Set.java
├── W7_Class and Sequence Diagrams for MADAM Clippings
│ ├── MADAM clippings class diagram version 1.pdf
│ ├── MADAM clippings class diagram version 2.pdf
│ ├── MADAM clippings sequence diagram version 1.pdf
│ └── MADAM clippings sequence diagram version 2.pdf
├── W7_FIT2099_WhatDoesADesignLookLike.pdf
├── W7_FIT2099_WhenDoWeDesignAndWhatDoWeMake.pdf
├── W7_sequence diagrams - UML distilled.pdf
├── W8_FIT2099_Encapsulation.pdf
├── W8_FIT2099_Good_Design.pdf
├── W9_FIT2099 How to Design - CRC Cards Demo.pdf
├── W9_FIT2099 How to Design.pdf
└── W9_How Java Objects Work.pdf
├── notes
├── code_smells.pdf
├── complete_ood_notes.pdf
├── fit2099_notes.pdf
├── uml.pdf
├── uml_cheatsheet.pdf
├── uml_class_diagrams_new.pdf
├── uml_sequence_diagrams.pdf
└── uml_syntax.pdf
├── object_oriented_fundamentals
├── Object Orientation Fundamentals in Java - Part 1.pdf
├── Object Orientation Fundamentals in Java - Part 2.pdf
├── Object Orientation Fundamentals in Java - Part 3.pdf
└── Object Orientation Fundamentals in Java - Part 4.pdf
├── pass_exercises
├── Week 10 PASS - S1 2019 (Solution) - Google Docs.pdf
├── Week 11 PASS - S1 2019 (Solution) - Google Docs.pdf
├── Week 12 PASS - S1 2019 (Solution) - Google Docs.pdf
├── Week 3 PASS - S1 2019 (Solution) - Google Docs.pdf
├── Week 4 PASS - S1 2019 (Solution) - Google Docs.pdf
├── Week 5 PASS - S1 2019 (Solution) - Google Docs.pdf
├── Week 6 PASS - S1 2019 (Solution) - Google Docs.pdf
├── Week 7 PASS - S1 2019 (Solution) - Google Docs.pdf
├── Week 8 PASS - S1 2019 (Solution) - Google Docs.pdf
└── Week 9 PASS - S1 2019 (Solution) - Google Docs.pdf
└── past_exam
├── further_sample_questions.pdf
├── s2-2018_solutions.pdf
├── sample_exam.pdf
└── sample_exam_solutions.pdf
/.gitignore:
--------------------------------------------------------------------------------
1 | # Mac file
2 | .DS_Store
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Attribution 4.0 International
2 |
3 | =======================================================================
4 |
5 | Creative Commons Corporation ("Creative Commons") is not a law firm and
6 | does not provide legal services or legal advice. Distribution of
7 | Creative Commons public licenses does not create a lawyer-client or
8 | other relationship. Creative Commons makes its licenses and related
9 | information available on an "as-is" basis. Creative Commons gives no
10 | warranties regarding its licenses, any material licensed under their
11 | terms and conditions, or any related information. Creative Commons
12 | disclaims all liability for damages resulting from their use to the
13 | fullest extent possible.
14 |
15 | Using Creative Commons Public Licenses
16 |
17 | Creative Commons public licenses provide a standard set of terms and
18 | conditions that creators and other rights holders may use to share
19 | original works of authorship and other material subject to copyright
20 | and certain other rights specified in the public license below. The
21 | following considerations are for informational purposes only, are not
22 | exhaustive, and do not form part of our licenses.
23 |
24 | Considerations for licensors: Our public licenses are
25 | intended for use by those authorized to give the public
26 | permission to use material in ways otherwise restricted by
27 | copyright and certain other rights. Our licenses are
28 | irrevocable. Licensors should read and understand the terms
29 | and conditions of the license they choose before applying it.
30 | Licensors should also secure all rights necessary before
31 | applying our licenses so that the public can reuse the
32 | material as expected. Licensors should clearly mark any
33 | material not subject to the license. This includes other CC-
34 | licensed material, or material used under an exception or
35 | limitation to copyright. More considerations for licensors:
36 | wiki.creativecommons.org/Considerations_for_licensors
37 |
38 | Considerations for the public: By using one of our public
39 | licenses, a licensor grants the public permission to use the
40 | licensed material under specified terms and conditions. If
41 | the licensor's permission is not necessary for any reason--for
42 | example, because of any applicable exception or limitation to
43 | copyright--then that use is not regulated by the license. Our
44 | licenses grant only permissions under copyright and certain
45 | other rights that a licensor has authority to grant. Use of
46 | the licensed material may still be restricted for other
47 | reasons, including because others have copyright or other
48 | rights in the material. A licensor may make special requests,
49 | such as asking that all changes be marked or described.
50 | Although not required by our licenses, you are encouraged to
51 | respect those requests where reasonable. More_considerations
52 | for the public:
53 | wiki.creativecommons.org/Considerations_for_licensees
54 |
55 | =======================================================================
56 |
57 | Creative Commons Attribution 4.0 International Public License
58 |
59 | By exercising the Licensed Rights (defined below), You accept and agree
60 | to be bound by the terms and conditions of this Creative Commons
61 | Attribution 4.0 International Public License ("Public License"). To the
62 | extent this Public License may be interpreted as a contract, You are
63 | granted the Licensed Rights in consideration of Your acceptance of
64 | these terms and conditions, and the Licensor grants You such rights in
65 | consideration of benefits the Licensor receives from making the
66 | Licensed Material available under these terms and conditions.
67 |
68 |
69 | Section 1 -- Definitions.
70 |
71 | a. Adapted Material means material subject to Copyright and Similar
72 | Rights that is derived from or based upon the Licensed Material
73 | and in which the Licensed Material is translated, altered,
74 | arranged, transformed, or otherwise modified in a manner requiring
75 | permission under the Copyright and Similar Rights held by the
76 | Licensor. For purposes of this Public License, where the Licensed
77 | Material is a musical work, performance, or sound recording,
78 | Adapted Material is always produced where the Licensed Material is
79 | synched in timed relation with a moving image.
80 |
81 | b. Adapter's License means the license You apply to Your Copyright
82 | and Similar Rights in Your contributions to Adapted Material in
83 | accordance with the terms and conditions of this Public License.
84 |
85 | c. Copyright and Similar Rights means copyright and/or similar rights
86 | closely related to copyright including, without limitation,
87 | performance, broadcast, sound recording, and Sui Generis Database
88 | Rights, without regard to how the rights are labeled or
89 | categorized. For purposes of this Public License, the rights
90 | specified in Section 2(b)(1)-(2) are not Copyright and Similar
91 | Rights.
92 |
93 | d. Effective Technological Measures means those measures that, in the
94 | absence of proper authority, may not be circumvented under laws
95 | fulfilling obligations under Article 11 of the WIPO Copyright
96 | Treaty adopted on December 20, 1996, and/or similar international
97 | agreements.
98 |
99 | e. Exceptions and Limitations means fair use, fair dealing, and/or
100 | any other exception or limitation to Copyright and Similar Rights
101 | that applies to Your use of the Licensed Material.
102 |
103 | f. Licensed Material means the artistic or literary work, database,
104 | or other material to which the Licensor applied this Public
105 | License.
106 |
107 | g. Licensed Rights means the rights granted to You subject to the
108 | terms and conditions of this Public License, which are limited to
109 | all Copyright and Similar Rights that apply to Your use of the
110 | Licensed Material and that the Licensor has authority to license.
111 |
112 | h. Licensor means the individual(s) or entity(ies) granting rights
113 | under this Public License.
114 |
115 | i. Share means to provide material to the public by any means or
116 | process that requires permission under the Licensed Rights, such
117 | as reproduction, public display, public performance, distribution,
118 | dissemination, communication, or importation, and to make material
119 | available to the public including in ways that members of the
120 | public may access the material from a place and at a time
121 | individually chosen by them.
122 |
123 | j. Sui Generis Database Rights means rights other than copyright
124 | resulting from Directive 96/9/EC of the European Parliament and of
125 | the Council of 11 March 1996 on the legal protection of databases,
126 | as amended and/or succeeded, as well as other essentially
127 | equivalent rights anywhere in the world.
128 |
129 | k. You means the individual or entity exercising the Licensed Rights
130 | under this Public License. Your has a corresponding meaning.
131 |
132 |
133 | Section 2 -- Scope.
134 |
135 | a. License grant.
136 |
137 | 1. Subject to the terms and conditions of this Public License,
138 | the Licensor hereby grants You a worldwide, royalty-free,
139 | non-sublicensable, non-exclusive, irrevocable license to
140 | exercise the Licensed Rights in the Licensed Material to:
141 |
142 | a. reproduce and Share the Licensed Material, in whole or
143 | in part; and
144 |
145 | b. produce, reproduce, and Share Adapted Material.
146 |
147 | 2. Exceptions and Limitations. For the avoidance of doubt, where
148 | Exceptions and Limitations apply to Your use, this Public
149 | License does not apply, and You do not need to comply with
150 | its terms and conditions.
151 |
152 | 3. Term. The term of this Public License is specified in Section
153 | 6(a).
154 |
155 | 4. Media and formats; technical modifications allowed. The
156 | Licensor authorizes You to exercise the Licensed Rights in
157 | all media and formats whether now known or hereafter created,
158 | and to make technical modifications necessary to do so. The
159 | Licensor waives and/or agrees not to assert any right or
160 | authority to forbid You from making technical modifications
161 | necessary to exercise the Licensed Rights, including
162 | technical modifications necessary to circumvent Effective
163 | Technological Measures. For purposes of this Public License,
164 | simply making modifications authorized by this Section 2(a)
165 | (4) never produces Adapted Material.
166 |
167 | 5. Downstream recipients.
168 |
169 | a. Offer from the Licensor -- Licensed Material. Every
170 | recipient of the Licensed Material automatically
171 | receives an offer from the Licensor to exercise the
172 | Licensed Rights under the terms and conditions of this
173 | Public License.
174 |
175 | b. No downstream restrictions. You may not offer or impose
176 | any additional or different terms or conditions on, or
177 | apply any Effective Technological Measures to, the
178 | Licensed Material if doing so restricts exercise of the
179 | Licensed Rights by any recipient of the Licensed
180 | Material.
181 |
182 | 6. No endorsement. Nothing in this Public License constitutes or
183 | may be construed as permission to assert or imply that You
184 | are, or that Your use of the Licensed Material is, connected
185 | with, or sponsored, endorsed, or granted official status by,
186 | the Licensor or others designated to receive attribution as
187 | provided in Section 3(a)(1)(A)(i).
188 |
189 | b. Other rights.
190 |
191 | 1. Moral rights, such as the right of integrity, are not
192 | licensed under this Public License, nor are publicity,
193 | privacy, and/or other similar personality rights; however, to
194 | the extent possible, the Licensor waives and/or agrees not to
195 | assert any such rights held by the Licensor to the limited
196 | extent necessary to allow You to exercise the Licensed
197 | Rights, but not otherwise.
198 |
199 | 2. Patent and trademark rights are not licensed under this
200 | Public License.
201 |
202 | 3. To the extent possible, the Licensor waives any right to
203 | collect royalties from You for the exercise of the Licensed
204 | Rights, whether directly or through a collecting society
205 | under any voluntary or waivable statutory or compulsory
206 | licensing scheme. In all other cases the Licensor expressly
207 | reserves any right to collect such royalties.
208 |
209 |
210 | Section 3 -- License Conditions.
211 |
212 | Your exercise of the Licensed Rights is expressly made subject to the
213 | following conditions.
214 |
215 | a. Attribution.
216 |
217 | 1. If You Share the Licensed Material (including in modified
218 | form), You must:
219 |
220 | a. retain the following if it is supplied by the Licensor
221 | with the Licensed Material:
222 |
223 | i. identification of the creator(s) of the Licensed
224 | Material and any others designated to receive
225 | attribution, in any reasonable manner requested by
226 | the Licensor (including by pseudonym if
227 | designated);
228 |
229 | ii. a copyright notice;
230 |
231 | iii. a notice that refers to this Public License;
232 |
233 | iv. a notice that refers to the disclaimer of
234 | warranties;
235 |
236 | v. a URI or hyperlink to the Licensed Material to the
237 | extent reasonably practicable;
238 |
239 | b. indicate if You modified the Licensed Material and
240 | retain an indication of any previous modifications; and
241 |
242 | c. indicate the Licensed Material is licensed under this
243 | Public License, and include the text of, or the URI or
244 | hyperlink to, this Public License.
245 |
246 | 2. You may satisfy the conditions in Section 3(a)(1) in any
247 | reasonable manner based on the medium, means, and context in
248 | which You Share the Licensed Material. For example, it may be
249 | reasonable to satisfy the conditions by providing a URI or
250 | hyperlink to a resource that includes the required
251 | information.
252 |
253 | 3. If requested by the Licensor, You must remove any of the
254 | information required by Section 3(a)(1)(A) to the extent
255 | reasonably practicable.
256 |
257 | 4. If You Share Adapted Material You produce, the Adapter's
258 | License You apply must not prevent recipients of the Adapted
259 | Material from complying with this Public License.
260 |
261 |
262 | Section 4 -- Sui Generis Database Rights.
263 |
264 | Where the Licensed Rights include Sui Generis Database Rights that
265 | apply to Your use of the Licensed Material:
266 |
267 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right
268 | to extract, reuse, reproduce, and Share all or a substantial
269 | portion of the contents of the database;
270 |
271 | b. if You include all or a substantial portion of the database
272 | contents in a database in which You have Sui Generis Database
273 | Rights, then the database in which You have Sui Generis Database
274 | Rights (but not its individual contents) is Adapted Material; and
275 |
276 | c. You must comply with the conditions in Section 3(a) if You Share
277 | all or a substantial portion of the contents of the database.
278 |
279 | For the avoidance of doubt, this Section 4 supplements and does not
280 | replace Your obligations under this Public License where the Licensed
281 | Rights include other Copyright and Similar Rights.
282 |
283 |
284 | Section 5 -- Disclaimer of Warranties and Limitation of Liability.
285 |
286 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
287 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
288 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
289 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
290 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
291 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
292 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
293 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
294 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
295 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
296 |
297 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
298 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
299 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
300 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
301 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
302 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
303 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
304 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
305 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
306 |
307 | c. The disclaimer of warranties and limitation of liability provided
308 | above shall be interpreted in a manner that, to the extent
309 | possible, most closely approximates an absolute disclaimer and
310 | waiver of all liability.
311 |
312 |
313 | Section 6 -- Term and Termination.
314 |
315 | a. This Public License applies for the term of the Copyright and
316 | Similar Rights licensed here. However, if You fail to comply with
317 | this Public License, then Your rights under this Public License
318 | terminate automatically.
319 |
320 | b. Where Your right to use the Licensed Material has terminated under
321 | Section 6(a), it reinstates:
322 |
323 | 1. automatically as of the date the violation is cured, provided
324 | it is cured within 30 days of Your discovery of the
325 | violation; or
326 |
327 | 2. upon express reinstatement by the Licensor.
328 |
329 | For the avoidance of doubt, this Section 6(b) does not affect any
330 | right the Licensor may have to seek remedies for Your violations
331 | of this Public License.
332 |
333 | c. For the avoidance of doubt, the Licensor may also offer the
334 | Licensed Material under separate terms or conditions or stop
335 | distributing the Licensed Material at any time; however, doing so
336 | will not terminate this Public License.
337 |
338 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
339 | License.
340 |
341 |
342 | Section 7 -- Other Terms and Conditions.
343 |
344 | a. The Licensor shall not be bound by any additional or different
345 | terms or conditions communicated by You unless expressly agreed.
346 |
347 | b. Any arrangements, understandings, or agreements regarding the
348 | Licensed Material not stated herein are separate from and
349 | independent of the terms and conditions of this Public License.
350 |
351 |
352 | Section 8 -- Interpretation.
353 |
354 | a. For the avoidance of doubt, this Public License does not, and
355 | shall not be interpreted to, reduce, limit, restrict, or impose
356 | conditions on any use of the Licensed Material that could lawfully
357 | be made without permission under this Public License.
358 |
359 | b. To the extent possible, if any provision of this Public License is
360 | deemed unenforceable, it shall be automatically reformed to the
361 | minimum extent necessary to make it enforceable. If the provision
362 | cannot be reformed, it shall be severed from this Public License
363 | without affecting the enforceability of the remaining terms and
364 | conditions.
365 |
366 | c. No term or condition of this Public License will be waived and no
367 | failure to comply consented to unless expressly agreed to by the
368 | Licensor.
369 |
370 | d. Nothing in this Public License constitutes or may be interpreted
371 | as a limitation upon, or waiver of, any privileges and immunities
372 | that apply to the Licensor or You, including from the legal
373 | processes of any jurisdiction or authority.
374 |
375 |
376 | =======================================================================
377 |
378 | Creative Commons is not a party to its public
379 | licenses. Notwithstanding, Creative Commons may elect to apply one of
380 | its public licenses to material it publishes and in those instances
381 | will be considered the “Licensor.” The text of the Creative Commons
382 | public licenses is dedicated to the public domain under the CC0 Public
383 | Domain Dedication. Except for the limited purpose of indicating that
384 | material is shared under a Creative Commons public license or as
385 | otherwise permitted by the Creative Commons policies published at
386 | creativecommons.org/policies, Creative Commons does not authorize the
387 | use of the trademark "Creative Commons" or any other trademark or logo
388 | of Creative Commons without its prior written consent including,
389 | without limitation, in connection with any unauthorized modifications
390 | to any of its public licenses or any other arrangements,
391 | understandings, or agreements concerning use of licensed material. For
392 | the avoidance of doubt, this paragraph does not form part of the
393 | public licenses.
394 |
395 | Creative Commons may be contacted at creativecommons.org.
396 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # fit2099-object-oriented-design-and-implementation
2 | FIT2099 Object-oriented Design and Implementation notes, batch of Semester 1, 2019.
3 |
4 | ## Notes
5 | Most notes are compiled and written by me during the entire semester. It serves the purpose of providing future students more learning materials and also reference for myself in the future. Do take note of any inaccuracies made by me.
6 |
7 | #### PASS Exercise
8 | Materials are obtained from PASS leader. It contains additional exercises outside lectures and tutorials to provide more hands-on learning on design principles.
9 |
10 | ## Review over FIT2099
11 | The unit itself requires immense reading where the amount of time used to "read code" is more than "writing code". So expect to put in lots of time to read software documentation and code, as to look for the pattern (or coding style). These coding styles are called design principles and exam expects you to have the ability to code in the style where the design principle can be easily detected. Assignments are not that heavy but it requires teamwork and close collaboration. Learned some couple of skills on using local and remote repositories. My advice is to work on the assignments as early as possible as you can have the additional time to consult tutors and improve on your existing design. Exam is open-book, but in most cases do not have time to flip or refer to notes, so expect the bring-in notes to serve as a "recall" over the knowledge learnt. Focus more on reading and understanding the design rather than just "diving" directly into coding and spend more time on your own learning, rather than going to lectures (as they are not that useful). This is the key for the unit's success.
12 |
13 | Overall Review: 8/10 Final Grade: HD
14 |
15 | ## License
16 |
17 | [](https://creativecommons.org/licenses/by/4.0/)
18 | Copyright (c) 2019 Jun Qing Lim The content of this repository is licensed under the [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/). Permits any use subject to providing credit and license notice, commonly used for media assets and educational materials. See [LICENSE](LICENSE) for more information.
19 |
--------------------------------------------------------------------------------
/UML_Distilled_ A Brief Guide to the Standard Object Modeling Language-Addison-Wesley Professional.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itsjunqing/fit2099-object-oriented-design-and-implementation/02ee39d4555eebbc1e73ff1fb0abecd8a1d53b26/UML_Distilled_ A Brief Guide to the Standard Object Modeling Language-Addison-Wesley Professional.pdf
--------------------------------------------------------------------------------
/assignments/Assignment 1.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itsjunqing/fit2099-object-oriented-design-and-implementation/02ee39d4555eebbc1e73ff1fb0abecd8a1d53b26/assignments/Assignment 1.pdf
--------------------------------------------------------------------------------
/assignments/Assignment 2.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itsjunqing/fit2099-object-oriented-design-and-implementation/02ee39d4555eebbc1e73ff1fb0abecd8a1d53b26/assignments/Assignment 2.pdf
--------------------------------------------------------------------------------
/assignments/Assignment 3.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itsjunqing/fit2099-object-oriented-design-and-implementation/02ee39d4555eebbc1e73ff1fb0abecd8a1d53b26/assignments/Assignment 3.pdf
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore1-Start/src/Customer.java:
--------------------------------------------------------------------------------
1 | import java.util.ArrayList;
2 |
3 | class Customer {
4 |
5 | private String _name;
6 | private ArrayList _rentals = new ArrayList();
7 |
8 | public Customer (String name){
9 | _name = name;
10 | };
11 |
12 | public void addRental(Rental arg) {
13 | _rentals.add(arg);
14 | }
15 |
16 | public String getName() {
17 | return _name;
18 | }
19 |
20 | public String statement() {
21 | double totalAmount = 0;
22 | int frequentRenterPoints = 0;
23 | String result = "Rental Record for " + getName() + "\n";
24 | for (Rental thisRental : _rentals) {
25 | double thisAmount = 0;
26 |
27 | //determine amounts for each line
28 | switch (thisRental.getMovie().getPriceCode()) {
29 | case Movie.REGULAR:
30 | thisAmount += 2;
31 | if (thisRental.getDaysRented() > 2)
32 | thisAmount += (thisRental.getDaysRented() - 2) * 1.5;
33 | break;
34 | case Movie.NEW_RELEASE:
35 | thisAmount += thisRental.getDaysRented() * 3;
36 | break;
37 | case Movie.CHILDRENS:
38 | thisAmount += 1.5;
39 | if (thisRental.getDaysRented() > 3)
40 | thisAmount += (thisRental.getDaysRented() - 3) * 1.5;
41 | break;
42 | }
43 |
44 | // add frequent renter points
45 | frequentRenterPoints ++;
46 | // add bonus for a two day new release rental
47 | if ((thisRental.getMovie().getPriceCode() == Movie.NEW_RELEASE) &&
48 | thisRental.getDaysRented() > 1) frequentRenterPoints ++;
49 |
50 | //show figures for this rental
51 | result += "\t" + thisRental.getMovie().getTitle()+ "\t" +
52 | String.valueOf(thisAmount) + "\n";
53 | totalAmount += thisAmount;
54 |
55 | }
56 | //add footer lines
57 | result += "Amount owed is " + String.valueOf(totalAmount) + "\n";
58 | result += "You earned " + String.valueOf(frequentRenterPoints) +
59 | " frequent renter points";
60 | return result;
61 | }
62 | }
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore1-Start/src/Movie.java:
--------------------------------------------------------------------------------
1 | public class Movie {
2 |
3 | public static final int CHILDRENS = 2;
4 | public static final int REGULAR = 0;
5 | public static final int NEW_RELEASE = 1;
6 |
7 | private String _title;
8 | private int _priceCode;
9 |
10 | public Movie(String title, int priceCode) {
11 | _title = title;
12 | _priceCode = priceCode;
13 | }
14 |
15 | public int getPriceCode() {
16 | return _priceCode;
17 | }
18 |
19 | public void setPriceCode(int arg) {
20 | _priceCode = arg;
21 | }
22 |
23 | public String getTitle (){
24 | return _title;
25 | };
26 | }
27 |
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore1-Start/src/Rental.java:
--------------------------------------------------------------------------------
1 | class Rental {
2 | private Movie _movie;
3 | private int _daysRented;
4 |
5 | public Rental(Movie movie, int daysRented) {
6 | _movie = movie;
7 | _daysRented = daysRented;
8 | }
9 |
10 | public int getDaysRented() {
11 | return _daysRented;
12 | }
13 |
14 | public Movie getMovie() {
15 | return _movie;
16 | }
17 | }
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore1-Start/src/TestVideoStore.java:
--------------------------------------------------------------------------------
1 |
2 | public class TestVideoStore {
3 |
4 | public static void main(String[] args) {
5 |
6 | // create some movies
7 | Movie neverEndingStory = new Movie("The NeverEnding Story", Movie.CHILDRENS);
8 | Movie starWars = new Movie("Star Wars: A New Hope", Movie.REGULAR);
9 | Movie solo = new Movie("Solo: A Star Wars Story", Movie.NEW_RELEASE);
10 |
11 | // create an example customer
12 | Customer fredNurke = new Customer("Fred Nurke");
13 |
14 | // add some rentals for the customer
15 | fredNurke.addRental(new Rental(neverEndingStory, 2));
16 | fredNurke.addRental(new Rental(solo, 3));
17 |
18 | // print the customer's statement
19 | System.out.println(fredNurke.statement());
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore2-AmountFor/src/Customer.java:
--------------------------------------------------------------------------------
1 | import java.util.ArrayList;
2 |
3 | class Customer {
4 |
5 | private String _name;
6 | private ArrayList _rentals = new ArrayList();
7 |
8 | public Customer (String name){
9 | _name = name;
10 | };
11 |
12 | public void addRental(Rental arg) {
13 | _rentals.add(arg);
14 | }
15 |
16 | public String getName() {
17 | return _name;
18 | }
19 |
20 | public String statement() {
21 | double totalAmount = 0;
22 | int frequentRenterPoints = 0;
23 | String result = "Rental Record for " + getName() + "\n";
24 | for (Rental thisRental : _rentals) {
25 |
26 | //determine amounts for each line
27 | double thisAmount = amountFor(thisRental);
28 |
29 | // add frequent renter points
30 | frequentRenterPoints ++;
31 | // add bonus for a two day new release rental
32 | if ((thisRental.getMovie().getPriceCode() == Movie.NEW_RELEASE) &&
33 | thisRental.getDaysRented() > 1) frequentRenterPoints ++;
34 |
35 | //show figures for this rental
36 | result += "\t" + thisRental.getMovie().getTitle()+ "\t" +
37 | String.valueOf(thisAmount) + "\n";
38 | totalAmount += thisAmount;
39 |
40 | }
41 | //add footer lines
42 | result += "Amount owed is " + String.valueOf(totalAmount) + "\n";
43 | result += "You earned " + String.valueOf(frequentRenterPoints) +
44 | " frequent renter points";
45 | return result;
46 | }
47 |
48 | private double amountFor(Rental thisRental) {
49 |
50 | double thisAmount = 0;
51 | switch (thisRental.getMovie().getPriceCode()) {
52 | case Movie.REGULAR:
53 | thisAmount += 2;
54 | if (thisRental.getDaysRented() > 2)
55 | thisAmount += (thisRental.getDaysRented() - 2) * 1.5;
56 | break;
57 | case Movie.NEW_RELEASE:
58 | thisAmount += thisRental.getDaysRented() * 3;
59 | break;
60 | case Movie.CHILDRENS:
61 | thisAmount += 1.5;
62 | if (thisRental.getDaysRented() > 3)
63 | thisAmount += (thisRental.getDaysRented() - 3) * 1.5;
64 | break;
65 | }
66 | return thisAmount;
67 | }
68 |
69 | }
70 |
71 |
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore2-AmountFor/src/Movie.java:
--------------------------------------------------------------------------------
1 | public class Movie {
2 |
3 | public static final int CHILDRENS = 2;
4 | public static final int REGULAR = 0;
5 | public static final int NEW_RELEASE = 1;
6 |
7 | private String _title;
8 | private int _priceCode;
9 |
10 | public Movie(String title, int priceCode) {
11 | _title = title;
12 | _priceCode = priceCode;
13 | }
14 |
15 | public int getPriceCode() {
16 | return _priceCode;
17 | }
18 |
19 | public void setPriceCode(int arg) {
20 | _priceCode = arg;
21 | }
22 |
23 | public String getTitle (){
24 | return _title;
25 | };
26 | }
27 |
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore2-AmountFor/src/Rental.java:
--------------------------------------------------------------------------------
1 | class Rental {
2 | private Movie _movie;
3 | private int _daysRented;
4 |
5 | public Rental(Movie movie, int daysRented) {
6 | _movie = movie;
7 | _daysRented = daysRented;
8 | }
9 |
10 | public int getDaysRented() {
11 | return _daysRented;
12 | }
13 |
14 | public Movie getMovie() {
15 | return _movie;
16 | }
17 | }
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore2-AmountFor/src/TestVideoStore.java:
--------------------------------------------------------------------------------
1 |
2 | public class TestVideoStore {
3 |
4 | public static void main(String[] args) {
5 |
6 | // create some movies
7 | Movie neverEndingStory = new Movie("The NeverEnding Story", Movie.CHILDRENS);
8 | Movie starWars = new Movie("Star Wars: A New Hope", Movie.REGULAR);
9 | Movie solo = new Movie("Solo: A Star Wars Story", Movie.NEW_RELEASE);
10 |
11 | // create an example customer
12 | Customer fredNurke = new Customer("Fred Nurke");
13 |
14 | // add some rentals for the customer
15 | fredNurke.addRental(new Rental(neverEndingStory, 2));
16 | fredNurke.addRental(new Rental(solo, 3));
17 |
18 | // print the customer's statement
19 | System.out.println(fredNurke.statement());
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore3-GetCharge/src/Customer.java:
--------------------------------------------------------------------------------
1 | import java.util.ArrayList;
2 |
3 | class Customer {
4 |
5 | private String _name;
6 | private ArrayList _rentals = new ArrayList();
7 |
8 | public Customer (String name){
9 | _name = name;
10 | };
11 |
12 | public void addRental(Rental arg) {
13 | _rentals.add(arg);
14 | }
15 |
16 | public String getName() {
17 | return _name;
18 | }
19 |
20 | public String statement() {
21 | double totalAmount = 0;
22 | int frequentRenterPoints = 0;
23 | String result = "Rental Record for " + getName() + "\n";
24 | for (Rental thisRental : _rentals) {
25 |
26 | //determine amounts for each line
27 | double thisAmount = thisRental.getCharge();
28 |
29 | // add frequent renter points
30 | frequentRenterPoints ++;
31 | // add bonus for a two day new release rental
32 | if ((thisRental.getMovie().getPriceCode() == Movie.NEW_RELEASE) &&
33 | thisRental.getDaysRented() > 1) frequentRenterPoints ++;
34 |
35 | //show figures for this rental
36 | result += "\t" + thisRental.getMovie().getTitle()+ "\t" +
37 | String.valueOf(thisAmount) + "\n";
38 | totalAmount += thisAmount;
39 |
40 | }
41 | //add footer lines
42 | result += "Amount owed is " + String.valueOf(totalAmount) + "\n";
43 | result += "You earned " + String.valueOf(frequentRenterPoints) +
44 | " frequent renter points";
45 | return result;
46 | }
47 |
48 | }
49 |
50 |
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore3-GetCharge/src/Movie.java:
--------------------------------------------------------------------------------
1 | public class Movie {
2 |
3 | public static final int CHILDRENS = 2;
4 | public static final int REGULAR = 0;
5 | public static final int NEW_RELEASE = 1;
6 |
7 | private String _title;
8 | private int _priceCode;
9 |
10 | public Movie(String title, int priceCode) {
11 | _title = title;
12 | _priceCode = priceCode;
13 | }
14 |
15 | public int getPriceCode() {
16 | return _priceCode;
17 | }
18 |
19 | public void setPriceCode(int arg) {
20 | _priceCode = arg;
21 | }
22 |
23 | public String getTitle (){
24 | return _title;
25 | };
26 | }
27 |
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore3-GetCharge/src/Rental.java:
--------------------------------------------------------------------------------
1 | class Rental {
2 | private Movie _movie;
3 | private int _daysRented;
4 |
5 | public Rental(Movie movie, int daysRented) {
6 | _movie = movie;
7 | _daysRented = daysRented;
8 | }
9 |
10 | public int getDaysRented() {
11 | return _daysRented;
12 | }
13 |
14 | public Movie getMovie() {
15 | return _movie;
16 | }
17 |
18 | public double getCharge() {
19 |
20 | double thisAmount = 0;
21 | switch (this.getMovie().getPriceCode()) {
22 | case Movie.REGULAR:
23 | thisAmount += 2;
24 | if (this.getDaysRented() > 2)
25 | thisAmount += (this.getDaysRented() - 2) * 1.5;
26 | break;
27 | case Movie.NEW_RELEASE:
28 | thisAmount += this.getDaysRented() * 3;
29 | break;
30 | case Movie.CHILDRENS:
31 | thisAmount += 1.5;
32 | if (this.getDaysRented() > 3)
33 | thisAmount += (this.getDaysRented() - 3) * 1.5;
34 | break;
35 | }
36 | return thisAmount;
37 | }
38 | }
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore3-GetCharge/src/TestVideoStore.java:
--------------------------------------------------------------------------------
1 |
2 | public class TestVideoStore {
3 |
4 | public static void main(String[] args) {
5 |
6 | // create some movies
7 | Movie neverEndingStory = new Movie("The NeverEnding Story", Movie.CHILDRENS);
8 | Movie starWars = new Movie("Star Wars: A New Hope", Movie.REGULAR);
9 | Movie solo = new Movie("Solo: A Star Wars Story", Movie.NEW_RELEASE);
10 |
11 | // create an example customer
12 | Customer fredNurke = new Customer("Fred Nurke");
13 |
14 | // add some rentals for the customer
15 | fredNurke.addRental(new Rental(neverEndingStory, 2));
16 | fredNurke.addRental(new Rental(solo, 3));
17 |
18 | // print the customer's statement
19 | System.out.println(fredNurke.statement());
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore4-getTotals/src/Customer.java:
--------------------------------------------------------------------------------
1 | import java.util.ArrayList;
2 |
3 | class Customer {
4 |
5 | private String _name;
6 | private ArrayList _rentals = new ArrayList();
7 |
8 | public Customer (String name){
9 | _name = name;
10 | };
11 |
12 | public void addRental(Rental arg) {
13 | _rentals.add(arg);
14 | }
15 |
16 | public String getName() {
17 | return _name;
18 | }
19 |
20 | public String statement() {
21 | double totalAmount = 0;
22 | int frequentRenterPoints = 0;
23 | String result = "Rental Record for " + getName() + "\n";
24 | for (Rental thisRental : _rentals) {
25 |
26 | //determine amounts for each line
27 | double thisAmount = thisRental.getCharge();
28 |
29 | // add frequent renter points
30 | frequentRenterPoints += thisRental.getFrequentRenterPoints();
31 |
32 | //show figures for this rental
33 | result += "\t" + thisRental.getMovie().getTitle()+ "\t" +
34 | String.valueOf(thisAmount) + "\n";
35 | totalAmount += thisAmount;
36 |
37 | }
38 | //add footer lines
39 | result += "Amount owed is " + String.valueOf(getTotalCharge()) + "\n";
40 | result += "You earned " + String.valueOf(getTotalFrequentRenterPoints()) +
41 | " frequent renter points";
42 | return result;
43 | }
44 |
45 | private double getTotalCharge() {
46 | double totalCharge = 0;
47 | for (Rental thisRental : _rentals) {
48 | totalCharge += thisRental.getCharge();
49 | }
50 | return totalCharge;
51 | }
52 |
53 | private int getTotalFrequentRenterPoints() {
54 | int totalFrequentRenterPoints = 0;
55 | for (Rental thisRental : _rentals) {
56 | totalFrequentRenterPoints += thisRental.getFrequentRenterPoints();
57 | }
58 | return totalFrequentRenterPoints;
59 | }
60 |
61 | }
62 |
63 |
64 |
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore4-getTotals/src/Movie.java:
--------------------------------------------------------------------------------
1 | public class Movie {
2 |
3 | public static final int CHILDRENS = 2;
4 | public static final int REGULAR = 0;
5 | public static final int NEW_RELEASE = 1;
6 |
7 | private String _title;
8 | private int _priceCode;
9 |
10 | public Movie(String title, int priceCode) {
11 | _title = title;
12 | _priceCode = priceCode;
13 | }
14 |
15 | public int getPriceCode() {
16 | return _priceCode;
17 | }
18 |
19 | public void setPriceCode(int arg) {
20 | _priceCode = arg;
21 | }
22 |
23 | public String getTitle (){
24 | return _title;
25 | };
26 | }
27 |
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore4-getTotals/src/Rental.java:
--------------------------------------------------------------------------------
1 | class Rental {
2 | private Movie _movie;
3 | private int _daysRented;
4 |
5 | public Rental(Movie movie, int daysRented) {
6 | _movie = movie;
7 | _daysRented = daysRented;
8 | }
9 |
10 | public int getDaysRented() {
11 | return _daysRented;
12 | }
13 |
14 | public Movie getMovie() {
15 | return _movie;
16 | }
17 |
18 | public double getCharge() {
19 |
20 | double thisAmount = 0;
21 | switch (this.getMovie().getPriceCode()) {
22 | case Movie.REGULAR:
23 | thisAmount += 2;
24 | if (this.getDaysRented() > 2)
25 | thisAmount += (this.getDaysRented() - 2) * 1.5;
26 | break;
27 | case Movie.NEW_RELEASE:
28 | thisAmount += this.getDaysRented() * 3;
29 | break;
30 | case Movie.CHILDRENS:
31 | thisAmount += 1.5;
32 | if (this.getDaysRented() > 3)
33 | thisAmount += (this.getDaysRented() - 3) * 1.5;
34 | break;
35 | }
36 | return thisAmount;
37 | }
38 |
39 | public int getFrequentRenterPoints() {
40 | if ((this.getMovie().getPriceCode() == Movie.NEW_RELEASE) && getDaysRented() > 1)
41 | return 2;
42 | else
43 | return 1;
44 | }
45 | }
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore4-getTotals/src/TestVideoStore.java:
--------------------------------------------------------------------------------
1 |
2 | public class TestVideoStore {
3 |
4 | public static void main(String[] args) {
5 |
6 | // create some movies
7 | Movie neverEndingStory = new Movie("The NeverEnding Story", Movie.CHILDRENS);
8 | Movie starWars = new Movie("Star Wars: A New Hope", Movie.REGULAR);
9 | Movie solo = new Movie("Solo: A Star Wars Story", Movie.NEW_RELEASE);
10 |
11 | // create an example customer
12 | Customer fredNurke = new Customer("Fred Nurke");
13 |
14 | // add some rentals for the customer
15 | fredNurke.addRental(new Rental(neverEndingStory, 2));
16 | fredNurke.addRental(new Rental(solo, 3));
17 |
18 | // print the customer's statement
19 | System.out.println(fredNurke.statement());
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore5-HTMLStatement/src/Customer.java:
--------------------------------------------------------------------------------
1 | import java.util.ArrayList;
2 |
3 | class Customer {
4 |
5 | private String _name;
6 | private ArrayList _rentals = new ArrayList();
7 |
8 | public Customer (String name){
9 | _name = name;
10 | };
11 |
12 | public void addRental(Rental arg) {
13 | _rentals.add(arg);
14 | }
15 |
16 | public String getName() {
17 | return _name;
18 | }
19 |
20 | public String statement() {
21 | double totalAmount = 0;
22 | int frequentRenterPoints = 0;
23 | String result = "Rental Record for " + getName() + "\n";
24 | for (Rental thisRental : _rentals) {
25 |
26 | //determine amounts for each line
27 | double thisAmount = thisRental.getCharge();
28 |
29 | // add frequent renter points
30 | frequentRenterPoints += thisRental.getFrequentRenterPoints();
31 |
32 | //show figures for this rental
33 | result += "\t" + thisRental.getMovie().getTitle()+ "\t" +
34 | String.valueOf(thisAmount) + "\n";
35 | totalAmount += thisAmount;
36 |
37 | }
38 | //add footer lines
39 | result += "Amount owed is " + String.valueOf(getTotalCharge()) + "\n";
40 | result += "You earned " + String.valueOf(getTotalFrequentRenterPoints()) +
41 | " frequent renter points";
42 | return result;
43 | }
44 |
45 | public String htmlStatement() {
46 | String result = "
Rentals for " + getName() + "
\n";
47 | for (Rental thisRental : _rentals) {
48 | //show figures for each rental
49 | result += thisRental.getMovie().getTitle()+ ": " +
50 | String.valueOf(thisRental.getCharge()) + " \n";
51 | }
52 | //add footer lines
53 | result += "
You owe " + String.valueOf(getTotalCharge()) + "
\n";
54 | result += "On this rental you earned " +
55 | String.valueOf(getTotalFrequentRenterPoints()) +
56 | " frequent renter points
";
57 | return result;
58 | }
59 |
60 | private double getTotalCharge() {
61 | double totalCharge = 0;
62 | for (Rental thisRental : _rentals) {
63 | totalCharge += thisRental.getCharge();
64 | }
65 | return totalCharge;
66 | }
67 |
68 | private int getTotalFrequentRenterPoints() {
69 | int totalFrequentRenterPoints = 0;
70 | for (Rental thisRental : _rentals) {
71 | totalFrequentRenterPoints += thisRental.getFrequentRenterPoints();
72 | }
73 | return totalFrequentRenterPoints;
74 | }
75 |
76 | }
77 |
78 |
79 |
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore5-HTMLStatement/src/Movie.java:
--------------------------------------------------------------------------------
1 | public class Movie {
2 |
3 | public static final int CHILDRENS = 2;
4 | public static final int REGULAR = 0;
5 | public static final int NEW_RELEASE = 1;
6 |
7 | private String _title;
8 | private int _priceCode;
9 |
10 | public Movie(String title, int priceCode) {
11 | _title = title;
12 | _priceCode = priceCode;
13 | }
14 |
15 | public int getPriceCode() {
16 | return _priceCode;
17 | }
18 |
19 | public void setPriceCode(int arg) {
20 | _priceCode = arg;
21 | }
22 |
23 | public String getTitle (){
24 | return _title;
25 | };
26 | }
27 |
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore5-HTMLStatement/src/Rental.java:
--------------------------------------------------------------------------------
1 | class Rental {
2 | private Movie _movie;
3 | private int _daysRented;
4 |
5 | public Rental(Movie movie, int daysRented) {
6 | _movie = movie;
7 | _daysRented = daysRented;
8 | }
9 |
10 | public int getDaysRented() {
11 | return _daysRented;
12 | }
13 |
14 | public Movie getMovie() {
15 | return _movie;
16 | }
17 |
18 | public double getCharge() {
19 |
20 | double thisAmount = 0;
21 | switch (this.getMovie().getPriceCode()) {
22 | case Movie.REGULAR:
23 | thisAmount += 2;
24 | if (this.getDaysRented() > 2)
25 | thisAmount += (this.getDaysRented() - 2) * 1.5;
26 | break;
27 | case Movie.NEW_RELEASE:
28 | thisAmount += this.getDaysRented() * 3;
29 | break;
30 | case Movie.CHILDRENS:
31 | thisAmount += 1.5;
32 | if (this.getDaysRented() > 3)
33 | thisAmount += (this.getDaysRented() - 3) * 1.5;
34 | break;
35 | }
36 | return thisAmount;
37 | }
38 |
39 | public int getFrequentRenterPoints() {
40 | if ((this.getMovie().getPriceCode() == Movie.NEW_RELEASE) && getDaysRented() > 1)
41 | return 2;
42 | else
43 | return 1;
44 | }
45 | }
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore5-HTMLStatement/src/TestVideoStore.java:
--------------------------------------------------------------------------------
1 |
2 | public class TestVideoStore {
3 |
4 | public static void main(String[] args) {
5 |
6 | // create some movies
7 | Movie neverEndingStory = new Movie("The NeverEnding Story", Movie.CHILDRENS);
8 | Movie starWars = new Movie("Star Wars: A New Hope", Movie.REGULAR);
9 | Movie solo = new Movie("Solo: A Star Wars Story", Movie.NEW_RELEASE);
10 |
11 | // create an example customer
12 | Customer fredNurke = new Customer("Fred Nurke");
13 |
14 | // add some rentals for the customer
15 | fredNurke.addRental(new Rental(neverEndingStory, 2));
16 | fredNurke.addRental(new Rental(solo, 3));
17 |
18 | // print the customer's statement
19 | System.out.println(fredNurke.htmlStatement());
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore6-ChargeInMovie/src/Customer.java:
--------------------------------------------------------------------------------
1 | import java.util.ArrayList;
2 |
3 | class Customer {
4 |
5 | private String _name;
6 | private ArrayList _rentals = new ArrayList();
7 |
8 | public Customer (String name){
9 | _name = name;
10 | };
11 |
12 | public void addRental(Rental arg) {
13 | _rentals.add(arg);
14 | }
15 |
16 | public String getName() {
17 | return _name;
18 | }
19 |
20 | public String statement() {
21 | double totalAmount = 0;
22 | int frequentRenterPoints = 0;
23 | String result = "Rental Record for " + getName() + "\n";
24 | for (Rental thisRental : _rentals) {
25 |
26 | //determine amounts for each line
27 | double thisAmount = thisRental.getCharge();
28 |
29 | // add frequent renter points
30 | frequentRenterPoints += thisRental.getFrequentRenterPoints();
31 |
32 | //show figures for this rental
33 | result += "\t" + thisRental.getMovie().getTitle()+ "\t" +
34 | String.valueOf(thisAmount) + "\n";
35 | totalAmount += thisAmount;
36 |
37 | }
38 | //add footer lines
39 | result += "Amount owed is " + String.valueOf(getTotalCharge()) + "\n";
40 | result += "You earned " + String.valueOf(getTotalFrequentRenterPoints()) +
41 | " frequent renter points";
42 | return result;
43 | }
44 |
45 | public String htmlStatement() {
46 | String result = "
Rentals for " + getName() + "
\n";
47 | for (Rental thisRental : _rentals) {
48 | //show figures for each rental
49 | result += thisRental.getMovie().getTitle()+ ": " +
50 | String.valueOf(thisRental.getCharge()) + " \n";
51 | }
52 | //add footer lines
53 | result += "
You owe " + String.valueOf(getTotalCharge()) + "
\n";
54 | result += "On this rental you earned " +
55 | String.valueOf(getTotalFrequentRenterPoints()) +
56 | " frequent renter points
";
57 | return result;
58 | }
59 |
60 | private double getTotalCharge() {
61 | double totalCharge = 0;
62 | for (Rental thisRental : _rentals) {
63 | totalCharge += thisRental.getCharge();
64 | }
65 | return totalCharge;
66 | }
67 |
68 | private int getTotalFrequentRenterPoints() {
69 | int totalFrequentRenterPoints = 0;
70 | for (Rental thisRental : _rentals) {
71 | totalFrequentRenterPoints += thisRental.getFrequentRenterPoints();
72 | }
73 | return totalFrequentRenterPoints;
74 | }
75 |
76 | }
77 |
78 |
79 |
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore6-ChargeInMovie/src/Movie.java:
--------------------------------------------------------------------------------
1 | public class Movie {
2 |
3 | public static final int CHILDRENS = 2;
4 | public static final int REGULAR = 0;
5 | public static final int NEW_RELEASE = 1;
6 |
7 | private String _title;
8 | private int _priceCode;
9 |
10 | public Movie(String title, int priceCode) {
11 | _title = title;
12 | setPriceCode(priceCode);
13 | }
14 |
15 | public int getPriceCode() {
16 | return _priceCode;
17 | }
18 | public void setPriceCode(int arg) {
19 | _priceCode = arg;
20 | }
21 |
22 | public String getTitle (){
23 | return _title;
24 | };
25 |
26 | int getFrequentRenterPoints(int daysRented) {
27 |
28 | if ((getPriceCode() == Movie.NEW_RELEASE) && daysRented > 1)
29 | return 2;
30 | else
31 | return 1;
32 | }
33 |
34 | public double getCharge(int daysRented) {
35 |
36 | double thisAmount = 0;
37 | switch (this.getPriceCode()) {
38 | case Movie.REGULAR:
39 | thisAmount += 2;
40 | if (daysRented > 2)
41 | thisAmount += (daysRented - 2) * 1.5;
42 | break;
43 | case Movie.NEW_RELEASE:
44 | thisAmount += daysRented * 3;
45 | break;
46 | case Movie.CHILDRENS:
47 | thisAmount += 1.5;
48 | if (daysRented > 3)
49 | thisAmount += (daysRented - 3) * 1.5;
50 | break;
51 | }
52 | return thisAmount;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore6-ChargeInMovie/src/Rental.java:
--------------------------------------------------------------------------------
1 | class Rental {
2 | private Movie _movie;
3 | private int _daysRented;
4 |
5 | public Rental(Movie movie, int daysRented) {
6 | _movie = movie;
7 | _daysRented = daysRented;
8 | }
9 |
10 | public int getDaysRented() {
11 | return _daysRented;
12 | }
13 |
14 | public Movie getMovie() {
15 | return _movie;
16 | }
17 |
18 | public double getCharge() {
19 | return this.getMovie().getCharge(getDaysRented());
20 | }
21 |
22 | public int getFrequentRenterPoints() {
23 | return this.getMovie().getFrequentRenterPoints(getDaysRented());
24 | }
25 | }
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore6-ChargeInMovie/src/TestVideoStore.java:
--------------------------------------------------------------------------------
1 |
2 | public class TestVideoStore {
3 |
4 | public static void main(String[] args) {
5 |
6 | // create some movies
7 | Movie neverEndingStory = new Movie("The NeverEnding Story", Movie.CHILDRENS);
8 | Movie starWars = new Movie("Star Wars: A New Hope", Movie.REGULAR);
9 | Movie solo = new Movie("Solo: A Star Wars Story", Movie.NEW_RELEASE);
10 |
11 | // create an example customer
12 | Customer fredNurke = new Customer("Fred Nurke");
13 |
14 | // add some rentals for the customer
15 | fredNurke.addRental(new Rental(neverEndingStory, 2));
16 | fredNurke.addRental(new Rental(solo, 3));
17 |
18 | // print the customer's statement
19 | System.out.println(fredNurke.statement());
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore7-PriceClass/src/ChildrensPrice.java:
--------------------------------------------------------------------------------
1 |
2 | public class ChildrensPrice extends Price {
3 |
4 | @Override
5 | int getPriceCode() {
6 | return Movie.CHILDRENS;
7 | }
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore7-PriceClass/src/Customer.java:
--------------------------------------------------------------------------------
1 | import java.util.ArrayList;
2 |
3 | class Customer {
4 |
5 | private String _name;
6 | private ArrayList _rentals = new ArrayList();
7 |
8 | public Customer (String name){
9 | _name = name;
10 | };
11 |
12 | public void addRental(Rental arg) {
13 | _rentals.add(arg);
14 | }
15 |
16 | public String getName() {
17 | return _name;
18 | }
19 |
20 | public String statement() {
21 | double totalAmount = 0;
22 | int frequentRenterPoints = 0;
23 | String result = "Rental Record for " + getName() + "\n";
24 | for (Rental thisRental : _rentals) {
25 |
26 | //determine amounts for each line
27 | double thisAmount = thisRental.getCharge();
28 |
29 | // add frequent renter points
30 | frequentRenterPoints += thisRental.getFrequentRenterPoints();
31 |
32 | //show figures for this rental
33 | result += "\t" + thisRental.getMovie().getTitle()+ "\t" +
34 | String.valueOf(thisAmount) + "\n";
35 | totalAmount += thisAmount;
36 |
37 | }
38 | //add footer lines
39 | result += "Amount owed is " + String.valueOf(getTotalCharge()) + "\n";
40 | result += "You earned " + String.valueOf(getTotalFrequentRenterPoints()) +
41 | " frequent renter points";
42 | return result;
43 | }
44 |
45 | public String htmlStatement() {
46 | String result = "
Rentals for " + getName() + "
\n";
47 | for (Rental thisRental : _rentals) {
48 | //show figures for each rental
49 | result += thisRental.getMovie().getTitle()+ ": " +
50 | String.valueOf(thisRental.getCharge()) + " \n";
51 | }
52 | //add footer lines
53 | result += "
You owe " + String.valueOf(getTotalCharge()) + "
\n";
54 | result += "On this rental you earned " +
55 | String.valueOf(getTotalFrequentRenterPoints()) +
56 | " frequent renter points
";
57 | return result;
58 | }
59 |
60 | private double getTotalCharge() {
61 | double totalCharge = 0;
62 | for (Rental thisRental : _rentals) {
63 | totalCharge += thisRental.getCharge();
64 | }
65 | return totalCharge;
66 | }
67 |
68 | private int getTotalFrequentRenterPoints() {
69 | int totalFrequentRenterPoints = 0;
70 | for (Rental thisRental : _rentals) {
71 | totalFrequentRenterPoints += thisRental.getFrequentRenterPoints();
72 | }
73 | return totalFrequentRenterPoints;
74 | }
75 |
76 | }
77 |
78 |
79 |
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore7-PriceClass/src/Movie.java:
--------------------------------------------------------------------------------
1 | public class Movie {
2 |
3 | public static final int CHILDRENS = 2;
4 | public static final int REGULAR = 0;
5 | public static final int NEW_RELEASE = 1;
6 |
7 | private String _title;
8 | private Price _price;
9 | private int _priceCode;
10 |
11 | public Movie(String title, int priceCode) {
12 | _title = title;
13 | setPriceCode(priceCode);
14 | }
15 |
16 | public int getPriceCode() {
17 | return _price.getPriceCode();
18 | }
19 | public void setPriceCode(int arg) {
20 | switch (arg) {
21 | case REGULAR:
22 | _price = new RegularPrice();
23 | break;
24 | case CHILDRENS:
25 | _price = new ChildrensPrice();
26 | break;
27 | case NEW_RELEASE:
28 | _price = new NewReleasePrice();
29 | break;
30 | default:
31 | throw new IllegalArgumentException("Incorrect Price Code");
32 | }
33 | }
34 |
35 | public String getTitle (){
36 | return _title;
37 | };
38 |
39 | int getFrequentRenterPoints(int daysRented) {
40 |
41 | if ((getPriceCode() == Movie.NEW_RELEASE) && daysRented > 1)
42 | return 2;
43 | else
44 | return 1;
45 | }
46 |
47 | double getCharge(int daysRented) {
48 | return _price.getCharge(daysRented);
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore7-PriceClass/src/NewReleasePrice.java:
--------------------------------------------------------------------------------
1 |
2 | public class NewReleasePrice extends Price {
3 |
4 | @Override
5 | int getPriceCode() {
6 | return Movie.NEW_RELEASE;
7 | }
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore7-PriceClass/src/Price.java:
--------------------------------------------------------------------------------
1 |
2 | public abstract class Price {
3 |
4 | abstract int getPriceCode();
5 |
6 | double getCharge(int daysRented) {
7 |
8 | double charge = 0;
9 |
10 | switch (getPriceCode()) {
11 | case Movie.REGULAR:
12 | charge += 2;
13 | if (daysRented > 2)
14 | charge += (daysRented - 2) * 1.5;
15 | break;
16 | case Movie.NEW_RELEASE:
17 | charge += daysRented * 3;
18 | break;
19 | case Movie.CHILDRENS:
20 | charge += 1.5;
21 | if (daysRented > 3)
22 | charge += (daysRented - 3) * 1.5;
23 | break;
24 | }
25 | return charge;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore7-PriceClass/src/RegularPrice.java:
--------------------------------------------------------------------------------
1 |
2 | public class RegularPrice extends Price {
3 |
4 | @Override
5 | int getPriceCode() {
6 | return Movie.REGULAR;
7 | }
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore7-PriceClass/src/Rental.java:
--------------------------------------------------------------------------------
1 | class Rental {
2 | private Movie _movie;
3 | private int _daysRented;
4 |
5 | public Rental(Movie movie, int daysRented) {
6 | _movie = movie;
7 | _daysRented = daysRented;
8 | }
9 |
10 | public int getDaysRented() {
11 | return _daysRented;
12 | }
13 |
14 | public Movie getMovie() {
15 | return _movie;
16 | }
17 |
18 | public double getCharge() {
19 | return this.getMovie().getCharge(getDaysRented());
20 | }
21 |
22 | public int getFrequentRenterPoints() {
23 | return this.getMovie().getFrequentRenterPoints(getDaysRented());
24 | }
25 | }
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore7-PriceClass/src/TestVideoStore.java:
--------------------------------------------------------------------------------
1 |
2 | public class TestVideoStore {
3 |
4 | public static void main(String[] args) {
5 |
6 | // create some movies
7 | Movie neverEndingStory = new Movie("The NeverEnding Story", Movie.CHILDRENS);
8 | Movie starWars = new Movie("Star Wars: A New Hope", Movie.REGULAR);
9 | Movie solo = new Movie("Solo: A Star Wars Story", Movie.NEW_RELEASE);
10 |
11 | // create an example customer
12 | Customer fredNurke = new Customer("Fred Nurke");
13 |
14 | // add some rentals for the customer
15 | fredNurke.addRental(new Rental(neverEndingStory, 2));
16 | fredNurke.addRental(new Rental(solo, 3));
17 |
18 | // print the customer's statement
19 | System.out.println(fredNurke.statement());
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore8-ReplaceSwitchWithPolymorphism/src/ChildrensPrice.java:
--------------------------------------------------------------------------------
1 |
2 | public class ChildrensPrice extends Price {
3 |
4 | @Override
5 | int getPriceCode() {
6 | return Movie.CHILDRENS;
7 | }
8 |
9 | double getCharge(int daysRented){
10 | double charge = 1.5;
11 | if (daysRented > 3)
12 | charge += (daysRented - 3) * 1.5;
13 | return charge;
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore8-ReplaceSwitchWithPolymorphism/src/Customer.java:
--------------------------------------------------------------------------------
1 | import java.util.ArrayList;
2 |
3 | class Customer {
4 |
5 | private String _name;
6 | private ArrayList _rentals = new ArrayList();
7 |
8 | public Customer (String name){
9 | _name = name;
10 | };
11 |
12 | public void addRental(Rental arg) {
13 | _rentals.add(arg);
14 | }
15 |
16 | public String getName() {
17 | return _name;
18 | }
19 |
20 | public String statement() {
21 | double totalAmount = 0;
22 | int frequentRenterPoints = 0;
23 | String result = "Rental Record for " + getName() + "\n";
24 | for (Rental thisRental : _rentals) {
25 |
26 | //determine amounts for each line
27 | double thisAmount = thisRental.getCharge();
28 |
29 | // add frequent renter points
30 | frequentRenterPoints += thisRental.getFrequentRenterPoints();
31 |
32 | //show figures for this rental
33 | result += "\t" + thisRental.getMovie().getTitle()+ "\t" +
34 | String.valueOf(thisAmount) + "\n";
35 | totalAmount += thisAmount;
36 |
37 | }
38 | //add footer lines
39 | result += "Amount owed is " + String.valueOf(getTotalCharge()) + "\n";
40 | result += "You earned " + String.valueOf(getTotalFrequentRenterPoints()) +
41 | " frequent renter points";
42 | return result;
43 | }
44 |
45 | public String htmlStatement() {
46 | String result = "
Rentals for " + getName() + "
\n";
47 | for (Rental thisRental : _rentals) {
48 | //show figures for each rental
49 | result += thisRental.getMovie().getTitle()+ ": " +
50 | String.valueOf(thisRental.getCharge()) + " \n";
51 | }
52 | //add footer lines
53 | result += "
You owe " + String.valueOf(getTotalCharge()) + "
\n";
54 | result += "On this rental you earned " +
55 | String.valueOf(getTotalFrequentRenterPoints()) +
56 | " frequent renter points
";
57 | return result;
58 | }
59 |
60 | private double getTotalCharge() {
61 | double totalCharge = 0;
62 | for (Rental thisRental : _rentals) {
63 | totalCharge += thisRental.getCharge();
64 | }
65 | return totalCharge;
66 | }
67 |
68 | private int getTotalFrequentRenterPoints() {
69 | int totalFrequentRenterPoints = 0;
70 | for (Rental thisRental : _rentals) {
71 | totalFrequentRenterPoints += thisRental.getFrequentRenterPoints();
72 | }
73 | return totalFrequentRenterPoints;
74 | }
75 |
76 | }
77 |
78 |
79 |
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore8-ReplaceSwitchWithPolymorphism/src/Movie.java:
--------------------------------------------------------------------------------
1 | public class Movie {
2 |
3 | public static final int CHILDRENS = 2;
4 | public static final int REGULAR = 0;
5 | public static final int NEW_RELEASE = 1;
6 |
7 | private String _title;
8 | private Price _price;
9 | private int _priceCode;
10 |
11 | public Movie(String title, int priceCode) {
12 | _title = title;
13 | setPriceCode(priceCode);
14 | }
15 |
16 | public int getPriceCode() {
17 | return _price.getPriceCode();
18 | }
19 | public void setPriceCode(int arg) {
20 | switch (arg) {
21 | case REGULAR:
22 | _price = new RegularPrice();
23 | break;
24 | case CHILDRENS:
25 | _price = new ChildrensPrice();
26 | break;
27 | case NEW_RELEASE:
28 | _price = new NewReleasePrice();
29 | break;
30 | default:
31 | throw new IllegalArgumentException("Incorrect Price Code");
32 | }
33 | }
34 |
35 | public String getTitle (){
36 | return _title;
37 | };
38 |
39 | int getFrequentRenterPoints(int daysRented) {
40 |
41 | return _price.getFrequentRenterPoints(daysRented);
42 |
43 | }
44 |
45 | double getCharge(int daysRented) {
46 | return _price.getCharge(daysRented);
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore8-ReplaceSwitchWithPolymorphism/src/NewReleasePrice.java:
--------------------------------------------------------------------------------
1 |
2 | public class NewReleasePrice extends Price {
3 |
4 | @Override
5 | int getPriceCode() {
6 | return Movie.NEW_RELEASE;
7 | }
8 |
9 | double getCharge(int daysRented){
10 | return daysRented * 3;
11 | }
12 |
13 | @Override
14 | int getFrequentRenterPoints(int daysRented) {
15 | return (daysRented > 1) ? 2: 1;
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore8-ReplaceSwitchWithPolymorphism/src/Price.java:
--------------------------------------------------------------------------------
1 |
2 | public abstract class Price {
3 |
4 | abstract int getPriceCode();
5 | abstract double getCharge(int daysRented);
6 |
7 | int getFrequentRenterPoints(int daysRented) {
8 |
9 | return 1; // this default behaviour can be overridden in subclasses
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore8-ReplaceSwitchWithPolymorphism/src/RegularPrice.java:
--------------------------------------------------------------------------------
1 |
2 | public class RegularPrice extends Price {
3 |
4 | @Override
5 | int getPriceCode() {
6 | return Movie.REGULAR;
7 | }
8 |
9 | double getCharge(int daysRented) {
10 | double charge = 2;
11 | if (daysRented > 2)
12 | charge += (daysRented - 2) * 1.5;
13 | return charge;
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore8-ReplaceSwitchWithPolymorphism/src/Rental.java:
--------------------------------------------------------------------------------
1 | class Rental {
2 | private Movie _movie;
3 | private int _daysRented;
4 |
5 | public Rental(Movie movie, int daysRented) {
6 | _movie = movie;
7 | _daysRented = daysRented;
8 | }
9 |
10 | public int getDaysRented() {
11 | return _daysRented;
12 | }
13 |
14 | public Movie getMovie() {
15 | return _movie;
16 | }
17 |
18 | public double getCharge() {
19 | return this.getMovie().getCharge(getDaysRented());
20 | }
21 |
22 | public int getFrequentRenterPoints() {
23 | return this.getMovie().getFrequentRenterPoints(getDaysRented());
24 | }
25 | }
--------------------------------------------------------------------------------
/lecture_slides/VideoStoreExampleCode/VideoStore8-ReplaceSwitchWithPolymorphism/src/TestVideoStore.java:
--------------------------------------------------------------------------------
1 |
2 | public class TestVideoStore {
3 |
4 | public static void main(String[] args) {
5 |
6 | // create some movies
7 | Movie neverEndingStory = new Movie("The NeverEnding Story", Movie.CHILDRENS);
8 | Movie starWars = new Movie("Star Wars: A New Hope", Movie.REGULAR);
9 | Movie solo = new Movie("Solo: A Star Wars Story", Movie.NEW_RELEASE);
10 |
11 | // create an example customer
12 | Customer fredNurke = new Customer("Fred Nurke");
13 |
14 | // add some rentals for the customer
15 | fredNurke.addRental(new Rental(neverEndingStory, 2));
16 | fredNurke.addRental(new Rental(solo, 3));
17 |
18 | // print the customer's statement
19 | System.out.println(fredNurke.statement());
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/lecture_slides/W10_FIT2099 Abstraction.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itsjunqing/fit2099-object-oriented-design-and-implementation/02ee39d4555eebbc1e73ff1fb0abecd8a1d53b26/lecture_slides/W10_FIT2099 Abstraction.pdf
--------------------------------------------------------------------------------
/lecture_slides/W10_FIT2099 Using Abstraction in Java.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itsjunqing/fit2099-object-oriented-design-and-implementation/02ee39d4555eebbc1e73ff1fb0abecd8a1d53b26/lecture_slides/W10_FIT2099 Using Abstraction in Java.pdf
--------------------------------------------------------------------------------
/lecture_slides/W11_FIT2099 Code Smells.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itsjunqing/fit2099-object-oriented-design-and-implementation/02ee39d4555eebbc1e73ff1fb0abecd8a1d53b26/lecture_slides/W11_FIT2099 Code Smells.pdf
--------------------------------------------------------------------------------
/lecture_slides/W11_FIT2099 Refactoring.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itsjunqing/fit2099-object-oriented-design-and-implementation/02ee39d4555eebbc1e73ff1fb0abecd8a1d53b26/lecture_slides/W11_FIT2099 Refactoring.pdf
--------------------------------------------------------------------------------
/lecture_slides/W12_FIT2099 Review.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itsjunqing/fit2099-object-oriented-design-and-implementation/02ee39d4555eebbc1e73ff1fb0abecd8a1d53b26/lecture_slides/W12_FIT2099 Review.pdf
--------------------------------------------------------------------------------
/lecture_slides/W1_Introduction to Object-Orientation.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itsjunqing/fit2099-object-oriented-design-and-implementation/02ee39d4555eebbc1e73ff1fb0abecd8a1d53b26/lecture_slides/W1_Introduction to Object-Orientation.pdf
--------------------------------------------------------------------------------
/lecture_slides/W1_Introduction to Unit 2019 S1.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itsjunqing/fit2099-object-oriented-design-and-implementation/02ee39d4555eebbc1e73ff1fb0abecd8a1d53b26/lecture_slides/W1_Introduction to Unit 2019 S1.pdf
--------------------------------------------------------------------------------
/lecture_slides/W2_Java Fundamentals.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itsjunqing/fit2099-object-oriented-design-and-implementation/02ee39d4555eebbc1e73ff1fb0abecd8a1d53b26/lecture_slides/W2_Java Fundamentals.pdf
--------------------------------------------------------------------------------
/lecture_slides/W3_UML Diagrams.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itsjunqing/fit2099-object-oriented-design-and-implementation/02ee39d4555eebbc1e73ff1fb0abecd8a1d53b26/lecture_slides/W3_UML Diagrams.pdf
--------------------------------------------------------------------------------
/lecture_slides/W4_Excerpt_from_Absolute_Java.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itsjunqing/fit2099-object-oriented-design-and-implementation/02ee39d4555eebbc1e73ff1fb0abecd8a1d53b26/lecture_slides/W4_Excerpt_from_Absolute_Java.pdf
--------------------------------------------------------------------------------
/lecture_slides/W4_Privacy Leaks.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itsjunqing/fit2099-object-oriented-design-and-implementation/02ee39d4555eebbc1e73ff1fb0abecd8a1d53b26/lecture_slides/W4_Privacy Leaks.pdf
--------------------------------------------------------------------------------
/lecture_slides/W5_Commenting_how and why.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itsjunqing/fit2099-object-oriented-design-and-implementation/02ee39d4555eebbc1e73ff1fb0abecd8a1d53b26/lecture_slides/W5_Commenting_how and why.pdf
--------------------------------------------------------------------------------
/lecture_slides/W5_Intro to JavaDoc.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itsjunqing/fit2099-object-oriented-design-and-implementation/02ee39d4555eebbc1e73ff1fb0abecd8a1d53b26/lecture_slides/W5_Intro to JavaDoc.pdf
--------------------------------------------------------------------------------
/lecture_slides/W6_CofojaDemo/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/lecture_slides/W6_CofojaDemo/.factorypath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/lecture_slides/W6_CofojaDemo/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | CofojaDemo
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/lecture_slides/W6_CofojaDemo/.settings/org.eclipse.jdt.apt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.apt.aptEnabled=true
3 | org.eclipse.jdt.apt.genSrcDir=.apt_generated
4 | org.eclipse.jdt.apt.processorOptions/com.google.java.contract.classoutput=%PROJECT.DIR%/bin
5 | org.eclipse.jdt.apt.processorOptions/com.google.java.contract.classpath=%PROJECT.DIR%/lib/cofoja.asm-1.3-20160207.jar
6 | org.eclipse.jdt.apt.processorOptions/com.google.java.contract.sourcepath=%PROJECT.DIR%/src
7 | org.eclipse.jdt.apt.reconcileEnabled=true
8 |
--------------------------------------------------------------------------------
/lecture_slides/W6_CofojaDemo/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6 | org.eclipse.jdt.core.compiler.compliance=1.8
7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12 | org.eclipse.jdt.core.compiler.processAnnotations=enabled
13 | org.eclipse.jdt.core.compiler.source=1.8
14 |
--------------------------------------------------------------------------------
/lecture_slides/W6_CofojaDemo/bin/BankAccount.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itsjunqing/fit2099-object-oriented-design-and-implementation/02ee39d4555eebbc1e73ff1fb0abecd8a1d53b26/lecture_slides/W6_CofojaDemo/bin/BankAccount.class
--------------------------------------------------------------------------------
/lecture_slides/W6_CofojaDemo/bin/ContractsDemo.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itsjunqing/fit2099-object-oriented-design-and-implementation/02ee39d4555eebbc1e73ff1fb0abecd8a1d53b26/lecture_slides/W6_CofojaDemo/bin/ContractsDemo.class
--------------------------------------------------------------------------------
/lecture_slides/W6_CofojaDemo/bin/MeansCofoja.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itsjunqing/fit2099-object-oriented-design-and-implementation/02ee39d4555eebbc1e73ff1fb0abecd8a1d53b26/lecture_slides/W6_CofojaDemo/bin/MeansCofoja.class
--------------------------------------------------------------------------------
/lecture_slides/W6_CofojaDemo/bin/MeansExceptionAssertion.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itsjunqing/fit2099-object-oriented-design-and-implementation/02ee39d4555eebbc1e73ff1fb0abecd8a1d53b26/lecture_slides/W6_CofojaDemo/bin/MeansExceptionAssertion.class
--------------------------------------------------------------------------------
/lecture_slides/W6_CofojaDemo/bin/OverdraftAccount.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itsjunqing/fit2099-object-oriented-design-and-implementation/02ee39d4555eebbc1e73ff1fb0abecd8a1d53b26/lecture_slides/W6_CofojaDemo/bin/OverdraftAccount.class
--------------------------------------------------------------------------------
/lecture_slides/W6_CofojaDemo/lib/cofoja.asm-1.3-20160207.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itsjunqing/fit2099-object-oriented-design-and-implementation/02ee39d4555eebbc1e73ff1fb0abecd8a1d53b26/lecture_slides/W6_CofojaDemo/lib/cofoja.asm-1.3-20160207.jar
--------------------------------------------------------------------------------
/lecture_slides/W6_CofojaDemo/src/BankAccount.java:
--------------------------------------------------------------------------------
1 | import com.google.java.contract.Requires;
2 | import com.google.java.contract.Ensures;
3 |
4 | public class BankAccount {
5 |
6 | protected int balance = 0;
7 |
8 | public int getBalance() {
9 |
10 | return balance;
11 |
12 | }
13 |
14 | @Requires({
15 | "amount >= 0", // must be a non-negative amount
16 | "amount % 10 == 0" // only accept deposits in multiples of 10
17 | })
18 | @Ensures({
19 | "balance == old (balance) + amount"
20 | })
21 | public void deposit(int amount) {
22 |
23 | balance += amount;
24 |
25 | }
26 |
27 | @Requires({
28 | "amount >= 0", // must be a non-negative amount
29 | "amount <= balance" // cannot withdraw more than is in the account
30 | })
31 | @Ensures({
32 | "balance == old (balance) - amount"
33 | })
34 | public void withdraw(int amount) {
35 |
36 | balance -= amount;
37 |
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/lecture_slides/W6_CofojaDemo/src/ContractsDemo.java:
--------------------------------------------------------------------------------
1 |
2 | public class ContractsDemo {
3 |
4 | public static void main(String[] args) throws Exception {
5 |
6 | //MeansExceptionAssertion means = new MeansExceptionAssertion();
7 | MeansCofoja means = new MeansCofoja();
8 | System.out.println(means.geometricMean(3, 8)); //try (-3, 8)
9 |
10 | BankAccount bankAccount = new BankAccount();
11 | bankAccount.deposit(100); // try 101
12 | bankAccount.withdraw(25); // try 125
13 | System.out.println("BankAccount Balance: " + bankAccount.getBalance());
14 |
15 | bankAccount = new OverdraftAccount();
16 | bankAccount.deposit(101);
17 | bankAccount.withdraw(125); // try -125
18 | System.out.println("OverdraftAccount Balance: " + bankAccount.getBalance());
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/lecture_slides/W6_CofojaDemo/src/MeansCofoja.java:
--------------------------------------------------------------------------------
1 | import com.google.java.contract.Ensures;
2 | import com.google.java.contract.Requires;
3 |
4 |
5 | public class MeansCofoja {
6 |
7 | @Requires({
8 | "a >= 0",
9 | "b >= 0"
10 | })
11 | @Ensures({
12 | "Math.abs(result*result - a*b) < 1e-10"
13 | })
14 | public double geometricMean(double a, double b) {
15 |
16 | double result = Math.sqrt(a*b);
17 | //double result = (a + b)/2; // WRONG This is the arithmetic mean
18 | return result;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/lecture_slides/W6_CofojaDemo/src/MeansExceptionAssertion.java:
--------------------------------------------------------------------------------
1 |
2 | public class MeansExceptionAssertion {
3 |
4 | public double geometricMean(double a, double b) throws Exception {
5 | /*
6 | * Start Preconditions
7 | */
8 | // Precondition: firstArgumentNonNegative
9 | if (a < 0) {
10 | throw new Exception("Precondition violated: firstArgumentNonNegative");
11 | } // Precondition: secondArgumentNonNegative
12 | if (b < 0) {
13 | throw new Exception("Precondition violated: secondArgumentNonNegative");
14 | }
15 | /*
16 | * End Preconditions
17 | */
18 |
19 | double result = Math.sqrt(a*b);
20 | //double result = (a + b)/2; // WRONG This is the arithmetic mean
21 |
22 | /*
23 | * Start Postconditions
24 | */
25 | // Postcondition: invertingGeoMeanAccurate
26 | // Note that we should always avoid checking for equality between floating point values, due to finite machine precision
27 | assert(Math.abs(result*result- a*b) < 1e-20) : "Postcondition violated: invertingGeoMeanAccurate";
28 | /*
29 | * End Postconditions
30 | */
31 | return result;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/lecture_slides/W6_CofojaDemo/src/OverdraftAccount.java:
--------------------------------------------------------------------------------
1 | import com.google.java.contract.Ensures;
2 | import com.google.java.contract.Requires;
3 |
4 | public class OverdraftAccount extends BankAccount {
5 |
6 | @Requires({
7 | "amount >= 0", // must be a non-negative amount
8 | // Can accept deposits of any positive amount
9 | })
10 | @Ensures({
11 | "balance == old (balance) + amount"
12 | })
13 | public void deposit(int amount) {
14 |
15 | balance += amount; // note: can't use super due to stronger preconditions
16 |
17 | }
18 |
19 | @Requires({
20 | "amount >= 0", // must be a non-negative amount
21 | })
22 | @Ensures({
23 | "balance == old (balance) - amount"
24 | // balance is allowed to go negative
25 | })
26 | public void withdraw(int amount) {
27 |
28 | balance -= amount;
29 |
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/lecture_slides/W6_FIT2099_DesignByContract 1.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itsjunqing/fit2099-object-oriented-design-and-implementation/02ee39d4555eebbc1e73ff1fb0abecd8a1d53b26/lecture_slides/W6_FIT2099_DesignByContract 1.pdf
--------------------------------------------------------------------------------
/lecture_slides/W6_FIT2099_DesignByContract 2.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itsjunqing/fit2099-object-oriented-design-and-implementation/02ee39d4555eebbc1e73ff1fb0abecd8a1d53b26/lecture_slides/W6_FIT2099_DesignByContract 2.pdf
--------------------------------------------------------------------------------
/lecture_slides/W6_SetDemo/src/ArraySet.java:
--------------------------------------------------------------------------------
1 | public class ArraySet implements Set {
2 |
3 | private int nextInsertPos = 0;
4 | // We will store the contents of the set in an array
5 | private Object[] setContents = new Object[2];
6 | private final int BADINDEX = -1;
7 |
8 | public void insert(Object o) {
9 |
10 | // Insert object o in the set if it does not already exist
11 | if (!contains(o)) {
12 | // first check if there is room to insert the new element of the set
13 | if (nextInsertPos == setContents.length) {
14 | /* create a new array double the size of the previous one
15 | * and copy the contents of the old one to it. Then change the
16 | * setContents attribute to point to the new array
17 | */
18 | Object[] newSetContents = new Object[2*setContents.length];
19 | for (int i = 0; i < setContents.length; i++) {
20 | newSetContents[i] = setContents[i];
21 | }
22 | setContents = newSetContents;
23 | }
24 | // By the time we get to here, we are guaranteed that there will be room
25 | setContents[nextInsertPos++] = o;
26 | }
27 | }
28 |
29 | public void delete(Object o) {
30 |
31 | int oIndex = indexOf(o);
32 | if (oIndex != BADINDEX) {
33 | // Copy the last element of the set over the one to be deleted
34 | setContents[oIndex] = setContents[nextInsertPos - 1];
35 | // reduce the effective size by one
36 | nextInsertPos--;
37 | }
38 | }
39 |
40 | public boolean contains(Object o) {
41 |
42 | return (indexOf(o) != BADINDEX);
43 | }
44 |
45 | @Override
46 | public String toString() {
47 |
48 | String result = "{ ";
49 | int objPos;
50 | for (objPos = 0; objPos < nextInsertPos - 1; objPos++) {
51 | result += setContents[objPos].toString() + ", ";
52 | }
53 | result += setContents[objPos].toString() + " }";
54 | return result;
55 | }
56 |
57 | private int indexOf(Object o) {
58 |
59 | /* Find the position of o in the array. Note we don't look beyond
60 | * nextInsertPos, as anything beyond that is either not yet assigned
61 | * or rubbish that was previously deleted
62 | * Returns index of o in contents array. Returns BADINDEX (-1) if
63 | * not found. Dodgy c-like practice, so keep it private.
64 | */
65 |
66 | boolean found = false;
67 | int objPos;
68 | for (objPos = 0; (objPos < nextInsertPos) && !found; objPos++) {
69 | found = (setContents[objPos] == o);
70 | }
71 | if (found) {
72 | // remember objPos will have been incremented after o was found
73 | return objPos - 1;
74 | }
75 | else {
76 | return BADINDEX;
77 | }
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/lecture_slides/W6_SetDemo/src/Driver.java:
--------------------------------------------------------------------------------
1 |
2 | public class Driver {
3 |
4 | public static void main(String[] args) {
5 |
6 | Set set = new ArraySet();
7 | /* Note that the method testSet(...) has no knowledge of the
8 | * concrete class of the object passed to it. All it knows is that
9 | * it will implement the interface "Set".
10 | */
11 | System.out.println("Test an ArraySet:");
12 | testSet(set);
13 | set = new HashSet();
14 | System.out.println("\nTest a HashSet:");
15 | testSet(set);
16 |
17 | }
18 |
19 | public static void testSet (Set set) {
20 |
21 | testInsert(set, 2);
22 | testInsert(set, 4);
23 | testInsert(set, 6);
24 | testInsert(set, 8);
25 | testInsert(set, 6);
26 | System.out.println(set);
27 |
28 | testDelete(set, 2);
29 | System.out.println(set);
30 |
31 | testDelete(set, 4);
32 | System.out.println(set);
33 |
34 | testDelete(set, 4);
35 | System.out.println(set);
36 |
37 | testDelete(set, 8);
38 | System.out.println(set);
39 |
40 | testInsert(set, 8);
41 | testInsert(set, 6);
42 | System.out.println(set);
43 |
44 | for (int i : new int[]{2, 8, 9, 6}) {
45 | if (set.contains(i)) {
46 | System.out.println("Set contains " + i);
47 | }
48 | else {
49 | System.out.println("Set does not contain " + i);
50 | }
51 | }
52 | testInsert(set, 10);
53 | testInsert(set, 11);
54 | testInsert(set, "frog");
55 | testInsert(set, 12);
56 | testInsert(set, 13);
57 | testInsert(set, 14);
58 | testInsert(set, 15);
59 | testInsert(set, 16);
60 | testInsert(set, 17);
61 | testInsert(set, 6);
62 | System.out.println(set);
63 | testDelete(set, "frog");
64 | System.out.println(set);
65 | }
66 |
67 | private static void testInsert(Set set, Object o) {
68 | System.out.println("Inserting: " + o);
69 | set.insert(o);
70 | }
71 |
72 | private static void testDelete(Set set, Object o) {
73 | System.out.println("Deleting: " + o);
74 | set.delete(o);
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/lecture_slides/W6_SetDemo/src/HashSet.java:
--------------------------------------------------------------------------------
1 | import java.util.HashMap;
2 |
3 | public class HashSet implements Set {
4 |
5 | // We will store the contents of the set in a HashMap
6 | private HashMap