---
# System prepended metadata

title: Lab 2 Mini-Assignment
tags: [Labs/Sections]

---

# Class Relationships Section Mini-Assignment

:::danger
Due Date: Before your section (Tuesday-Thursday, September 24-26)
:::

## Introduction: 
This mini-assignment will focus on association, scope and parameter passing. This will be useful for our upcoming project –– TicTacToe –– as well as for larger projects later in the semester. We recommend you complete this as thoroughly as possible, as it will help you better understand the concepts. All mini-assignments will be graded on completion and thoughtfulness.
 
### Helpful Resources: 
 - [Working with Objects Lecture Part 1](https://cs.brown.edu/courses/cs015/lecture/pdf/CS15.Lecture_4_Working_With_Objects.9.17.24.pdf)
 - [Working with Objects Lecture Part 2](https://cs.brown.edu/courses/cs015/lecture/pdf/CS15.Lecture_5_Working_With_Objects_Part_2.9.19.24.pdf)
 - [Ed](https://edstem.org/us/courses/63887/discussion/)
 - [Project Hours](https://cs.brown.edu/courses/cs015/)

### Problem 1: Pong Reflection

In Pong, you used a helper method to assist in restarting the game. In your own words, explain **what** a helper method is and **why** you think it was useful in this context. It might be helpful to think about what your program would have looked like without this method. If you think it was unnecessary, please explain why. 

### Problem 2: Class Relationships

Look over the program below and answer the questions that follow.

<span style="font-family: 'Consolas', monospace;">public class App {
&nbsp;&nbsp;&nbsp;public static void main(String[] args) {
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.wipeTables();
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.takeOrder();
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.prepareIngredients();
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.makeChineseFood();
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.serveFood();
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.processPayments();
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.cleanKitchen();
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.takeInventory();
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.orderSupplies();
&nbsp;&nbsp;&nbsp;}
[code elided]
}
</span>


1. What, if anything, is wrong with the design of this program?
2. How can we use association to improve the design of this program? Briefly propose an alternative design based on your ideas. 
3. Draw a class diagram for the new design proposed in (b).

### Problem 3: Scope
*Remember*, scope is defined as: where, in a program, a variable “exists.”

<span style="font-family: 'Consolas', monospace;">public class CS15Section {
&nbsp;&nbsp;&nbsp;private TeachingAssistant <span style="color: red;">ta</span>;
&nbsp;&nbsp;&nbsp;public CS15Section() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.ta = new TeachingAssistant();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.startSection();
&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;public void startSection() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Projector <span style="color: blue;">projector</span> = new Projector();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.ta.projectSlides(projector);
&nbsp;&nbsp;&nbsp;}
}
</span>

Look at the code above and determine the scopes of the two highlighted variables:
1. What is the scope of the <span style="color: red;">ta</span>?
2. What is the scope of the <span style="color: blue;">projector</span> variable?
3. Are these local or instance variables?



## To Handin: 
Fill out [this form](https://docs.google.com/forms/d/e/1FAIpQLScyLNF9O9WYtQU6RG1r-V74l5YNzjyydvofKRG7rNKRK2Bw5A/viewform) with your answers before the due date. Any handins after the due date will not be accepted.