Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 8image text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g Database Administrator Implementation And Administration

Authors: Gavin Powell, Carol McCullough Dieter

2nd Edition

1418836656, 9781418836658

More Books

Students also viewed these Databases questions