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
BankAccount
class that implements thePrintable
interface. 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
Shape
that implements thePrintable
interface. - Create a
Circle
class that extends theShape
class.- You must implement all the
Shape
methods. - You mush implement the
printToConsole()
method. - (For 1 Extra Point) implement the
printToFile()
method
- You must implement all the
- Create a
Rectangle
class that extends theShape
class.- You must implement all the
Shape
methods. - 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
printToConsole
method. - (For 4 Extra Points)
- Copy the
Filter
interface from the lab. - Create a
LargeShapesFilter
class that implements the Filter interface. Modify theaccept
implementation 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
Junit
to test the getters,deposit
andwithdraw
methods of theBankAccount
class.
Grading
- The program runs with no errors.
- Created and defined the Interface file.
- The
BankAccount
class includes all the fields and methods specified above. - The
BankAccount
class properly implements thePrintable
interface. - Used
Junit
to test the getters,deposit
andwithdraw
methods of theBankAccount
class. - (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.java
properly prints all instances of the classes. ApplicationRunner
properly 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)