Suppose that class bag is a javautilcollection that


Java

Given the specification of a class, write code that uses it.

Suppose that class Bag is a java.util.Collection that represents a bunch of items, where the same item can appear multiple times. 

It provides methods 

public void add(Item item)  

//adds item to this Bag (if item is already present, it adds another one)  

public int size( )       

//returns the number of items including duplicates

public Item remove( )   

//removes a random item from this Bag and returns a copy of it.

Write the following method. 

You can assume that Item is Comparable

public class X{

//returns the number of different items in bag. Bag is unchanged.

public static int numDifItems( Bag bag ){

Solution Preview :

Prepared by a verified Expert
Basic Computer Science: Suppose that class bag is a javautilcollection that
Reference No:- TGS02562358

Now Priced at $10 (50% Discount)

Recommended (96%)

Rated (4.8/5)