Compare commits
2 commits
Author | SHA1 | Date | |
---|---|---|---|
b47f222dec | |||
3ffc40596a |
5 changed files with 134 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 **9th 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)
|
||||
|
|
68
hai/hello/Car.java
Normal file
68
hai/hello/Car.java
Normal file
|
@ -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();
|
||||
}
|
||||
|
||||
/*
|
||||
* ⠀⢸⠂⠀⠀⠀⠘⣧⠀⠀⣟⠛⠲⢤⡀⠀⠀⣰⠏⠀⠀⠀⠀⠀⢹⡀
|
||||
* ⠀⡿⠀⠀⠀⠀⠀⠈⢷⡀⢻⡀⠀⠀⠙⢦⣰⠏⠀⠀⠀⠀⠀⠀⢸⠀
|
||||
* ⠀⡇⠀⠀⠀⠀⠀⠀⢀⣻⠞⠛⠀⠀⠀⠀⠻⠀⠀⠀⠀⠀⠀⠀⢸⠀
|
||||
* ⠀⡇⠀⠀⠀⠀⠀⠀⠛⠓⠒⠓⠓⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀
|
||||
* ⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⠀
|
||||
* ⠀⢿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣀⣀⠀⠀⢀⡟⠀
|
||||
* ⠀⠘⣇⠀⠘⣿⠋⢹⠛⣿⡇⠀⠀⠀⠀⣿⣿⡇⠀⢳⠉⠀⣠⡾⠁⠀
|
||||
* ⣦⣤⣽⣆⢀⡇⠀⢸⡇⣾⡇⠀⠀⠀⠀⣿⣿⡷⠀⢸⡇⠐⠛⠛⣿⠀
|
||||
* ⠹⣦⠀⠀⠸⡇⠀⠸⣿⡿⠁⢀⡀⠀⠀⠿⠿⠃⠀⢸⠇⠀⢀⡾⠁⠀
|
||||
* ⠀⠈⡿⢠⢶⣡⡄⠀⠀⠀⠀⠉⠁⠀⠀⠀⠀⠀⣴⣧⠆⠀⢻⡄⠀⠀
|
||||
* ⠀⢸⠃⠀⠘⠉⠀⠀⠀⠠⣄⡴⠲⠶⠴⠃⠀⠀⠀⠉⡀⠀⠀⢻⡄⠀
|
||||
* ⠀⠘⠒⠒⠻⢦⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣤⠞⠛⠒⠛⠋⠁⠀
|
||||
* ⠀⠀⠀⠀⠀⠀⠸⣟⠓⠒⠂⠀⠀⠀⠀⠀⠈⢷⡀⠀⠀⠀⠀⠀⠀⠀
|
||||
* ⠀⠀⠀⠀⠀⠀⠀⠙⣦⠀⠀⠀⠀⠀⠀⠀⠀⠈⢷⠀⠀⠀⠀⠀⠀⠀
|
||||
* ⠀⠀⠀⠀⠀⠀⠀⣼⣃⡀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣆⠀⠀⠀⠀⠀⠀
|
||||
* ⠀⠀⠀⠀⠀⠀⠀⠉⣹⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⠀⠀⠀⠀⠀⠀
|
||||
* ⠀⠀⠀⠀⠀⠀⠀⠀⡿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡆⠀⠀⠀⠀⠀
|
||||
*/
|
||||
}
|
21
hai/hello/ExplosionException.java
Normal file
21
hai/hello/ExplosionException.java
Normal file
|
@ -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));
|
||||
}
|
||||
}
|
23
hai/hello/Kotauki.java
Normal file
23
hai/hello/Kotauki.java
Normal file
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
20
hai/hello/NotEnoughGasException.java
Normal file
20
hai/hello/NotEnoughGasException.java
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue