Assignment 4 - Printable Interface
Table of contents
Lab Goals:
- Practise using interfaces.
- Practise using predicate-based interfaces.
- Create a callback interface.
- Create Abstract Classes.
Final Result:
You will be submitting a git repository with the following naming convention, 4-printable-interface-<your-github-username>, (i.e., 4-filter-interface-Ygilany). The repository contains:
- one Java Project with the following files:
- Printable.java (interface file)
- Shape.java (abstract class)
- Circle.java (inherits from
Shape) - Square.java (inherits from
Shape) - BankAccount.java (implements
Printable) - ApplicationRunner.java (has a main method)
- a modified README.md file that includes your self-assessment
Instructions
- Create an interface as follows.
public interface Printable { void printToConsole(Object x); void printToFile(Object x); } - Create a simple
BankAccountclass that implements thePrintableinterface. a. You mush implement theprintToConsole()method.
| Bank Account | ||
|---|---|---|
| Fields | ||
double balance; | ||
String accountNumber; | ||
| Methods | ||
| Constructor | Sets all properties | |
| Getters | Yes, No setters. | |
public void deposit(double amount) | ||
public void withdraw(double amount) |
- Create a simple abstract class
Shapethat implements thePrintableinterface. - Create a
Circleclass that extends theShapeclass.- You must implement all the
Shapemethods. - You mush implement the
printToConsole()method. - (For 1 Extra Point) implement the
printToFile()method
- You must implement all the
- Create a
Rectangleclass that extends theShapeclass.- You must implement all the
Shapemethods. - You mush implement the
printToConsole()method. - (For the same 1 Extra Point) implement the
printToFile()method
- You must implement all the

- In the
ApplicationRunner.java, create at least 1 instance of each instantiatable class. - Add all objects to an
ArrayList<...>. What type of ArrayList should this be? - Loop over all the objects and call the
printToConsolemethod. - (For 4 Extra Points)
- Copy the
Filterinterface from the lab. - Create a
LargeShapesFilterclass that implements the Filter interface. Modify theacceptimplementation so it accepts any shape with an area of 50 units and above. - in the ApplicationRunner, make sure you have multiple shapes of different sizes, filter out all the large ones and print them to console.
- Copy the
- Used
Junitto test the getters,depositandwithdrawmethods of theBankAccountclass.
Grading
- The program runs with no errors.
- Created and defined the Interface file.
- The
BankAccountclass includes all the fields and methods specified above. - The
BankAccountclass properly implements thePrintableinterface. - Used
Junitto test the getters,depositandwithdrawmethods of theBankAccountclass. - (For 1 Extra Point) implement the
printToFile()method for (BankAccount, Circle, and Rectangle Classes) - Created a proper ArrayList to house all the different printable objects.
- The
ApplicationRunner.javaproperly prints all instances of the classes. ApplicationRunnerproperly utilizes the static helper method to filter the arraylist of shapes.- (For 4 Extra Points) Proper implementation and usgae of the Filter interface.
- Proper usage of Git and GitHub (frequent commits, explanatory commit messages)