Compare commits
2 commits
Author | SHA1 | Date | |
---|---|---|---|
7c7b3604af | |||
3ffc40596a |
5 changed files with 99 additions and 14 deletions
16
README.md
16
README.md
|
@ -1,17 +1,5 @@
|
|||
# PPJ
|
||||
|
||||
This repository exists to archive PJATK tasks for the PPJ curriculum.
|
||||
This branch contains the solution for the **10th task**.
|
||||
|
||||
Each task can be found under its **corresponding branch**: `task/n`.
|
||||
|
||||
### Completed tasks:
|
||||
|
||||
- [Task 1](/femsci/ppj/src/branch/task/1)
|
||||
- [Task 2](/femsci/ppj/src/branch/task/2)
|
||||
- [Task 3](/femsci/ppj/src/branch/task/3)
|
||||
- [Task 4](/femsci/ppj/src/branch/task/4)
|
||||
- [Task 5](/femsci/ppj/src/branch/task/5)
|
||||
- [Task 6](/femsci/ppj/src/branch/task/6)
|
||||
- [Task 7](/femsci/ppj/src/branch/task/7)
|
||||
- [Task 8](/femsci/ppj/src/branch/task/8)
|
||||
- [Task 9](/femsci/ppj/src/branch/task/9)
|
||||
[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