Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

needs to be in java For this program you are to complete the methods given to you to implement a bag (data . structure) using

needs to be in java image text in transcribed
image text in transcribed
image text in transcribed
For this program you are to complete the methods given to you to implement a bag (data . structure) using an array. A bag is an unordered collection of values that can have duplicate values. Your task is to fill in the implementation of the methods that manipulates an array of integers.. We have provided a main method in the Main class that tests some of your methods. We will, not be grading the main method in this assignment. Do not have any extraneous print statements in your program, including error messages. Your program should print out exactly what is specified and nothing else. (If the comment prefixing a method does not mention printing, the method should not print anything.) Adds an element to the bag into the first (smallest index) empty location. If the bag is full then print an error message. public static void add(int item, int bag[]) \{\} /** Removes all elements, with the specified value, from the bag. Print an error message if the bag is empty or if the specified item is not in the bag.\% public static void remove(int item, int bag[]) \{\} / Removes all elements from the bag. */ public static void reset(int bag[]) \{\} /** Counts and returns the frequency of the specified item in the bag. * public static int getFrequency(int item, int bag[]) \{\} /** Prints all elements in the bag. */ public static void display(int bag[]) \{\} output should be: 1 Bag: 000000 2 Can not remove an item from an empty bag. 3 Bag: 10000 4 Bag: 12000 5 Bag: 128300 6 Bag: 12340 7 Bag: 12040 8 Bag: 12540 9 Item not found in the bag. Nothing removed 10Bag: 12546 11 Can not add an item to a full bag. 12Bag: 12546 13 Bag: 12540 14 Bag: 125541 15 Bag: 02540 16 Bag: 00000 17 Can not remove an item from an empty bag. 18 There are 5 zeroes

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

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions

Question

What is the multiple regression equation?

Answered: 1 week ago