Compare commits

...

2 commits
nya ... task/10

Author SHA1 Message Date
7c7b3604af
task 10 2024-06-24 23:29:41 +02:00
3ffc40596a
skele 2024-03-28 19:25:56 +01:00
5 changed files with 99 additions and 3 deletions

View file

@ -1,6 +1,5 @@
# PPJ # 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`. [Go back to main](/femsci/ppj/src/branch/nya)
Example: `task/2`.

View 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
View 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
View 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
View 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);
}
}