Question: Use Java 8 Add a method called addItem that takes a String and appends it to the array of String which represents contents of this
Use Java 8

Add a method called addItem that takes a String and appends it to the array of String which represents contents of this Bag. If this Bag is full (i.e., the number of contents in this Bag is equal to this Bag's capacity), return the input String. Otherwise, return null, which means the item has been added to this Bag. Add a method called popItem, which removes and returns the last item added to this Bag. If this Bag is empty, return null. abstract class Bag { private String color; private int capacity; private int number0fContents; private String[] contents; public Bag(String color, int capacity) { this.color = color; this.capacity = capacity; this.contents = new String[capacity]; // Getters: getColor, getNumber0fContents, and getCapacity public String getColor (0 { return this.color; public int getNumberofContents() { return this.numberofContents; public int getCapacity() { return this.capacity; // Setter: setColor public void setColor(String color) { this.color = color; public String addItem(String str) { // Insert code here } public String popItem() { // Insert code here } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
