From dd15f0e7039ae4f554fdd21540e9d4313cfe179c Mon Sep 17 00:00:00 2001 From: Gino Bryja Date: Thu, 14 Feb 2019 18:27:10 -0500 Subject: [PATCH] ERROR statement in get_num() is buggy --- .idea/vcs.xml | 6 ++ .idea/workspace.xml | 21 ++-- .../github/book_folding_app/BookFolder.class | Bin 3338 -> 4303 bytes .../github/book_folding_app/BookFolder.java | 91 +++++++++++------- 4 files changed, 79 insertions(+), 39 deletions(-) create mode 100644 .idea/vcs.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index eee9a90..07c2c10 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,7 +1,10 @@ - + + + + + + + @@ -97,7 +105,7 @@ - + @@ -186,12 +194,13 @@ - - + + + diff --git a/out/production/BookApp/com/github/book_folding_app/BookFolder.class b/out/production/BookApp/com/github/book_folding_app/BookFolder.class index ddf623004f68d1e6d4e87d409040da7b9164989c..4bffb214a09ccc5a49cd00066b84cdad3749ac64 100644 GIT binary patch literal 4303 zcmb7I`F9i775>H=Te29l*cb<5lOfnd-Y|O-Ow5vE>eN7LV;mrj8A~H;K$=mc5lb3E z+NSBgH?$<7Eu^ix&;)2~Q%ETNwf!r4`d{R5LcjZFEQ>^()1HH7-g57K_xtYh#{Bcs zTXz6#!9U_KkdNZ!dK6HMqXvFGHlifcQ*oTe8Cg3kk5}aJ)firl;#?f7@S1F&kKuJ$ z|5^-RkK-G7BZ_av(S*EMc~eH;igWaB8GT0{-;LsXqWygl_<^kaFoqwA%#UT|Co%j~ zKY#xIeOdXLto%HNx8!{xhF{40moZ$F_uDbN6T`bAcS+{I()Zj2Wc2GOek03yd0f^I zb8=G?u9dSjG!CDzPFa0f%bn^Q^$U(W)vuv0V>?qBUxPNNq4u4^7+0!To~lsF7UYM6k!y7y0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{b&6APmh4-(r&s4jN{3zb>YW$|`g5n(er&#JlCx#$zE)L~f` zYn$bfgB!e8f3}zZ!H5OFyYVx9!K^&yUIkId;iI4;G1!$d;=BcA9M z)5-L>Hjz}5(OnGAYj4Jso%SMFeJ<7159#-WQtkL89QS36z!2@cPz?7eX{!b8!EohRmy z= min && num <= max) { + break; + } else { + System.out.format("ERROR: Input must be between %d and %d\n", min, max); + } + } + else { + System.out.println("ERROR: Input must be a number\n"); + } + } + return num; + } + // Determine cut distance(s) for a given page - ArrayList get_page_cuts(int[] arr, float min_cut_len, int tolerance, float px_height, float height) { + private ArrayList get_page_cuts(int[] arr) { ArrayList cuts = new ArrayList<>(); boolean start_cut = true; for (int i = 0; i < arr.length; i++) { @@ -51,7 +72,7 @@ ArrayList get_page_cuts(int[] arr, float min_cut_len, int tolerance, floa else if (arr[i] >= tolerance && !start_cut) { cuts.add((float)i); start_cut = true; - cuts = check_page_cuts(cuts, min_cut_len, px_height, height); + cuts = check_page_cuts(cuts); } } if (!start_cut) { @@ -61,7 +82,7 @@ else if (arr[i] >= tolerance && !start_cut) { } // Removes cut instructions if less than minimum cut length - ArrayList check_page_cuts(ArrayList cuts, float min_cut_len, float px_height, float height) { + private ArrayList check_page_cuts(ArrayList cuts) { int end = cuts.size() - 1; // if get_height if (cuts.get(end) - cuts.get(end - 1) < min_cut_len) { @@ -71,32 +92,36 @@ ArrayList check_page_cuts(ArrayList cuts, float min_cut_len, float return cuts; } - float get_height(float num, float px_height, float height) { + private float get_height(float num, float px_height, float height) { return num / px_height * height; } - public static void main(String[] args) { - Scanner scanner = new Scanner(System.in); - BookFolder bf = new BookFolder(); - bf.img_name = bf.get_str("\nEnter filename of image\n" + - " This image should be black--and-white only\n> ", scanner); - bf.height = bf.get_num("\nEnter page height in inches\n> ", scanner, 0, Float.MAX_VALUE); - bf.num_pages = bf.get_num("\nEnter number of pages in book\n" + + private void run() { + // Get dimensions from user input + img_name = get_str("\nEnter filename of image\n" + + " This image should be black--and-white only\n"); + height = get_num("\nEnter page height in inches\n", + 0, Float.MAX_VALUE); + num_pages = get_num("\nEnter number of pages in book\n" + " Numbered pages (with different numbers on front and back) will count as a single page\n" + - " Be sure to include non-numbered pages\n> ", scanner, 0, Float.MAX_VALUE); - - - + " Be sure to include non-numbered pages\n", 0, Float.MAX_VALUE); + offset_front = get_num("\nEnter number of pages to offset image from the front cover\n", + 0, num_pages); + offset_back = get_num("\nEnter number of pages to offset image from the back cover\n", + 0, num_pages); + min_cut_len = get_num("\nEnter the minimum cut length in inches for each page\n", + 0, height); + tolerance = get_num("\nInput a black-white pixel tolearnce (0 - 255)\n" + + " All values above this will not be considered part of the image\n", + (short)0, (short)255); + width = num_pages - offset_front - offset_back; + // 1 in : 96 px + px_height = height * 96; + } - /* - bf.tolerance = 2; - bf.min_cut_len = 0.2f; - int[] arr = {0, 5, 5, 5, 0, 0, 0, 0, 5, 5, 5, 5, 0, 5, 0, 5, 0, 0, 5}; - ArrayList cuts = bf.get_page_cuts(arr, bf.min_cut_len, bf.tolerance, 0, 0); - for (Float i : cuts){ - System.out.println(i); - } - */ + public static void main(String[] args) { + BookFolder bookFolder = new BookFolder(); + bookFolder.run(); } }