Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
Week 12: Homework 8 - Introductory Programming in Java Skip navigation Introductory Programming in Java ANU College of Engineering & Computer Science Search query Search ANU web, staff & maps Search COMP6700 Lectures Labs Assignments menu Search query Search ANU web, staff & maps Search Search COMP6700 labs Week 01: Welcome Week 02: Lab 1 Week 03: Lab 2 and HW 1 Week 04: Lab 3 and HW 2 Week 05: Drop-in Lab, HW 3 Week 06: Lab 4 and HW 4 Week 07: Mid-sem Exam Week 08: Free (Anzac Day) Week 09: Lab 5 and HW 5 Week 10: Lab 6 and HW 6 Week 11: Lab 7 and HW 7 Week 12: Lab 8 and HW 8 related sites Wattle Piazza Week 12: Homework 8 Functional Interfaces, Laziness and JavaFX Objectives To use functional composition technique and lazy evaluation to create an image processing utility. Note: this homework is based on exercises from Chapter 3 of “Java SE 8 for the Really Impatient” book by Cay Hortsmann which were modified a little. Preparations Review the notion of λ-expressions and functional interfaces using either F2 lectures slides, or Oracle’s Lambda Expressions tutorial, or one of the resources listed in F2, last slide (or anything useful you can find online, just don’t spread too wide and thing). Make sure that you have forked the GitLab repository and cloned the forked one your comp6700-2017 Gitlab repository (or more likely, if you have cloned it already, run git pull command to update it, either on the command line, or from an IDE if your are using one). Change into hw8 directory and find three Java source files and a JPEG image file — these will be the resource which you shall use in this homework: ColourFilter.java ImageDemo.java LatentImage.java amazing-trees.jpg Study the code of the ColourFilter.java program (including the commented out “alternative” lines 29,30 which can be executed instead of the “composed” transform, line 32), understand the meaning and the effect of the ColourFilter.compose(op1, op2) which returns a composition of two java.util.function.UnaryOperator objects, similar to two functions composition in Mathematics: y = f(x), z = g(y) → h = g o f,   h(x) = g(f(x)) The UnaryOperator interface consists of the abstract method T apply(T t). One obvious benefit of the image transformation composition is avoidance of intermediate image object(s). Multiple transformations can be first composed into one transformation, and then the original image is “broken into pixels”, and each is transformed in the final value, the pixels combined back into the transformed image and returned. Such “only once transforming” approach is known as lazy computation (a computation is defined and ready to be used, but its actual use is postponed until it is absolutely necessary). Next, study an alternative image processing which allows to combine multiple transformations. The client class ImageDemo.java makes use of the class LatentImage in the LatentImage.java file which contains a list of unary operator objects — pending operations — and the terminal operation (a method) toImage() which returns the result (an original image transformed in sequence by a number of colour operations). Part One Consider a transform(Image in, UnaryOperator f) method from the class ColourFilter, and add the ColourTransformer functional interface: @FunctionalInterface interface ColourTransformer { Color apply(int x, int y, Color colorAtXY); } to the class ColourFilter, and add another (overload name) static method Image transform(Image in, ColorTransformer f) which performs an image transforming operation similar to the method Image transform(Image in, UnaryOperator f) where the ColourTransformer interface object is used instead. Make use of the new method to add a 10 pixel wide gray frame replacing the pixels on the border of an image by calling it with the appropriate λ-expression in place of ColourTransformer interface object. Observe the effect of closure (what are the captured variables?) Ponder why did we need the distributed (which depends of pixel coordinate) colour filter to solve a problem like this. Part Two Using the insight from the Part One, enhance (add new methods) the LatentImage class to allow it perform blur operation in which every pixel colour value of the original is replaced by the average of itself and its eight neighbour pixels. Note, that such operations as blurring require the knowledge of pixels from the previous stages (which precedes blurring) and therefore cannot be done lazily. Assessment You will get up to two marks (one for each task), if you submit your work by pushing the local repository using git push command by 6pm Friday, 26 May 2017, in your GitLab repository following the instructions to be provided in the Git and GitLab. The code should be placed in the same hw8 directory where the original source and image files where located when your cloned your local repository for the first time. You can optionally (if the opportunity will exist) present your solution to tutor during the Week 12 labs. Updated:  14 Mar 2017/ Responsible Officer:  Head of School/ Page Contact:  Alexei Khorev Contact ANU Copyright Disclaimer Privacy Freedom of Information +61 2 6125 5111 The Australian National University, Canberra CRICOS Provider : 00120C ABN : 52 234 063 906 You appear to be using Internet Explorer 7, or have compatibility view turned on. Your browser is not supported by ANU web styles. » Learn how to fix this » Ignore this warning in future