ECET370 Lab 1
Scenario and Summary
The purpose of the lab exercises is to help the student acquire skills in developing programs that require the implementation with arrays of abstract data types, such as lists and bags.
There are four exercises in this lab, although not all of them will be required for submission. Be sure to read the following instructions carefully.
Exercise 1: No submission is required.
Exercise 2 contains parts a, b, c and continues through part h. Keep in mind that the methods developed for each of these parts should be within the same ArrayList class. We have added in Doc Sharing a framework for the ArrayList class with stubs for these methods. Use the framework to complete the exercise.
Create a folder and name it Week 1 Lab. Inside this folder, create the subfolders Ex2, Ex3, and Ex4. Place the solution to each of the three exercises required for submission in the corresponding subfolder. Compress the folder Week 1 Lab using a program like WinZip, and drop the resulting zipped folder into the Dropbox.
Note that Exercises 2, 3, and 4 require software development. Place in the corresponding folders only .java files. Do not submit the .class files or other files or folders that are generated by the IDE.
Access the software at https://lab.devry.edu .
Exercise 1: Review of Array-Based Lists
Back to Top
Create a project using the classes in the Doc Sharing area labeled A Simple ArrayList class.
Compile it, run it, and review the code that is given carefully. This code tests the ArrayList class provided in the lecture.
Exercise 2: Implementing an Array List
Back to Top
Modify the class ArrayList given in the lecture by adding the methods to it listed below for Exercise 2. In each case, the appropriate error message should be generated if an invalid condition occurs. For example, an error message should be generated when trying to insert an item in a given location in the list and the location is out of range. Create a main class to test your ArrayList class.
a. ArrayList(int size): Create a constructor that sets the size of the array list to the value passed in size (note that the class variable size cannot be final anymore).
b. int getLength(): Create this method to return the number of items in the list (accessor method).
c. int getSize(): Create this method to return the size of the list (accessor method).
d. void clear(): Create this method to remove all of the items from the list. After this operation, the length of the list is zero.
e. void replace(int location, int item): Create this method to replace the item in the list at the position specified by location. The item should be replaced with item.
f. void add(int location, int item): Create this method to add an item to the list at the position specified by location.
g. void remove(int item): Create this method to remove an item from the list. All occurrences of the item in the list should be removed.
h. int get(int location): Create a method that returns the element at location.
In the Doc Sharing area labeled Implementing an ArrayList class, you will find the basic framework of the ArrayList class you need to use to implement your solution.
Exercise 3: Using an Array-Based List
Back to Top
Using the class ArrayList completed in the previous exercise, write a program to store the first 30 Fibonacci numbers in an ArrayList object.
Exercise 4: Implementing a Bag Class
Back to Top
Create a class Bag (multiset) that uses an array to store the bag items. The class should have the methods listed below. Create a main class to test your Bag class. This main class should fill a bag of integers with 10 random numbers, each in the interval [0, 15], and print how many times each integer in the interval [0, 15] appears in the bag.
a. Bag(): default constructor that sets the size of the bag to 20
b. Bag(int size): nondefault constructor that sets the size of the bag to the value passed in size
c. boolean isEmpty(): determines whether the bag is empty
d. void display(): prints the bag elements
e. int getLength(): returns the number of items in the bag
f. int getSize(): returns the size of the bag
g. void clear(): removes all of the items from the bag
h. void add(int item): adds an item to the bag
i. void remove(int item): removes an item from the bag; all occurrences of item in the bag should be removed.
j. int count(int item): counts the number of occurrences of item in the bag
(Note that you can reuse the code completed in Exercise 2 for the ArrayList class to create your Bag class. It will help you to save development time.)
Here is compete solution for ECET370 Lab 1
If you have more questions, please contact me via email firstname.lastname@example.org
I will help you any time