---
# System prepended metadata

title: Loops + ArrayLists Section Mini-Assignment
tags: [Labs/Sections]

---

# Loops + ArrayLists Section Mini-Assignment
:::danger
**Due Date:** Before your section (**Tuesday, October 22-Thursday, October 24**)
:::

## Introduction:
This mini assignment focuses on working with a partner, loops, and ArrayLists – all of which will be helpful to you while completing Doodle Jump. If you need help we recommend the resources listed below, asking on Ed, or going to conceptual hours. You should email your section TAs your completed mini assignment before the start of your section.

### Helpful Resources
 - Loops lecture
 - Arrays lecture
 - [Part 1 of Lab 5 (the section on GitHub and merging)](https://hackmd.io/@Fall2024-CS15/HJKArBCsR)
 - [CS15 Partner Guide](https://docs.google.com/document/d/1lQosdXxv7iWerTrgZC2TsTQgvv4m1K5EAzNCjP2cc-Q/edit)
 - [CS15 Partner Logistics](https://docs.google.com/document/d/1Pg5YtaoUKsykerqjwS3E7BsLiy8ZDdiY-AZl_hwdwW0/edit#heading=h.hl218puks2cr)

### Problem 0: Working with a Partner
For Doodle Jump, you may be partner programming for the first time in this course! Coordinating and working with others on writing code is an invaluable skill, and something you will be doing a lot more of (both at Brown and in industry) if you choose to continue with computer science. When working with a partner, **communication is key**.

If you’re working with a partner, please take a moment now to think about a couple questions you would like to ask your partner to ensure you’re on the same page before you start coding and note them down here (one good example could be “what time of day do you prefer for us to meet up?” but come up with at least 2 of your own!).

### Problem 1: GitHub
As we saw in last week’s lab, GitHub can get a little trickier when working with another person. You learned about the git pull command that you can use to update the code on your computer to match with whatever your partner has pushed to GitHub. We now have three essential steps (some of which use git terminal commands) while working on projects: 

1. Add, commit, and push your code to GitHub
2. Run the **`git pull`** command (which incorporates any changes made elsewhere, e.g., on your partner’s laptop, into your code base)
3. Write/make changes to your code 

Which of the following is the correct order to do these actions in order to **best try to avoid merge conflicts**? 

a) 1, 3, 2
b) 3, 1, 2
c) 2, 3
d) 2, 3, 1
e) 3, 1

### Problem 2: Understanding Loops

#### Part A: Loop Iterations
How many times will each of the following loops run before terminating? 

**Question 1:**
<span style="font-family: 'Consolas', monospace;">for(int i = 0; i <= 15; i++) {
&nbsp;&nbsp;&nbsp;i++;
}
</span>
    
**Question 2:** 
<span style="font-family: 'Consolas', monospace;">int count = 10;
    while (count < 15) {
&nbsp;&nbsp;&nbsp;count = 10 + 1;
}
</span>
    
#### Part B: Updating Variables
What will the final value of <span style="font-family: 'Consolas', monospace;">myVar</span> be at the end of each of the following loops?

**Question 1:**
<span style="font-family: 'Consolas', monospace;">int myVar = 10;
    do {
&nbsp;&nbsp;&nbsp;this.waitForCollege();
&nbsp;&nbsp;&nbsp;myVar++;
} while(myVar < 13)</span>

**Question 2:**
<span style="font-family: 'Consolas', monospace;">String myVar;
String[] rainbow = new String[7]
rainbow[0] = “red”;
rainbow[1] = “green”;
rainbow[2] = “violet”;
rainbow[3] = “yellow”;
rainbow[4] = “orange”;
rainbow[5] = “blue”;
rainbow[6] = “indigo”;
for(String color : rainbow) {
&nbsp;&nbsp;&nbsp;myVar = color;
}

</span>

    
### Problem 3: Understanding Arrays + ArrayLists
What type of error, if any, will the following pieces of code produce?

**Question 1** 
<span style="font-family: 'Consolas', monospace;">Dog[] dogs = new Dog[8];
for(int i = 0; i <= dogs.length; i++) {
&nbsp;&nbsp;&nbsp; dogs[i] = new Terrier();
}
</span>
    
**Question 2**
<span style="font-family: 'Consolas', monospace;">Dog[] dogs = new Dog[8];
for(int i = 0; i < dogs.length; i++) {
&nbsp;&nbsp;&nbsp; dogs[i].bark();
}
                              
</span>
    
**Question 3**
<span style="font-family: 'Consolas', monospace;">ArrayList<Dog> dogs = new ArrayList<>();  
dogs.add(new Poodle());
dogs.add(new Labrador());
dogs.add(1, null);
dogs.add(0, new Beagle());
dogs.remove(2);
for (Dog dog: dogs) {
&nbsp;&nbsp;&nbsp; dog.bark();
}
</span>

## To Handin: 
Submit your answers to [this form](https://docs.google.com/forms/d/e/1FAIpQLSeM-0OLuonAPtuS_yzetCPlsm6ZPtHlLFsyps3n8snmxtqCYA/viewform) before your due date. Any handins after the due date will not be accepted. 
