Question: / / fill this out and make sure it works / / streamtest . java package question 3 ; import java.util.stream.Stream; public class StreamsTest {

//fill this out and make sure it works
//streamtest.java
package question3;
import java.util.stream.Stream;
public class StreamsTest {
public static class Item {
Double amount;
Integer count;
ItemType itemType;
public Item(Double amount, Integer count, ItemType itemType){
this.amount = amount;
this.count = count;
this.itemType = itemType;
}
}
// question3.java
package question3;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.testng.Assert;
import org.testng.annotations.Test;
public class Question3{
/*
* Create a stream method that returns the total amount for each item, filtered by item type
*/
@Test
public void test(){
var item = new StreamsTest.Item(100.0,2, StreamsTest.ItemType.RETURN);
Assert.assertEquals(StreamsTest.processStream(
List.of(item).stream(), StreamsTest.ItemType.RETURN)
.mapToDouble((a -> a)).sum(),200.0);
var item2= new StreamsTest.Item(100.0,3, StreamsTest.ItemType.RETURN);
Assert.assertEquals(StreamsTest.processStream(
List.of(item, item2).stream(), StreamsTest.ItemType.RETURN)
.mapToDouble((a -> a)).sum(),500.0);
Assert.assertEquals(StreamsTest.processStream(
List.of(item, item2).stream(), StreamsTest.ItemType.PURCHASE)
.mapToDouble((a -> a)).sum(),0.0);
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!