diff --git a/CrossPrinter.java b/CrossPrinter.java new file mode 100644 index 0000000..756cae9 --- /dev/null +++ b/CrossPrinter.java @@ -0,0 +1,50 @@ +/* + * TASK 3 + * archived at https://git.femboy.science/femsci/ppj/src/branch/task/3 + * by femsci + */ + +public class CrossPrinter { + + public CrossPrinter(int size) { + _size = size; + _ast = "*".repeat(_size); + _whi = " ".repeat(_size); + // 3n² chars + 3n of \n + _buf = new StringBuffer((int) Math.pow(size * 3, 2) + size * 3); + + fillBuffer(); + } + + // yes i'm a C# dev + private final int _size; + private final StringBuffer _buf; + // :3333 + private final CharSequence _whi; + private final CharSequence _ast; + + public StringBuffer getBuffer() { + return new StringBuffer(_buf); + } + + public void printToStdout() { + System.out.println(getBuffer().toString()); + } + + // populate the buffer + private void fillBuffer() { + fillTopBottom(); + fillCore(); + fillTopBottom(); + } + + // to fill upper and lower segments for strbuffer + private void fillTopBottom() { + _buf.append(String.format("%s%s%s\n", _whi, _ast, _whi).repeat(_size)); + } + + // fill the middle segment + private void fillCore() { + _buf.repeat(String.format("%s\n", _ast.toString().repeat(3)), _size); + } +} diff --git a/Meow.java b/Meow.java new file mode 100644 index 0000000..54f5dfa --- /dev/null +++ b/Meow.java @@ -0,0 +1,34 @@ +/* + * TASK 3 + * archived at https://git.femboy.science/femsci/ppj/src/branch/task/3 + * by femsci + */ + +public class Meow { + + // printing logic decoupled to CrossPrinter.java + + public static void main(String[] args) { + if (args.length == 0) { + System.err.println("No argument provided..."); + System.exit(2); + } + + int size = 0; + + try { + size = Integer.parseInt(args[0]); + + if (size <= 0) { + // short circuit + throw new Exception(); + } + } catch (Exception __) { + System.err.println("Invalid argument provided..."); + System.exit(1); + } + + var cross = new CrossPrinter(size); + cross.printToStdout(); + } +} diff --git a/README.md b/README.md index 78a26cb..17dff11 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # PPJ -This repository exists to archive PJATK tasks for the PPJ curriculum. +This branch contains the solution for the **3rd task**. Each task can be found under its **corresponding branch**: `task/n`. Example: `task/2`. + +[Go back to main](/femsci/ppj/src/branch/nya)