Computer Science 210
Data Structures

Fall 2017, Siena College

Lab 1: Array Practice
Due: the start of your next lab session

You will be paired with a partner to complete this lab. Only one submission per group is needed.

Getting Set Up

You will receive an email with the link to follow to set up your GitHub repository arraypractice-lab-yourgitname for this Lab. One member of the group should follow the link to set up the repository on GitHub, then that person should email the instructor with the other group members' GitHub usernames so they can be granted access. This will allow all members of the group to clone the repository and commit and push changes to the origin on GitHub. At least one group member should make a clone of the repository to begin work.

In your git bash window, after you clone and cd to the repository, you can type the command

touch package.bluej

which will create the little BlueJ icon for you to click on to launch BlueJ.

Please answer lab questions in the README.md file in your group's GitHub repository.

Collaborating with git and GitHub

Once your repository has been set up to grant access to all group members, complete this section to learn how git and GitHub can help with group work.

Each group member should clone a copy of the repository and make changes to the file Collaborate.java. Be careful to modify in different parts. Each group member should modify one of the lines in the class comment with his or her name (but each should choose a different one). And each group member should add an additional printout (but each should be in a different place) in the main method.

When done, each can commit to his/her own clone of the repository. One group member can then push to the origin on GitHub (which should be successful). If a second member then tries to push, an error message will be printed, stating that the clone is not up to date. A pull is needed, which will then merge the changes made by the group member who already pushed to the origin with the changes made by the group member trying to pull. So do that git pull, and as long as changes are made in different parts of the file, git will be able to do this automatically. If you have a third group member, repeat for the third member's changes. Now, the origin has everyone's changes. Group members can each then perform a pull to update their own clone to have everyone's changes.

This process will be very helpful when working in groups on labs and projects in this course, and in all of your programming careers in school and beyond. No emailing files back and forth or trying to figure out who changed what since the last time files were exchanged.

Practicing with Arrays

For this section, you will be writing some methods that operate on arrays. You are responsible for writing the methods, and adding code to the main method to test them thoroughly. Place all of these in the provided ArrayPractice class. Note that your methods should not print their answers. Instead, they should return their answers so they can be printed by your test cases in main.

  1. Write a method sum that takes an array of double values as its parameter and returns the sum of all elements in the array.
  2. Write a method sum that takes an array of int values as its parameter and returns the sum of all elements in the array.
  3. Write a method largest that takes an array of int values as its parameter and returns the value of the largest element in the array.
  4. Write a method countLarger that takes an array of int values and an additional int as its parameters, and returns the number of entries in the array that are at least as large as the additional int.
  5. Write a method countTrues that takes an array of boolean values as its parameter and returns the number of entries that contain true.
  6. Write a method stringLengths that takes an array of String values as its parameter and returns an array of int that contains the lengths of those Strings. That is, each element in the returned array contains the length of the String in the corresponding element of the parameter array.

Question 1: You have two methods named sum. How does Java know which one to execute when you call sum in your main method? (2 points)

Modifying Arrays

In many of our examples so far, we have constructed and populated an array and but not changed it. In situations where this is necessary, we will need to make the distinction between the size, or length of the array, and the number of elements currently stored within it.

The ArrayModifier class includes a main method that will allow you to implement some array modifications. In the while loop in the main method, fill in the missing functionality for the "add", "insert", "remove", and "clear" commands.

Submitting

Your submission requires that all required deliverables are committed and pushed to the master for your repository's origin on GitHub. That's it! If you see everything you intend to submit when you visit your repository's page on GitHub, you're set.

Grading

This assignment is worth 80 points, which are distributed as follows:

> FeatureValueScore
Collaborate.java changes 5
sum of double method 5
sum of int method 5
largest method 5
countLarger method 7
countTrues method 5
stringLengths method 8
test cases in ArrayPractice main 15
Lab question 1 2
ArrayModifier add command 6
ArrayModifier insert command 8
ArrayModifier remove command 6
ArrayModifier clear command 3
Total 80