From 35deba7bd1c70358be74d94885ca6a7891630991 Mon Sep 17 00:00:00 2001 From: Juuso Rytilahti <juuso.b.rytilahti@utu.fi> Date: Thu, 30 May 2024 13:24:51 +0000 Subject: [PATCH] updated exercise 2 and unified prints --- Exercise1/Exercise1.java | 2 +- Exercise2/Exercise2.java | 10 +++++----- Exercise2/TestZipper.java | 40 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 Exercise2/TestZipper.java diff --git a/Exercise1/Exercise1.java b/Exercise1/Exercise1.java index 36deaa1..a6a8c66 100644 --- a/Exercise1/Exercise1.java +++ b/Exercise1/Exercise1.java @@ -9,7 +9,7 @@ public class Exercise1 { try (var zipper = new TestZipper("books.zip")) { zipper.run(); } catch (IOException e) { - System.err.println("A failure occurred"); + System.err.println("Execution failed!"); e.printStackTrace(); } } diff --git a/Exercise2/Exercise2.java b/Exercise2/Exercise2.java index 7cd408a..c91e8f2 100644 --- a/Exercise2/Exercise2.java +++ b/Exercise2/Exercise2.java @@ -1,15 +1,15 @@ -package fi.utu.tech.ooj.exercise2.teht2; +package fi.utu.tech.ooj.exercise4.exercise2; import java.io.IOException; -public class Teht2 { - public Teht2() { - System.out.println("Tehtävä 2"); +public class Exercise2 { + public Exercise2() { + System.out.println("Exercise 2"); try (var zipper = new TestZipper2("books.zip")) { zipper.run(); } catch (IOException e) { - System.err.println("Ajo epäonnistui!"); + System.err.println("Execution failed!"); e.printStackTrace(); } } diff --git a/Exercise2/TestZipper.java b/Exercise2/TestZipper.java new file mode 100644 index 0000000..a0a4766 --- /dev/null +++ b/Exercise2/TestZipper.java @@ -0,0 +1,40 @@ +package fi.utu.tech.ooj.exercise4.exercise2; + +import fi.utu.tech.ooj.exercise4.exercise1.Zipper; + +import java.io.IOException; +import java.nio.file.Path; + +class Book { +} + +class TestZipper2 extends Zipper { + Book[] books = new Book[100]; + int idx = 0; + + TestZipper2(String zipFile) throws IOException { + super(zipFile); + } + + @Override + public void run() throws IOException { + super.run(); + + System.out.printf(""" + + Handled %d Books. + Now we could sort it out a bit. + + """, idx); + } + + @Override + protected Handler createHandler(Path file) { + return new Handler(file) { + @Override + public void handle() { + books[idx++] = new Book(); + } + }; + } +} -- GitLab