diff --git a/README.md b/README.md index a4b6575..13569a2 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # PPJ -This branch contains the solution for the **nth task**. +This branch contains the solution for the **9th task**. [Go back to main](/femsci/ppj/src/branch/nya) diff --git a/hai/hello/Car.java b/hai/hello/Car.java new file mode 100644 index 0000000..718eea1 --- /dev/null +++ b/hai/hello/Car.java @@ -0,0 +1,68 @@ +/* + * TASK 9 + * archived at https://git.femboy.science/femsci/ppj/src/branch/task/9 + * by femsci + */ + +package hai.hello; + +import java.util.concurrent.ThreadLocalRandom; + +// meow~ +public class Car { + int fuel = 35, odometer = 0; + + public void printFuelLevel() { + System.out.printf("after filling: %dL >.<\n", this.fuel); + } + + public void printStats() { + System.out.printf("%dkm driven, %dl left\n", this.odometer, this.fuel); + } + + public void fill() // >.< + { + ThreadLocalRandom r = ThreadLocalRandom.current(); + if (r.nextInt(100) < 10) { + throw new ExplosionException(this); + } + + this.fuel += r.nextInt(15, 36); + printFuelLevel(); + } + + // linear funky wunky? + // public void drive(int distance) throws NotEnoughGasException { + // } + + public void drive100km() throws NotEnoughGasException { + if (this.fuel < 10) { + throw new NotEnoughGasException(this); + } + + this.fuel -= 10; + this.odometer += 100; + + printStats(); + } + + /* + * ⠀⢸⠂⠀⠀⠀⠘⣧⠀⠀⣟⠛⠲⢤⡀⠀⠀⣰⠏⠀⠀⠀⠀⠀⢹⡀ + * ⠀⡿⠀⠀⠀⠀⠀⠈⢷⡀⢻⡀⠀⠀⠙⢦⣰⠏⠀⠀⠀⠀⠀⠀⢸⠀ + * ⠀⡇⠀⠀⠀⠀⠀⠀⢀⣻⠞⠛⠀⠀⠀⠀⠻⠀⠀⠀⠀⠀⠀⠀⢸⠀ + * ⠀⡇⠀⠀⠀⠀⠀⠀⠛⠓⠒⠓⠓⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀ + * ⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⠀ + * ⠀⢿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣀⣀⠀⠀⢀⡟⠀ + * ⠀⠘⣇⠀⠘⣿⠋⢹⠛⣿⡇⠀⠀⠀⠀⣿⣿⡇⠀⢳⠉⠀⣠⡾⠁⠀ + * ⣦⣤⣽⣆⢀⡇⠀⢸⡇⣾⡇⠀⠀⠀⠀⣿⣿⡷⠀⢸⡇⠐⠛⠛⣿⠀ + * ⠹⣦⠀⠀⠸⡇⠀⠸⣿⡿⠁⢀⡀⠀⠀⠿⠿⠃⠀⢸⠇⠀⢀⡾⠁⠀ + * ⠀⠈⡿⢠⢶⣡⡄⠀⠀⠀⠀⠉⠁⠀⠀⠀⠀⠀⣴⣧⠆⠀⢻⡄⠀⠀ + * ⠀⢸⠃⠀⠘⠉⠀⠀⠀⠠⣄⡴⠲⠶⠴⠃⠀⠀⠀⠉⡀⠀⠀⢻⡄⠀ + * ⠀⠘⠒⠒⠻⢦⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣤⠞⠛⠒⠛⠋⠁⠀ + * ⠀⠀⠀⠀⠀⠀⠸⣟⠓⠒⠂⠀⠀⠀⠀⠀⠈⢷⡀⠀⠀⠀⠀⠀⠀⠀ + * ⠀⠀⠀⠀⠀⠀⠀⠙⣦⠀⠀⠀⠀⠀⠀⠀⠀⠈⢷⠀⠀⠀⠀⠀⠀⠀ + * ⠀⠀⠀⠀⠀⠀⠀⣼⣃⡀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣆⠀⠀⠀⠀⠀⠀ + * ⠀⠀⠀⠀⠀⠀⠀⠉⣹⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⠀⠀⠀⠀⠀⠀ + * ⠀⠀⠀⠀⠀⠀⠀⠀⡿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡆⠀⠀⠀⠀⠀ + */ +} diff --git a/hai/hello/ExplosionException.java b/hai/hello/ExplosionException.java new file mode 100644 index 0000000..6099351 --- /dev/null +++ b/hai/hello/ExplosionException.java @@ -0,0 +1,21 @@ +/* + * TASK 9 + * archived at https://git.femboy.science/femsci/ppj/src/branch/task/9 + * by femsci + */ + +package hai.hello; + +// pentaerythritol tetranitrate was detected in during subsequent spectrometric analysis +public class ExplosionException extends RuntimeException { + public ExplosionException(Car c) { + car = c; + } + + private final Car car; + + @Override + public String getMessage() { + return String.format("hai hello your car (%s) exploded >:3c", System.identityHashCode(car)); + } +} diff --git a/hai/hello/Kotauki.java b/hai/hello/Kotauki.java new file mode 100644 index 0000000..4860ad0 --- /dev/null +++ b/hai/hello/Kotauki.java @@ -0,0 +1,23 @@ +/* + * TASK 9 + * archived at https://git.femboy.science/femsci/ppj/src/branch/task/9 + * by femsci + */ + +package hai.hello; + +// meow meow~ +public class Kotauki { + public static void main(String[] args) { + Car kitten = new Car(); // kitty car :3 + + while (true) { + try { + kitten.drive100km(); + } catch (NotEnoughGasException ex) { + System.err.println(ex.getMessage()); + kitten.fill(); + } + } + } +} diff --git a/hai/hello/NotEnoughGasException.java b/hai/hello/NotEnoughGasException.java new file mode 100644 index 0000000..8f827e1 --- /dev/null +++ b/hai/hello/NotEnoughGasException.java @@ -0,0 +1,20 @@ +/* + * TASK 9 + * archived at https://git.femboy.science/femsci/ppj/src/branch/task/9 + * by femsci + */ + +package hai.hello; + +public class NotEnoughGasException extends Exception { + public NotEnoughGasException(Car c) { + car = c; + } + + private final Car car; + + @Override + public String getMessage() { + return String.format("not enough gas: %dl left", car.fuel); + } +}