Skip to main content

Lab 08: Interfaces


The main goals for this lab are for you to get more comfortable implementing interfaces and working with classes.

Paired Programming rules

This lab is a paired programming assignment. What exactly does that mean? You will be working in pairs on the CS lab computers. Each pair will be working on one computer. One person will be the driver and the other person will be the navigator. Here is the rule: the driver controlls the lab computer, but the driver can only type what the navigator tells them to type. For this to work well, each pair should be constantly talking among themselves. After each problem, you will switch roles, the navigator will become the driver and the driver will become the navigator.

Partners You must work with your partner from last week. If they are not here, please see your instructor.

Finishing the lab

Before leaving the lab, make sure you fill out the attendance sheet and go through your answers with a TA or instructor. You will not get full credit otherwise.

1. Overview

In this lab you will be adding some features to a Bank. You will be creating a file, called By the end of this lab, you will have written a program to that implements a working Bank.

TODO: Download the files and from

2. MyBank

Create a new class called MyBank. The class should contain the following instance methods:

For this lab, it is okay if you do not implement getters or setters.

Hint: Make sure the access modifiers for the instance variables ensure that no other class can directly access the instance variables.

TODO: Implement a constructor that specifies the size of the Bank, i.e. how many accounts it can store.

TODO: Implement a toString() method. The String should indicate the name of the bank and how many accounts it stores and how many maximum accounts it can currently store.

3. BankActions

Question: 3.1: In the space below, write down what actions should a bank support (i.e. what are the actions a bank should be able to do)?

Question: 3.2: Look at the file called Do the actions in the file align with what you wrote above?

3.2 Implementing BankActions

Now modify the line in where you declare the class so that it looks like this:

public class MyBank implements BankActions

Now compile

Question: 3.2.1: In the space below, write down the error message you see and what you think this means.

Now, lets add method stubs to our class. Question: 3.2.1: After adding method stubs, compile In the space below, write down if the error message no longer appears. If it does, why do you think its the case? If you are not sure, please reach out to your instructor or TAs.

Now, one by one begin implementing the methods. When implementing the methods in an interface, you are free to choose the implementation details as long as you obey the contract specified by the interface.

For example, this means that when you create a new account, you are free in your own bank to decide the initial balance. If you want to attract customers, you can give them more money than your competing bank.

Another example is that when you add a new account to the list of accounts, you are free to add the account to the begining of the list, the end of the list, the middle of the list - whereever you like! Next week we’ll learn about different drawbacks to this decision.


Wrap up

In today’s lab we covered interfaces and searching. You gained more practice working across multiple files and growing arrays!

Signing out

Before leaving, make sure your TA/instructor have signed you out of the lab. If you finish the lab early, you are free to go.