Course Solutions Uncategorized (Solved) : Modify Following Shelf Class Becomes Generic Class String Class Replaced Class Public Clas Q28059161 . . . .

(Solved) : Modify Following Shelf Class Becomes Generic Class String Class Replaced Class Public Clas Q28059161 . . . .

 

Modify the following Shelf class so it becomesa Generic class where String class can be replaced with anyclass.

Public class Shelf{

private String[] items;

private int capacity, itemsNumber = 0;

private String mainItem;

public Shelf(int capacity){

items = (String[]) new String [capacity];

}

public void add (String item){

if (!item.equals(mainItem))

items[itemsNumber++] = item;

}

public String getFirst() {return items[0];}

public int getCapcity() {return capacity;}

}

Expert Answer


An answer will be send to you shortly. . . . .

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post