Use the supplied Widget class

In the primary logic, instantiate an ArrayList of Widget Loop 20 times

In each iteration use a Supplier to get a randomly generated Widget

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 to test if the value is zero or greater.

If the Widget has a positive value, use a UnaryOperator to convert the Widget name to all lowercase letters, then add the Widget to the ArrayList

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();
}

}
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.