task 10
This commit is contained in:
parent
3ffc40596a
commit
7c7b3604af
5 changed files with 98 additions and 1 deletions
|
@ -1,5 +1,5 @@
|
||||||
# PPJ
|
# PPJ
|
||||||
|
|
||||||
This branch contains the solution for the **nth task**.
|
This branch contains the solution for the **10th task**.
|
||||||
|
|
||||||
[Go back to main](/femsci/ppj/src/branch/nya)
|
[Go back to main](/femsci/ppj/src/branch/nya)
|
||||||
|
|
31
dev/pain/CalculatingDevice.java
Normal file
31
dev/pain/CalculatingDevice.java
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
22
dev/pain/Calculator.java
Normal file
22
dev/pain/Calculator.java
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
* TASK 10
|
||||||
|
* archived at https://git.femboy.science/femsci/ppj/src/branch/task/10
|
||||||
|
* by femsci
|
||||||
|
*/
|
||||||
|
|
||||||
|
package dev.pain;
|
||||||
|
|
||||||
|
public class Calculator extends CalculatingDevice {
|
||||||
|
|
||||||
|
public Calculator(String name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String calculate(double x, double y) {
|
||||||
|
// for the order of writing, stat and check mtime
|
||||||
|
// 1. wtf why reparse it ?????
|
||||||
|
// 2. oh ok just appending, still weird; meow~
|
||||||
|
return String.format("%s; %,.1f-%,.1f=%,.1f", super.calculate(x, y), x, y, x - y);
|
||||||
|
}
|
||||||
|
}
|
24
dev/pain/Computer.java
Normal file
24
dev/pain/Computer.java
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
* TASK 10
|
||||||
|
* archived at https://git.femboy.science/femsci/ppj/src/branch/task/10
|
||||||
|
* by femsci
|
||||||
|
*/
|
||||||
|
|
||||||
|
package dev.pain;
|
||||||
|
|
||||||
|
//uwuwuwuwuwuwu nested inheritance :3
|
||||||
|
public class Computer extends Calculator {
|
||||||
|
|
||||||
|
// i like composition and components >:3c
|
||||||
|
public Computer(String name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String calculate(double x, double y) {
|
||||||
|
|
||||||
|
return String.format("%s; %,.1f*%,.1f=%,.1f; %,.1f/%,.1f=%,.1f",
|
||||||
|
super.calculate(x, y),
|
||||||
|
x, y, x * y, x, y, x / y);
|
||||||
|
}
|
||||||
|
}
|
20
dev/pain/Computers.java
Normal file
20
dev/pain/Computers.java
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
/*
|
||||||
|
* TASK 10
|
||||||
|
* archived at https://git.femboy.science/femsci/ppj/src/branch/task/10
|
||||||
|
* by femsci
|
||||||
|
*/
|
||||||
|
|
||||||
|
package dev.pain;
|
||||||
|
|
||||||
|
public final class Computers {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
CalculatingDevice[] arr = {
|
||||||
|
new Computer("Cray"),
|
||||||
|
new CalculatingDevice("Abacus"),
|
||||||
|
new Calculator("HP")
|
||||||
|
};
|
||||||
|
|
||||||
|
CalculatingDevice.printRes(arr, 21, 7);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue