Difference between revisions of "PowersOf2Iterable"
Line 18: | Line 18: | ||
=Code to Implement= | =Code to Implement= | ||
+ | It is important to consider what state each class should encapsulate. The class PowersOfTwoLessThan, which is Iterable, should be have need to store little (if anything) beyond the maxExclusive passed in to its constructor. Further, PowersOfTwoLessThan should be immutable. There is no need to change any of the data during its lifetime. | ||
+ | |||
+ | The Iterator<Integer> instances created whenever one invokes the iterator() method? Now, the data for those instances are going to need to mutate. | ||
+ | |||
{{CodeToImplement|PowersOfTwoLessThan|constructor<br/>iterator|slices.studio}} | {{CodeToImplement|PowersOfTwoLessThan|constructor<br/>iterator|slices.studio}} | ||
Line 25: | Line 29: | ||
==iterator== | ==iterator== | ||
{{Sequential|public Iterator<Integer> iterator()}} | {{Sequential|public Iterator<Integer> iterator()}} | ||
+ | |||
+ | Investigate: [https://docs.oracle.com/javase/tutorial/java/javaOO/anonymousclasses.html Anonymous Inner Classes] | ||
=Testing Your Solution= | =Testing Your Solution= |
Revision as of 21:58, 21 January 2020
Contents
Motivation
Experience with implementing interfaces.
Warm Up
If you are struggling with this studio, consider completing the Shape warm up.
Investigate
interface Iterable<T>
interface Iterator<T>
Mistakes To Avoid
Warning: Do NOT Parallelize |
Code to Implement
It is important to consider what state each class should encapsulate. The class PowersOfTwoLessThan, which is Iterable, should be have need to store little (if anything) beyond the maxExclusive passed in to its constructor. Further, PowersOfTwoLessThan should be immutable. There is no need to change any of the data during its lifetime.
The Iterator<Integer> instances created whenever one invokes the iterator() method? Now, the data for those instances are going to need to mutate.
class: | PowersOfTwoLessThan.java | |
methods: | constructor iterator |
|
package: | slices.studio | |
source folder: | student/src/main/java |
constructor
method: public PowersOfTwoLessThan(int maxExclusive)
(sequential implementation only)
iterator
method: public Iterator<Integer> iterator()
(sequential implementation only)
Investigate: Anonymous Inner Classes
Testing Your Solution
Correctness
class: | PowersOfTwoTestSuite.java | |
package: | powersoftwo.studio | |
source folder: | testing/src/test/java |
Pledge, Acknowledgments, Citations
file: | studio-powers-of-two-iterable-pledge-acknowledgments-citations.txt |
More info about the Honor Pledge