Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programming Assignment 2 : Ordered Collection of Things using Array Goal: Can represent an ordered collection using an array Problem Description You will be creating

Programming Assignment2: Ordered Collection of Things using Array
Goal: Can represent an ordered collection using an array
Problem Description
You will be creating an ordered collection class. You will be storing your things in an array.
You may NOT use the Java library classes AxraxList or Vector or any other java collection class.
You must use simple java Arrays in the same way as discussed in class.
No method in the collection class should print anything!!!!
The name of your collection class should include the name of your Thing. For example, if your Thing is called Book, then your collection class should be called BogkCollestion. Alternatively, if your collection class has a natural group name, please use that. This will help with "thinking" in objects. For example, a collection of books can be called a library.
Collection Class
A collection class is a class that can hold a group of items. In this assignment, you will create an array inside your collection class to hold your things as follows: implement a collection class of your things using an array. Your collection class must have the following characteristics:
[2 points] Include exactly two instance variables such that:
the first instance variable must be an array to hold the things in your collection
the second instance variable is an integer to represent how many items are in your collection
[2 points] 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.
[4 points] boglead insert(Thing) : a method that takes one input parameter matching the type of your Thing and then inserts it in the collection class IN DESCENDING ORDER according to the search key instance variable. Return false if there was no room for the item, true otherwise.
[4 points] void delete(Thing) : this method takes one input parameter of your type of Thing. The method then searches the collection for the first object that equals the input object and deletes its occurrence if found. After the item has been deleted, the list must still be maintained IN ORDER.
[2 points] int size() : a method that returns the number of objects in the collection. collection, false otherwise.
[3 points] int indexQf(Thing) : a method that returns the index of the first instance of Thing found in the collection. Returns -1 if not found.
[3 points] int dastTndexof(Thing) : a method that returns the index of the last instance of Thing found in the collection. Returns -1 if not found.
[3 points] berlear contains (Thing) : this method takes one input parameter matching the type of your Thing. The method returns true or fal se based on whether the collection contains at least one Thing that is equal to the input parameter. Use the equals () method from your Thing class to determine if two objects are equal.
[3 points] String testring() : 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, one Thing per line. toString() will not print but rather will return a String. For example, a String representing a list of students (in reverse order by name) could be formatted as follows:
\table[[Name,Age,Registered],[Reem,27,true],[Mohammed,25,false],[Maria,20,true],[Hanna,30,true]]
[3 points] Thing find(String): this method depends on the search key attribute of your Thing class. The method takes as input a String value and returns the first object with a search key that matches the input search value. Depending on the value of the parameter, the method returns the number of Things whose beglean instance variable is true or the number of Things whose boolean instance variable is false.
[2 points] int total () : this method uses the int instance variable of your Thing class. The method calculates and returns the sum of the int instance variables all objects stored in the collection.
[2 points] double average () : this method returns the average of the int instance variables of all objects stored in the collection.
[2 points] int sruatRapgs (int low, int high): this method depends on the int instance variable of your Thing class. The method takes as input two int values and counts how many objects in the list have a value that lies in the given range including the endpoints. Note that if the first input parameter is greater than the second input parameter then the method always returns 0(i.e., crunt Range ) returns 0).
image text in transcribed

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

Advances In Spatial And Temporal Databases 10th International Symposium Sstd 2007 Boston Ma Usa July 2007 Proceedings Lncs 4605

Authors: Dimitris Papadias ,Donghui Zhang ,George Kollios

2007th Edition

3540735399, 978-3540735397

More Books

Students also viewed these Databases questions

Question

b. Explain how you initially felt about the communication.

Answered: 1 week ago