31 lines
749 B
Java
31 lines
749 B
Java
/*
|
|
* TASK 10
|
|
* archived at https://git.femboy.science/femsci/ppj/src/branch/task/10
|
|
* by femsci
|
|
*/
|
|
|
|
package dev.pain;
|
|
|
|
import java.util.Arrays;
|
|
|
|
public class CalculatingDevice {
|
|
|
|
public CalculatingDevice(String name) {
|
|
this.name = name;
|
|
}
|
|
|
|
private final String name;
|
|
|
|
public String calculate(double x, double y) {
|
|
return String.format("%s: %,.1f+%,.1f=%,.1f", this.name, x, y, x + y);
|
|
}
|
|
|
|
public static void printRes(CalculatingDevice[] devs, double x, double y) {
|
|
// can also do direct .forEach(sout(d.calc)) but this one is cuter to look at
|
|
Arrays.asList(devs)
|
|
.stream()
|
|
.map(d -> d.calculate(x, y))
|
|
.forEach(System.out::println);
|
|
}
|
|
|
|
}
|