This activity is designed to give you practice making use of anonymous classes and lambda expressions. By the end of this activity, you should be able to create new instances of objects 1) using a traditional named class, 2) using an anonymous class, and 3) using a lambda expression.
Table of Contents
- Setup Lambda Activity
- Creating a Simple Makefile
- Implementing Object Instantiation
- Submit Work
1. Setup Lambda Activity
- Run the
cs400 get command, and choose A07.Lambda from the menu to download a folder named A07.Lambda containing the starter files for this assignment.
- Navigate into the folder that you just downloaded to complete this activity. While doing so, please ignore and leave intact the hidden files and folders (with names starting with a period) in this directory. They are used to track your progress and enable you to submit your work at the end of this assignment.
2. Creating a Simple Makefile
- Create a Makefile within your A07.Lambda folder with two rules: the first rule should use the target “run” and should run the provided CalculatorApp program. And the second rule should compile the provided CalculatorApp.java project into a .class file. Because of this the first rule should include a dependency on the second rule, so that the .class file is only generated or updated as needed.
- When you compile and run this project, you should see a table with a bunch of dashes in place of the sum, difference, and product of the pair of numbers in each row.
3. Implementing Object Instantiation
- There are three static methods inside CalculatorApp.java that each contain TODO comments. Follow these instructions to update the return value of each method. You are not required to add any additional comments beyond those that are provided. Do not make changes to the main method.
- Ensure that your code compile and runs, and prints out a table of sums, differences, and products, rather than the dashes that you saw before. Also, double check your source code to ensure that each of the three MathOperation objects that you are returning are instantiated according to the requirements described in the provided TODO comments.
4. Submit Work
- Run the
cs400 submit command from directly within the A07.Lambda folder.
- Check whether your submission successfully transferred to gitlab and also whether it passed our pre-grading correctness scans by running the cs400 script with the check argument as follows:
cs400 check. You may need to wait a minute or two before the scan finishes to get the feedback you are interested in from his command.
- Another way that you can check the contents of your most recent submission is to log into DoIT’s Gitlab instance using the UW-Madison NetID button near the bottom of this page. Once logged in, you can navigate to your A07.Lambda project to review the contents of the files and folders within your most recent submission.