Compare commits
No commits in common. "139528560ae6b4b68eae72b4f08902dcecef49ab" and "d52f770cf1add707e03c04cd7e58b7c3d5337514" have entirely different histories.
139528560a
...
d52f770cf1
23 changed files with 185 additions and 298 deletions
1
.envrc
1
.envrc
|
|
@ -1 +0,0 @@
|
||||||
use flake
|
|
||||||
6
.gitignore
vendored
6
.gitignore
vendored
|
|
@ -63,8 +63,4 @@ fabric.properties
|
||||||
.idea/httpRequests
|
.idea/httpRequests
|
||||||
|
|
||||||
# Android studio 3.1+ serialized cache file
|
# Android studio 3.1+ serialized cache file
|
||||||
.idea/caches/build_file_checksums.ser.direnv
|
.idea/caches/build_file_checksums.ser
|
||||||
|
|
||||||
.direnv/
|
|
||||||
|
|
||||||
*.class
|
|
||||||
27
flake.lock
generated
27
flake.lock
generated
|
|
@ -1,27 +0,0 @@
|
||||||
{
|
|
||||||
"nodes": {
|
|
||||||
"nixpkgs": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1753489912,
|
|
||||||
"narHash": "sha256-uDCFHeXdRIgJpYmtcUxGEsZ+hYlLPBhR83fdU+vbC1s=",
|
|
||||||
"owner": "nixos",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "13e8d35b7d6028b7198f8186bc0347c6abaa2701",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "nixos",
|
|
||||||
"ref": "nixos-25.05",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"root": {
|
|
||||||
"inputs": {
|
|
||||||
"nixpkgs": "nixpkgs"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"root": "root",
|
|
||||||
"version": 7
|
|
||||||
}
|
|
||||||
11
flake.nix
11
flake.nix
|
|
@ -1,11 +0,0 @@
|
||||||
{
|
|
||||||
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05";
|
|
||||||
outputs = {nixpkgs, ...}: let
|
|
||||||
system = "x86_64-linux";
|
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
|
||||||
in {
|
|
||||||
devShells.${system}.default = pkgs.mkShell {
|
|
||||||
nativeBuildInputs = [pkgs.jetbrains.idea-community-bin pkgs.jdk8];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
23
src/com/ing/zoo/Hippo.java
Normal file
23
src/com/ing/zoo/Hippo.java
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.ing.zoo;
|
||||||
|
|
||||||
|
public class Hippo {
|
||||||
|
public String name;
|
||||||
|
public String helloText;
|
||||||
|
public String eatText;
|
||||||
|
|
||||||
|
public Hippo()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sayHello()
|
||||||
|
{
|
||||||
|
helloText = "splash";
|
||||||
|
System.out.println(helloText);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void eatLeaves()
|
||||||
|
{
|
||||||
|
eatText = "munch munch lovely";
|
||||||
|
System.out.println(eatText);
|
||||||
|
}
|
||||||
|
}
|
||||||
23
src/com/ing/zoo/Lion.java
Normal file
23
src/com/ing/zoo/Lion.java
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.ing.zoo;
|
||||||
|
|
||||||
|
public class Lion {
|
||||||
|
public String name;
|
||||||
|
public String helloText;
|
||||||
|
public String eatText;
|
||||||
|
|
||||||
|
public Lion()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sayHello()
|
||||||
|
{
|
||||||
|
helloText = "roooaoaaaaar";
|
||||||
|
System.out.println(helloText);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void eatMeat()
|
||||||
|
{
|
||||||
|
eatText = "nomnomnom thx mate";
|
||||||
|
System.out.println(eatText);
|
||||||
|
}
|
||||||
|
}
|
||||||
47
src/com/ing/zoo/Pig.java
Normal file
47
src/com/ing/zoo/Pig.java
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
package com.ing.zoo;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class Pig {
|
||||||
|
public String name;
|
||||||
|
public String helloText;
|
||||||
|
public String eatText;
|
||||||
|
public String trick;
|
||||||
|
|
||||||
|
public Pig()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sayHello()
|
||||||
|
{
|
||||||
|
helloText = "splash";
|
||||||
|
System.out.println(helloText);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void eatLeaves()
|
||||||
|
{
|
||||||
|
eatText = "munch munch oink";
|
||||||
|
System.out.println(eatText);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void eatMeat()
|
||||||
|
{
|
||||||
|
eatText = "nomnomnom oink thx";
|
||||||
|
System.out.println(eatText);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void performTrick()
|
||||||
|
{
|
||||||
|
Random random = new Random();
|
||||||
|
int rnd = random.nextInt(2);
|
||||||
|
if(rnd == 0)
|
||||||
|
{
|
||||||
|
trick = "rolls in the mud";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
trick = "runs in circles";
|
||||||
|
}
|
||||||
|
System.out.println(trick);
|
||||||
|
}
|
||||||
|
}
|
||||||
41
src/com/ing/zoo/Tiger.java
Normal file
41
src/com/ing/zoo/Tiger.java
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
package com.ing.zoo;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class Tiger {
|
||||||
|
public String name;
|
||||||
|
public String helloText;
|
||||||
|
public String eatText;
|
||||||
|
public String trick;
|
||||||
|
|
||||||
|
public Tiger()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sayHello()
|
||||||
|
{
|
||||||
|
helloText = "rraaarww";
|
||||||
|
System.out.println(helloText);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void eatMeat()
|
||||||
|
{
|
||||||
|
eatText = "nomnomnom oink wubalubadubdub";
|
||||||
|
System.out.println(eatText);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void performTrick()
|
||||||
|
{
|
||||||
|
Random random = new Random();
|
||||||
|
int rnd = random.nextInt(2);
|
||||||
|
if(rnd == 0)
|
||||||
|
{
|
||||||
|
trick = "jumps in tree";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
trick = "scratches ears";
|
||||||
|
}
|
||||||
|
System.out.println(trick);
|
||||||
|
}
|
||||||
|
}
|
||||||
26
src/com/ing/zoo/Zebra.java
Normal file
26
src/com/ing/zoo/Zebra.java
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.ing.zoo;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class Zebra {
|
||||||
|
public String name;
|
||||||
|
public String helloText;
|
||||||
|
public String eatText;
|
||||||
|
public String trick;
|
||||||
|
|
||||||
|
public Zebra()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sayHello()
|
||||||
|
{
|
||||||
|
helloText = "zebra zebra";
|
||||||
|
System.out.println(helloText);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void eatLeaves()
|
||||||
|
{
|
||||||
|
eatText = "munch munch zank yee bra";
|
||||||
|
System.out.println(eatText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,66 +2,37 @@ package com.ing.zoo;
|
||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
import com.ing.zoo.animals.*;
|
|
||||||
import com.ing.zoo.base.*;
|
|
||||||
|
|
||||||
public class Zoo {
|
public class Zoo {
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
{
|
{
|
||||||
Animal[] animals = {
|
String[] commands = new String[4];
|
||||||
new Lion("henk"),
|
commands[0] = "hello";
|
||||||
new Pig("dora"),
|
commands[1] = "give leaves";
|
||||||
new Tiger("wally"),
|
commands[2] = "give meat";
|
||||||
new Zebra("marty"),
|
commands[3] = "perform trick";
|
||||||
new Fish("blubber"),
|
|
||||||
new Crab("ferris")
|
Lion henk = new Lion();
|
||||||
};
|
henk.name = "henk";
|
||||||
|
Hippo elsa = new Hippo();
|
||||||
|
elsa.name = "elsa";
|
||||||
|
Pig dora = new Pig();
|
||||||
|
dora.name = "dora";
|
||||||
|
Tiger wally = new Tiger();
|
||||||
|
wally.name = "wally";
|
||||||
|
Zebra marty = new Zebra();
|
||||||
|
marty.name = "marty";
|
||||||
|
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
System.out.print("Enter your command: ");
|
System.out.print("Voer uw command in: ");
|
||||||
|
|
||||||
String input = scanner.nextLine().trim();
|
String input = scanner.nextLine();
|
||||||
String[] splittedInput = input.split("\\s+");
|
if(input.equals(commands[0] + " henk"))
|
||||||
|
{
|
||||||
scanner.close(); // NOTE: You don't do this in the template for some reason; It's a resource leak.
|
henk.sayHello();
|
||||||
|
}
|
||||||
if (splittedInput.length == 0) {
|
else
|
||||||
System.out.println("Please provide an command.");
|
{
|
||||||
return;
|
System.out.println("Unknown command: " + input);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (splittedInput[0].equals("hello")) {
|
|
||||||
for (Animal animal : animals) {
|
|
||||||
if (splittedInput.length > 1 && animal.name.equals(splittedInput[1]))
|
|
||||||
animal.sayHello();
|
|
||||||
else if (splittedInput.length == 1) animal.sayHello();
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Animal animal : animals) {
|
|
||||||
switch (input) {
|
|
||||||
case "give leaves":
|
|
||||||
if (animal instanceof HerbivoreBehavior)
|
|
||||||
((HerbivoreBehavior) animal).eatLeaves();
|
|
||||||
|
|
||||||
break;
|
|
||||||
case "give meat":
|
|
||||||
if (animal instanceof CarnivoreBehavior)
|
|
||||||
((CarnivoreBehavior) animal).eatMeat();
|
|
||||||
|
|
||||||
break;
|
|
||||||
case "perform trick":
|
|
||||||
animal.performTrick();
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
System.err.println("Invalid command: " + input);
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
package com.ing.zoo.animals;
|
|
||||||
import com.ing.zoo.base.Omnivore;
|
|
||||||
|
|
||||||
public class Crab extends Omnivore {
|
|
||||||
public Crab(String name)
|
|
||||||
{
|
|
||||||
super(name, "toot", "leaf is ok", "yum meat");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
package com.ing.zoo.animals;
|
|
||||||
|
|
||||||
import com.ing.zoo.base.*;
|
|
||||||
import java.awt.Desktop; // INFO: cheated a bit, had to search for this one.
|
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
public class Fish extends Herbivore {
|
|
||||||
public Fish(String name) {
|
|
||||||
super(name, "hi blub", "blub yum");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void performTrick() {
|
|
||||||
try {
|
|
||||||
URI uri = new URI("https://jsw.tf");
|
|
||||||
Desktop desktop = Desktop.getDesktop();
|
|
||||||
desktop.browse(uri);
|
|
||||||
|
|
||||||
System.out.println("Blub, open browser, blub.");
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.err.println("Tried to open 'https://jsw.tf' in your browser, blub. I failed though, can you open it for me?");
|
|
||||||
System.err.println(e);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
package com.ing.zoo.animals;
|
|
||||||
|
|
||||||
import com.ing.zoo.base.Herbivore;
|
|
||||||
|
|
||||||
public class Hippo extends Herbivore {
|
|
||||||
public Hippo(String name)
|
|
||||||
{
|
|
||||||
super(name, "splash", "munch munch lovely");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
package com.ing.zoo.animals;
|
|
||||||
|
|
||||||
import com.ing.zoo.base.Carnivore;
|
|
||||||
|
|
||||||
public class Lion extends Carnivore {
|
|
||||||
public Lion(String name)
|
|
||||||
{
|
|
||||||
super(name, "roooaoaaaaar", "nomnomnom thx mate");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
package com.ing.zoo.animals;
|
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import com.ing.zoo.base.Omnivore;
|
|
||||||
|
|
||||||
public class Pig extends Omnivore {
|
|
||||||
public String trick;
|
|
||||||
|
|
||||||
public Pig(String name)
|
|
||||||
{
|
|
||||||
super(name, "splash", "munch munch oink", "nomnomnom oink thx");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void performTrick()
|
|
||||||
{
|
|
||||||
Random random = new Random();
|
|
||||||
int rnd = random.nextInt(2);
|
|
||||||
if(rnd == 0)
|
|
||||||
{
|
|
||||||
trick = "rolls in the mud";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
trick = "runs in circles";
|
|
||||||
}
|
|
||||||
System.out.println(trick);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
package com.ing.zoo.animals;
|
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import com.ing.zoo.base.Carnivore;
|
|
||||||
|
|
||||||
public class Tiger extends Carnivore {
|
|
||||||
public String trick;
|
|
||||||
|
|
||||||
public Tiger(String name)
|
|
||||||
{
|
|
||||||
super(name, "rraaarww", "nomnomnom oink wubalubadubdub");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void performTrick()
|
|
||||||
{
|
|
||||||
Random random = new Random();
|
|
||||||
int rnd = random.nextInt(2);
|
|
||||||
if(rnd == 0)
|
|
||||||
{
|
|
||||||
trick = "jumps in tree";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
trick = "scratches ears";
|
|
||||||
}
|
|
||||||
System.out.println(trick);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
package com.ing.zoo.animals;
|
|
||||||
|
|
||||||
import com.ing.zoo.base.Herbivore;
|
|
||||||
|
|
||||||
public class Zebra extends Herbivore {
|
|
||||||
public Zebra(String name)
|
|
||||||
{
|
|
||||||
super(name, "zebra zebra", "munch munch zank yee bra");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
package com.ing.zoo.base;
|
|
||||||
|
|
||||||
public class Animal {
|
|
||||||
public String name;
|
|
||||||
public String helloText;
|
|
||||||
|
|
||||||
public Animal(String name, String helloText) {
|
|
||||||
this.name = name;
|
|
||||||
this.helloText = helloText;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sayHello() {
|
|
||||||
System.out.println(this.helloText);
|
|
||||||
}
|
|
||||||
public void performTrick(){}
|
|
||||||
}
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
package com.ing.zoo.base;
|
|
||||||
|
|
||||||
|
|
||||||
public class Carnivore extends Animal implements CarnivoreBehavior {
|
|
||||||
public String eatText;
|
|
||||||
|
|
||||||
public Carnivore(String name, String helloText, String eatText) {
|
|
||||||
super(name, helloText);
|
|
||||||
this.eatText = eatText;
|
|
||||||
}
|
|
||||||
public void eatMeat() {
|
|
||||||
System.out.println(eatText);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
package com.ing.zoo.base;
|
|
||||||
|
|
||||||
public interface CarnivoreBehavior {
|
|
||||||
public void eatMeat();
|
|
||||||
}
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
package com.ing.zoo.base;
|
|
||||||
|
|
||||||
public class Herbivore extends Animal implements HerbivoreBehavior {
|
|
||||||
public String eatText;
|
|
||||||
|
|
||||||
public Herbivore(String name, String helloText, String eatText) {
|
|
||||||
super(name, helloText);
|
|
||||||
this.eatText = eatText;
|
|
||||||
}
|
|
||||||
public void eatLeaves() {
|
|
||||||
System.out.println(eatText);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
package com.ing.zoo.base;
|
|
||||||
|
|
||||||
public interface HerbivoreBehavior {
|
|
||||||
public void eatLeaves();
|
|
||||||
}
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
package com.ing.zoo.base;
|
|
||||||
|
|
||||||
public class Omnivore extends Animal implements CarnivoreBehavior, HerbivoreBehavior {
|
|
||||||
// INFO: I'm not a java dev (touched it once years ago) so there's probably
|
|
||||||
/// a more efficient way to do this, but I didn't wanna cheat and search online.
|
|
||||||
|
|
||||||
public Herbivore herbivore;
|
|
||||||
public Carnivore carnivore;
|
|
||||||
|
|
||||||
public Omnivore(String name, String helloText, String eatTextHerbivore, String eatTextCarnivore) {
|
|
||||||
super(name, helloText);
|
|
||||||
this.herbivore = new Herbivore(name, helloText, eatTextHerbivore);
|
|
||||||
this.carnivore = new Carnivore(name, helloText, eatTextCarnivore);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void eatLeaves() {
|
|
||||||
this.herbivore.eatLeaves();
|
|
||||||
}
|
|
||||||
public void eatMeat() {
|
|
||||||
this.carnivore.eatMeat();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Reference in a new issue