Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the BookArrayBag application from slide #6 in the lecture-03-jan-28.pptx. Consider also the following BookArrayBagDriver, 8 public class BookArrayBagDriver { 90 public static void main

image text in transcribedimage text in transcribedimage text in transcribed

Consider the BookArrayBag application from slide #6 in the lecture-03-jan-28.pptx. Consider also the following BookArrayBagDriver, 8 public class BookArrayBagDriver { 90 public static void main (String args[]) { 10 BookArrayBag myBag = new BookArrayBag(5); 11 myBag.add(new Book ("Database", 2011)); 12 myBag.add(new Book ("Operating Systems", 1991)); 13 Book algorithms = new Book ("Algorithms", 1991); 14 myBag.add(algorithms); 16 System.out.println(myBag); System.out.println(myBag.size()); 18 System.out.println(myBag.grab(2)); System.out.println(myBag.find(new Book("Database", 0))); Book programming = new Book("programming", 0); if (myBag.find(programming)==null) myBag.add(programming); 27 System.out.println(myBag); myBag.remove(new Book("algorithms",0)); System.out.println(myBag.countOccurances (algorithms)); myBag.remove(new Book ("Database",0)); System.out.println(myBag.grab(0)); 1 Implementing BookArrayBag Book -title: String - year : int + Book ( title : String, year: int) + getTitle(): String + getYear(): int + setTitle (title : String): void + setYear (year: int) : void + equals ( obj: Object): boolean + toString(): String BookArrayBag - data : Book[] manyltems : int + BookBag () + BookBag ( capacity: int ) + add (b: Book ) : void + remove (b: Book ) : void + size(): int + grab (index : int ): Book + find (b: Book): Book + countOccurrences (b:Book): int + toString(): String + max(): Book *Two books are equal when they have the same title (case insensitive). ICS 240-50: Introduction to Data Structures - Spring 2022 Exercise 2: replace method in IntArrayBag Implement an instance method belonging to the IntArrayBag class that takes two input parameters, oldval and newval. The method replaces each oldval element in the array with newVal. Make sure to include the method header. Exercise 3: countInYear method in BookArrayBag Consider the BookArrayBag from slide #6 in the lecture-03-jan-28.pptx. Write an instance method belonging to BookArrayBag that takes one integer input, called year, and returns as output the number of books published in that year. Exercise 4: equalsTo method for IntArrayBag Implement a static method, called equalsTo, in the IntArrayBag's class that takes one input parameter and returns a boolean value. The input parameter is of type IntArrayBag. The method returns true if the input bag and the bag that activates the method have exactly the same elements. Otherwise the method return false. Note that the locations of the elements in the data arrays are not necessarily be the same, it is only the number of occurrences of each element that must be the same

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_2

Step: 3

blur-text-image_3

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

The Structure Of The Relational Database Model

Authors: Jan Paredaens ,Paul De Bra ,Marc Gyssens ,Dirk Van Gucht

1st Edition

3642699588, 978-3642699580

Students also viewed these Databases questions

Question

Describe your ideal working day.

Answered: 1 week ago

Question

LO1 Summarize the organizations strategic planning process.

Answered: 1 week ago