From 499aec3490118b3e9d92264edcc4f8816c5f3abb Mon Sep 17 00:00:00 2001 From: amdegregorio Date: Wed, 30 Jan 2019 13:55:37 -0500 Subject: [PATCH] updates to simplify example --- .../java/com/baeldung/jar/Dimensioner.java | 27 ------------ .../java/com/baeldung/jar/JarExample.java | 24 +--------- .../main/java/com/baeldung/jar/Rectangle.java | 44 ------------------- 3 files changed, 1 insertion(+), 94 deletions(-) delete mode 100644 core-java/src/main/java/com/baeldung/jar/Dimensioner.java delete mode 100644 core-java/src/main/java/com/baeldung/jar/Rectangle.java diff --git a/core-java/src/main/java/com/baeldung/jar/Dimensioner.java b/core-java/src/main/java/com/baeldung/jar/Dimensioner.java deleted file mode 100644 index bc5cea4010..0000000000 --- a/core-java/src/main/java/com/baeldung/jar/Dimensioner.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.baeldung.jar; - -import java.io.BufferedReader; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.List; - -public class Dimensioner { - - public List loadFromFile(String dimensionFile) throws FileNotFoundException, IOException { - List rectangles = new ArrayList(); - try (BufferedReader br = new BufferedReader(new InputStreamReader(Dimensioner.class.getResourceAsStream(dimensionFile)))) { - String line; - while ((line = br.readLine()) != null) { - String[] dimensions = line.split(","); - if (dimensions.length == 2) { - Rectangle rectangle = new Rectangle(Integer.valueOf(dimensions[0]), Integer.valueOf(dimensions[1])); - rectangles.add(rectangle); - } - } - } - return rectangles; - } - -} diff --git a/core-java/src/main/java/com/baeldung/jar/JarExample.java b/core-java/src/main/java/com/baeldung/jar/JarExample.java index daa44025d5..5f33188adf 100644 --- a/core-java/src/main/java/com/baeldung/jar/JarExample.java +++ b/core-java/src/main/java/com/baeldung/jar/JarExample.java @@ -1,31 +1,9 @@ package com.baeldung.jar; -import java.io.IOException; -import java.util.List; - public class JarExample { - private static final String DIMENSION_FILE = "/dimensions.txt"; public static void main(String[] args) { - String inputType = System.getProperty("input"); - if (inputType != null && inputType.equalsIgnoreCase("file")) { - Dimensioner dimensioner = new Dimensioner(); - try { - List rectangles = dimensioner.loadFromFile(DIMENSION_FILE); - rectangles.forEach(rectangle -> { - rectangle.printArea(); - rectangle.printPerimeter(); - }); - } catch (IOException e) { - System.err.println("Exception loading dimensions"); - } - } else if (args.length > 0) { - int length = Integer.valueOf(args[0]); - int width = (args.length > 1) ? Integer.valueOf(args[1]) : Integer.valueOf(args[0]); - Rectangle rectangle = new Rectangle(length, width); - rectangle.printArea(); - rectangle.printPerimeter(); - } + System.out.println("Hello Baeldung Reader!"); } } diff --git a/core-java/src/main/java/com/baeldung/jar/Rectangle.java b/core-java/src/main/java/com/baeldung/jar/Rectangle.java deleted file mode 100644 index f2a174c819..0000000000 --- a/core-java/src/main/java/com/baeldung/jar/Rectangle.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.baeldung.jar; - -public class Rectangle { - private int length; - private int width; - - public Rectangle(int length, int width) { - this.length = length; - this.width = width; - } - - public int area() { - return length * width; - } - - public int perimeter() { - return (length * 2) + (width * 2); - } - - public void printArea() { - System.out.println("Area: " + area()); - } - - public void printPerimeter() { - System.out.println("Perimeter: " + perimeter()); - } - - public int getLength() { - return length; - } - - public void setLength(int length) { - this.length = length; - } - - public int getWidth() { - return width; - } - - public void setWidth(int width) { - this.width = width; - } - -}