Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Download the files IntegerList.java and ScoresList.java from Blackboard and save

ID: 3549046 • Letter: D

Question



Download the files IntegerList.java and ScoresList.java from Blackboard and save on your H:drive.


2. Study the code in both files carefully. Note that all of the instance methods of the IntegerList class are "stubbed" in so that the class will compile but no method is fully implemented. That is what you will be doing in this lab.

a. Which class would be considered the Server and which the Client?


3. The IntegerList class defines an IntegerList type that is capable of storing a list of integers and providing the user with methods that will calculate the average of the values, the maximum of the values, the minimum of the values and various other methods. The ScoresList program will instantiate an IntegerList object and then call the methods to show that they work.

This is a Scores List Menu

1. Add a score to the collection of scores.

2. Find the average of the values in the collection.

3. Find the minimum value of the collection.

4. Find the maximum value of the collection.

5. Display all values.

6. Find number of occurrences for a particular score

7. Exit


Enter the number of your choice:

4. Now that you have an overview of the functionality and relationship of these two classes, run the program in its current incomplete state. To do so:

a. Compile both files. (i.e. javac IntegerList.java and javac ScoresList.java)

b. Execute the class that contains the main method (i.e. java ScoresList)

c. Make choices from the menu and observe the results. Note that the messages include values of zero or "NaN" (not a number) for each choice.

Complete each method of the IntegerList class, using the client class ScoresList to test each completion.

Task #1 Adding elements in an array

First we turn our attention to the add method of IntegerList class. We will complete the method and then test using the client program.


Open the IntegerList.java file and modify this method by assigning the value v to the current list element as directed by the comments for the method. Remember to remove (or comment out) any not implemented type statements!

Save your changes and recompile the new version of IntegerList.java. Note that you do not have to re-compile the client since you made no changes to it. Run ScoresList to test the change you made by choosing the following sequence of choices from the

a. Choose menu item 1. When prompted, add the values 3, 9, 10 ending with -1 to return to the menu.

b. Choose menu item 5. The values 3, 9 and 10 should be displayed. If not, there is an error in your code. Exit the program and debug as needed. Otherwise, continue to the next step without exiting the program.

c. Choose menu item 1. When prompted add the values 2, 4 and then -1 to return to the menu.

d. Choose menu item 5. The list 3, 9, 10, 2, and 4 should be displayed. If not, there is an error in your code. Choose 7 to exit the program and debug as needed. Otherwise, exit the program and go to the next activity!

Task #2 Finding the minimum value in an array

Next we complete the min method. We will complete the method and then run the client program to test the result.

In the IntegerList class, modify this method as directed by the comments for the method to determine the minimum value in the array list. You may want to refer to the arrays PowerPoint on Blackboard. Remember to remove (or comment out) any "not implemented" type statements. Save your changes and recompile the new version of this class. Note that you do not have to re-compile the client class since you made no changes to it. Run the client, ScoresList to test the new method by making the following sequence of choices from the

a. Choose menu item 1. When prompted, add the values 30, 2, 8, 4 ending with -1 to return to the menu. b. Choose menu item 3. You should see the minimum value of 2 displayed. If not, there is a bug in your code. Choose menu item 7 to exit, debug your code and begin again with a). Otherwise, exit the menu and go to the next activity!

Task #3 Finding the maximum value in an array

Next we complete the max method of the IntegerList class. We will complete the method and then test using the client program. In the IntegerList class, modify this method as directed by the comments for the method to determine the maximum value in the array list. You may want to refer to the arrays PowerPoint on Blackboard.Remember to remove (or comment out) the "not implemented" type statements. Save your changes and recompile the new version of IntegerList.java. Note that you do not have to re-compile the client since you made no changes to it.Run the client to view the results of the change you made by choosing the following sequence of choices from the menu:

a. Choose menu item 1. When prompted, add the values 14, 33, 9, and 5 ending with -1 to return to the menu.

b. Choose the menu item 4 for finding the maximum. You should see the maximum value of 33 displayed. If not, there is a bug in your code. Choose menu item 7 to exit, debug your code and begin again with a). Otherwise, exit the menu and go to the next activity!

Task #4 Finding the average in an array

Next we complete the average method and then run the client program to test.

In the IntegerList class, modify this method as directed by the comments for the method to determine the average value in the array list. You may want to refer to the arrays PowerPoint on Blackboard. Remember to remove (or comment out) the "not implemented" type statements. Save your changes and recompile the new version of IntegerList.java. Note that you do not have to re-compile the client since you made no changes to it. Run the client to view the results of the change you made by choosing the following sequence of choices from the menu:

a. Choose menu item 1. When prompted, add the values 5, 8, and 6 ending with -1 to return to the menu.

b. Choose the menu item 2 for finding the average. You should see the average of 6.33333333 displayed. If not, there is a bug in your code. Choose menu item 7 to exit. Debug your code and begin with a. Otherwise, exit the menu and go to the next activity!

Task #5 Determining the number of times a score appears in the list

Add a method to the IntegerList class that will count the number of times a score appears in the list as directed by the comments for the method. Save your changes and recompile the new version of IntegerList.java. Note that you do not have to re-compile the client since you made no changes to it. Run the client to view the results of the change you made by choosing the following sequence of choices from the menu:

a. Choose menu item 1. When prompted, add the values 9, 5, 8, 6 and 9 ending with -1 to return to the menu.

b. Choose the menu item for finding the number of occurrences for the score 9. The score 9 appears twice in your list. Choose menu item 7 to exit. Debug your code, if necessary.

Task #6 Increasing the number of elements in list

Add a method to the IntegerList class that will increase the size of list as directed by the comments for the method. Save your changes and recompile the new version of IntegerList.java. Note that you do not have to re-compile the client since you made no changes to it. Run the client to view the results of the change you made by choosing the following sequence of choices from the menu:

a. Choose menu item 1. When prompted, add the values 1,2,3,4,5,6,7,8,9,10 ending with -1 to return to the menu.

b. Choose the menu item 5 to verify that all 10 elements of list are those entered in instruction a.


c. Choose menu item 1. When prompted, add the values 13 and 14. Now choose menu item 5 again and verify these two elements have been added. Note that because the array size is now 20, there will be 8 zeroes displayed if you used the array length. Choose menu item 7 to exit.








Pls download ( Java Files to be use ) from : http://pastebin.com/UNCujsp2



Explanation / Answer

First Class

public class IntegerList { // Declare constant for default capacity public final static int CAPACITY=10; //Declare the instance variables private int count; // holds the number of integers stored in the list private int [] list; // holds the reference to the array of integers private int minValue; private int maxValue; //default constructor method used to instantiate an array of size 10 by default public IntegerList() { list = new int[CAPACITY]; count = 0; minValue=0; maxValue=100; } //constructor method used to instantiate an array of a user specified size public IntegerList( int size ) { list = new int[size]; count=0; minValue=0; maxValue=100; } //constructor method used to instantiate an array of a user specified size public IntegerList( int minValue, int maxValue ) { list = new int[CAPACITY]; count=0; this.minValue = minValue; this.maxValue = maxValue; } /**Appends the specified element to the end of the list @param v - the element to be added @return void */ public void add(int v) { if (v >= minValue && v <= maxValue) // if the value is within range { if (count < list.length) // if there is still an available slot in the array { //Task #1 //NOT IMPLEMENTED YET // assign the value v to the next available slot in list. //Note that count keeps track of the current empty slot. list[count] = v; }    else { increase(); // list is full - increase size of list array by calling // the private method increase list[count] = v; //now add the new value to list } count++; // increment the counter } else { System.out.println("Error: The value is out of range. Value not added"); } } /**Finds the minimum value store in the list @return the minimum of all values */ public int min () { //Task #2 //NOT IMPLEMENTED YET int min = list[0]; // Use count as the upper boundary of your for-loop // Why is count used as the upper boundary vs. list.length? for (int i = 1; i < count; i++){ if (list[i]< min){ min = list[i]; } } return min; }    /**Finds the maximum value store in the list @return the maximum of all values */ public int max () { //Task #3 //NOT IMPLEMENTED YET int max = list[0]; for (int i = 1; i < count; i++){ if (list[i]> max){ max = list[i]; } } //Use count as the upper boundary of your for-loop // Why is count used as the upper boundary vs. list.length? return max; } /**Finds the average value store in the list @return the average of all values */ public double average () { //Task #4 //NOT IMPLEMENTED YET // first we calculate the sum double sum =0;    //Again, use count as the upper boundary rather than list.length? for (int i = 0; i < count; i++){ sum += list[i]; } // now we can calculate and return the average - Note: why is count used as the denominator vs. array.length? return sum / count; } /**Finds the number of times a score occurs in the list @return the number of times score occurs */    public int countOf(int score) { //Task #5 //NOT IMPLEMENTED YET int scoreCount=0; for (int i = 0; i < count; i++){ if (list[i]== score){ scoreCount++; } } //Again, use count as the upper boundary vs. list.length? //Step through array. If the element is equal to the "score" I'm looking //for, then increment scoreCount return scoreCount; } /**Adds elements to the list array by adding CAPACITY number of elements */ private void increase() { int newLength = list.length + CAPACITY; //Add 10 to current list.length int [ ] temp = new int[newLength]; // Create a temp array that is the new list length    //Task #6 //NOT IMPLEMENTED YET    // Copy contents of list array into the temp array for (int i = 0; i < list.length; i++) { temp[i] = list[i]; } list = temp;    //assign list to temp (Note that this statement uses the address of temp and list)       }    /**Displays all values in the array */ public void display() { for (int i=0; i < list.length; i++) System.out.println(list[i]); } }   
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote