---
tags: Setup
---
# Lecture 14 Setup/Prep
Last class, we talked about the importance of putting methods into the classes that held the data needed by the methods. Getting methods into the right classes supports making data private and is part of good OO design.
This lecture, we will look at guidelines for when to break a larger class into several smaller classes. We'll continue working with the Banking example from last class.
## Prep
Here is the [starter code](https://brown-cs18-master.github.io/content/lectures/14mvc/lec14init.zip), which extends on the code from the last lecture. In the new code:
- the common for-loop code in the `withdraw` and `getBalance` methods in the `BankingService` class have been abstracted into a helper function (called `findAccount` which is private and also in the `BankingService` class)
- there is a `loginScreen` method for having a user enter their username and password
When deciding what classes to create for a larger program, there are two guidelines:
- create a class for each distinct entity or artifact with fields (e.g., `Account`, `Customer`)
- make separate classes for parts that you might want to swap out for a different class that provides similar functionality but in a different way (e.g., replace a linked list with an array list)
We will start by looking at the `BankingService` and asking how many separate classes we might break it into. Come to class familiar with which methods are in the `BankingService` (what they do, not the details of their code).
## UPDATE -- Monday 9:10am
If your version of the starter code has a for-loop for finding the customer inside the `login` method in `BankingService`, please replace your `login` method with the following two methods.
```
private Customer findCustomer(String custname) {
for (Customer cust:customers) {
if (cust.nameMatches(custname)) {
return cust;
}
}
return null;
}
public String login(String custname, String withPwd) {
Customer cust = findCustomer(custname);
if (cust.checkPwd(withPwd)) {
return "Welcome";
} else {
return "Try Again";
}
return "Oops -- don't know this customer";
}
```
## Update -- Monday 10:55 AM
```
// add to BankingService
public void addCustomer(Customer newC) {
this.customers.addFirst(newC);
}
// new main method in Main class
public static void main(String[] args) {
BankingService B = new BankingService();
Customer kCust = new Customer("kathi", "cs18");
Account kAcct = new Account(100465, kCust, 150);
B.addAccount(kAcct);
B.addCustomer(kCust); // <--- this line is new
B.loginScreen();
kAcct.printBalance();
B.withdraw(100465, 30);
kAcct.printBalance();
}
```