Difference between revisions of "Iterable Range Assignment"

From CSE425S Wiki
Jump to navigation Jump to search
Line 15: Line 15:
 
  <nowiki>public static Iterable<Integer> minToMaxExclusive(int min, int maxExclusive)</nowiki>
 
  <nowiki>public static Iterable<Integer> minToMaxExclusive(int min, int maxExclusive)</nowiki>
  
=Example=
+
=Client=
{{Example|RangesExample|range.example}}
+
{{Example|RangesClient|range.client}}
  
 
The code:
 
The code:
  <nowiki>for(int i : Ranges.minToMaxExclusive(4, 12)) {
+
  <nowiki>for (int i : Ranges.minToMaxExclusive(4, 12)) {
 
System.out.println(i);
 
System.out.println(i);
 +
}
 +
System.out.println();
 +
for (double d : Ranges.minToMaxExclusive(3, 7.1, 0.25)) {
 +
System.out.println(d);
 
}</nowiki>
 
}</nowiki>
  
Line 31: Line 35:
 
9
 
9
 
10
 
10
11</nowiki>
+
11
 +
 
 +
3.0
 +
3.25
 +
3.5
 +
3.75
 +
4.0
 +
4.25
 +
4.5
 +
4.75
 +
5.0
 +
5.25
 +
5.5
 +
5.75
 +
6.0
 +
6.25
 +
6.5
 +
6.75
 +
7.0</nowiki>
  
 
=Test=
 
=Test=
 
{{TestSuite|RangesTestSuite|range.warmup}}
 
{{TestSuite|RangesTestSuite|range.warmup}}

Revision as of 02:27, 26 November 2022

Code To Investigate

Iterable

interface java.lang.Iterable<T>

Iterator<T> iterator()

Iterator

interface java.util.Iterator<T>

boolean hasNext()
T next()

Code To Implement

minToMaxExclusive

class: Ranges.java Java.png
methods: minToMaxExclusive
package: range.warmup
source folder: src/main/java
public static Iterable<Integer> minToMaxExclusive(int min, int maxExclusive)

Client

class: RangesClient.java Presentation icon-72a7cf.svg
package: range.client
source folder: src/main/java

The code:

for (int i : Ranges.minToMaxExclusive(4, 12)) {
	System.out.println(i);
}
System.out.println();
for (double d : Ranges.minToMaxExclusive(3, 7.1, 0.25)) {
	System.out.println(d);
}

produces the output:

4
5
6
7
8
9
10
11

3.0
3.25
3.5
3.75
4.0
4.25
4.5
4.75
5.0
5.25
5.5
5.75
6.0
6.25
6.5
6.75
7.0

Test

class: RangesTestSuite.java Junit.png
package: range.warmup
source folder: src/test/java