Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using the given BagInterface program, complete problem 1, thanks in advance! Using the given generic interface Baginterface.java, create a class MyBag.java which is a generic

image text in transcribedimage text in transcribed

Using the given BagInterface program, complete problem 1, thanks in advance!

Using the given generic interface Baginterface.java, create a class MyBag.java which is a generic class which implements Baginterface.java. It should contain the following attributes: int size - The current number of items in the bag. TO bag - The generic array in question - this will change data type based on how it is called in a program. As well as the following constructors/methods: MyBago: constructor - initializes bag as an object array casted as the T[ data type, size is set to 0. getCurrentSize(): int - returns the current number of items in the bag./ isEmptyO: Boolean - returns true if bag is empty, false otherwise. add(T newEntry): void - adds a new entry into the bag. If bag has no room, create an array 1 element larger using Arrays.copyOf. remove(): T-Removes a random item from the bag (to determine which, use java.util.Random). Returns the removed item. remove(T anEntry): boolean - Attempts to remove the item anEntry from the bag. Returns true if able to remove item from bag, false otherwise. clear(): void Empties the bag. getCountOf(T anEntry): boolean - Returns the number of times 'anEntry' occurs in the bag. contains(T anEntry): boolean - returns true if the bag contains 'anEntry'. toString : String - returns a String containing the contents of the bag. * This is a variation of the BagInterface from the text: + "Data Structures and Abstractions with JAVA" * by Frank Carrano and Timothy Henry * This is a generic interface, the class which implements this interface, * must be a generic container for values of any type "T" stands for some unknown class type public interface BagInterface { getCurrentSize(): This method returns the current number of items in the bag public int getCurrentSize(); isEmpty(): This method returns true if the bag is empty public boolean isEmpty(); add(newEntry): This method adds a new entry into the Bag public void add(T newEntry); remove(): This removes a random item from the bag, use the library import java.util. Random public T remove(); remove (T anEntry): This method returns true if the bag contains a specific entry, and that entry is successfully removed from the bag. public boolean remove(T anEntry); clear(): Empties the Bag */ public void clear(); getCountof(T anEntry): returns the number of times "anEntry" occurs in the Bag public int getCountOF(T anEntry); contains(T anEntry): returns true if the Bag contains "anEntry" public boolean contains(T anEntry); toString(): returns a String containing the contents of the bag 1 public String toString(); }

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

Database Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

More Books

Students also viewed these Databases questions

Question

what is Edward Lemieux effect / Anomeric effect ?

Answered: 1 week ago

Question

Define Management by exception

Answered: 1 week ago

Question

Explain the importance of staffing in business organisations

Answered: 1 week ago