Use the supplied Widget class
In the primary logic, instantiate an ArrayList of Widget Loop 20 times
In each iteration use a Supplier
The value should be a random value from -10 to 90
The name should be a String made of random uppercase letters (ASCII codes 65 to 90)
For each random Widget, use a Predicate
If the Widget has a positive value, use a UnaryOperator
If the Widget has a negative value, ignore that Widget and move on
Outside of that loop, create another loop to iterate through the ArrayList
For each iteration, use a Consumer< Widget> to print each Widget on its own line
Do not use the toString() method of Widget
The format should be: Widget[ value: 77 name: pfwiiqdd] where the fields for value and name have a fixed width
/**
* A simple Widget for demonstrating lambda expressions.
*
* @author Bob Trapp
*/
public class Widget implements Comparable{
/**
* A numeric value.
*/
private int value;
/**
* The name of the Widget.
*/
private String name;
/**
* The full constructor.
*
* @param value a numeric value
* @param name the name of the Widget
*/
public Widget(int value, String name) {
this.value = value;
this.name = name;
}
/**
* An override of toString()
*
* @return a String representation of the Widget
*/
@Override
public String toString() {
return "Widget{" + "value=" + value + ", name=" + name + '}';
}
/**
* A numeric value.
*
* @return the value
*/
public int getValue() {
return value;
}
/**
* A numeric value.
*
* @param value the value to set
*/
public void setValue(int value) {
this.value = value;
}
/**
* The name of the Widget.
*
* @return the name
*/
public String getName() {
return name;
}
/**
* The name of the Widget.
*
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* An implementation of Comparable to help sort Widget objects by value.
*
* @param otherWidget
* @return
*/
@Override
public int compareTo(Widget otherWidget) {
return this.value - otherWidget.getValue();
}
}