Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement your Thing class Start by choosing what sort of list you would like to keep. For example: To-do list. Vacation and travel information Pets

Implement your Thing class Start by choosing what sort of list you would like to keep.

For example: To-do list. Vacation and travel information Pets Real estate properties pretty much any sort of list You can be creative about your list. It is prohibited to use grocery items, student, bank accounts, or songs.

Your Thing class must have the following characteristics:

has exactly 3 instance variables such that: o one instance variable must be integer (i.e, int) and this variable will be used to find aggregate information about Things that are stored in a collection class as will be explained later. o

one instance variable must be String and this variable will be used as a search key. o

The third variable can be either int or String type based on the semantics of your Thing.

All instance variables must be private. Implement getters and setters for all the attributes of your Thing.

Implement toString method that returns a String representation of your Thing class where all the instance variables are in one line and separated by tabs.

Implement the equals method for your Thing where two things are considered equal when they have the same values in the three instance variables. Note that, the equality of String attributes should be case insensitive.

For example, MATH, math and Math match each other. In order to compare strings in Java use the String's equalsIgnoreCase method. For example, the following code prints true: String str1 = "Hello"; String str2 = "hello"; System.out.println(str1.equalsIgnoreCase(str2));

Part 2: Implement a Collection class Implement a collection class of Things using an array. You may NOT use the Java library classes ArrayList or Vector or any other java collection class. b.

You must use simple java Arrays in the same way as we implemented IntArrayBag collection in class.

The name of your collection class should include the name of your Thing. For example, if your Thing is called Country, then your collection class should be called CountryArrayBag.

Implement a constructor for your collection class that takes one input parameter that represents the maximum number of elements that can be stored in your collection.

Implement the following methods in your collection class:

1. insert: a method that takes three input parameters and uses these inputs to instantiate an object of type Thing, initialize its instance variables, and then inserts it in the collection class.

2. size: a method that returns the number of objects in the collection.

3. toString: a method that returns a String representation of the collection that includes all elements that are stored in the collection. The output string must be nicely formatted in a tabular format. For example, a list of students is to be displayed as follows: name age major --------------------------- John 20 CS Eric 25 CIT Hanna 30 Math Reem 27 CS

4. display: this method depends on the search key attribute of the Thing class. The method takes as input a String value and displays all objects with a search key that matches the input search value. The display must be nicely displayed in a tabular format similar to the toString method output as discussed above. Note that the search key should be key insensitive. For example, MATH, math and Math match each other. Note also that this method displays the output on the screen and does not return any output. For example, the call display("cs") on the students collection class prints the following: name age major --------------------------- John 20 CS Reem 27 CS

5. countOccurrences: this method depends on the search key attribute of the Thing class. The method takes as input a String value and returns as output the number of objects in the collection that possesses a search key attribute that matches the input search value. Same to the display method, the key match should be case insensitive.

6. contains: this method takes one input parameter of type Thing. The method returns true or false based on whether the collection contains at least one Thing that is equal to the input parameter. Note that the equality of things is determined by the equals method in your Thing's class.

7. total: this method uses the int instance variable of the Thing class. Basically, the method calculates and returns the sum of the int instance variable of all objects stored in the collection. For example, in the student collection, this method finds the sum of age of all students in the list. This sum can be used, for example, along with the output of the size method to find the average student age.

8. countRange: this method depends on the int instance variable of the Thing class. The method takes as input two int values and counts how many objects in the list has a value that lies in the given range. For example, in the student collection class that is displayed above, countRange(25,30) returns 3 because there are 3 students with age values that fall in the range between 25 and 30 inclusive. Note that if the first input parameter is less than the second input parameter then the method always return 0 (i.e., countRange(30,25) returns 0).

9. delete: similar to the contains method, this method takes one input parameter of type Thing. The method then searches the collection for an object that equals the input object and deletes one occurrence of that object if found. The method then displays a message at the end to say whether an object is deleted or there were no objects with the given search key. The method also returns true if an object is deleted and false otherwise.

Part 3: Implement your Driver class Implement a Driver class that works as follows:

create a collection class with capacity 10.

Uses the insert method to insert 5 items in the collection. You may use any arbitrary values in the objects to be inserted.

The driver then calls the methods 2 through 9 in order. Note that you do not have to use a Scanner to read any inputs from the user. On the other hand, use hard coded values for the different methods' inputs.

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 Technology And Management Computers And Information Processing Systems For Business

Authors: Robert C. Goldstein

1st Edition

0471887374, 978-0471887379

More Books

Students also viewed these Databases questions

Question

BF 1 9 ? ?

Answered: 1 week ago

Question

Consistently develop management talent.

Answered: 1 week ago

Question

Create a refreshed and common vision and values across Europe.

Answered: 1 week ago

Question

Provide the best employee relations environment.

Answered: 1 week ago