Difference between revisions of "PowersOf2Iterable"

From CSE231 Wiki
Jump to navigation Jump to search
Line 2: Line 2:
 
Experience with implementing interfaces.
 
Experience with implementing interfaces.
  
=Warm Up=
+
=Warm Ups=
If you are struggling with this studio, consider completing the [[Shape]] warm up.
+
If you are struggling with this studio, consider completing one or both of the warm ups
 +
==Shape==
 +
Complete the [[Shape]] warm up to gain experience with implementing an interface, as well as declaring and using fields.
 +
 
 +
==DoubleRange==
 +
The [[DoubleRange]] warm up to gain experience implementing an Iterable<T> without simply containing a List<T> which holds the values.
  
 
=Investigate=
 
=Investigate=

Revision as of 03:38, 28 January 2020

Motivation

Experience with implementing interfaces.

Warm Ups

If you are struggling with this studio, consider completing one or both of the warm ups

Shape

Complete the Shape warm up to gain experience with implementing an interface, as well as declaring and using fields.

DoubleRange

The DoubleRange warm up to gain experience implementing an Iterable<T> without simply containing a List<T> which holds the values.

Investigate

interface Iterable<T>

interface Iterator<T>

Mistakes To Avoid

Attention niels epting.svg Warning: Do NOT Parallelize
Attention niels epting.svg Warning: Do NOT confuse Iterable<T> from Iterator<T>

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.

One should NOT need to create a List to support this class. A single private final double instance variable is all you need for PowersOfTwoLessThan and a single (mutable) double instance variable is all you need for its Iterator.

class: PowersOfTwoLessThan.java Java.png
methods: constructor
iterator
package: slices.studio
source folder: student/src/main/java

constructor

method: public PowersOfTwoLessThan(int maxExclusive) Sequential.svg (sequential implementation only)

iterator

method: public Iterator<Integer> iterator() Sequential.svg (sequential implementation only)

Investigate: Anonymous Inner Classes

Testing Your Solution

Correctness

class: PowersOfTwoTestSuite.java Junit.png
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