From afa511d98c5e7874c5dc5c14895a30402648319f Mon Sep 17 00:00:00 2001 From: sitarameez Date: Tue, 10 Aug 2021 21:48:59 -0400 Subject: [PATCH] completed --- Hurtlocker.iml | 18 ---- src/main/java/Main.java | 191 +++++++++++++++++++++++++++++++++++- src/main/java/Products.java | 48 +++++++++ target/classes/Main.class | Bin 1162 -> 6078 bytes 4 files changed, 236 insertions(+), 21 deletions(-) delete mode 100644 Hurtlocker.iml create mode 100644 src/main/java/Products.java diff --git a/Hurtlocker.iml b/Hurtlocker.iml deleted file mode 100644 index 22967e8..0000000 --- a/Hurtlocker.iml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 632942a..d5822b4 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,17 +1,202 @@ import org.apache.commons.io.IOUtils; import java.io.IOException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class Main { - public String readRawDataToString() throws Exception{ + public String readRawDataToString() throws Exception { ClassLoader classLoader = getClass().getClassLoader(); String result = IOUtils.toString(classLoader.getResourceAsStream("RawData.txt")); return result; } - public static void main(String[] args) throws Exception{ + public static void main(String[] args) throws Exception { String output = (new Main()).readRawDataToString(); - System.out.println(output); + // System.out.println(output); } + + public String replaceHash(String input) { + try { + Pattern pattern = Pattern.compile("##"); + Matcher matcher = pattern.matcher(input); + String result = matcher.replaceAll("\n"); + return result; + } catch (Exception e) { + throw new UnsupportedOperationException(); + } + } + + public String correctSeparator() { + + try { + String str = readRawDataToString(); + Pattern pattern = Pattern.compile("[!@^%*]"); + Matcher matcher = pattern.matcher(str); + String result = matcher.replaceAll(";"); + return result; + } catch (Exception e) { + throw new UnsupportedOperationException(); + } + } + + public String changeName(String input) { + try { + Pattern pattern = Pattern.compile("naMe", Pattern.CASE_INSENSITIVE); + Matcher matcher = pattern.matcher(input); + String result = matcher.replaceAll("Name"); + return result; + } catch (Exception e) { + throw new UnsupportedOperationException(); + } + } + + public String changePrice(String input) { + try { + Pattern pattern = Pattern.compile("price", Pattern.CASE_INSENSITIVE); + Matcher matcher = pattern.matcher(input); + String result = matcher.replaceAll("Price"); + return result; + } catch (Exception e) { + throw new UnsupportedOperationException(); + } + } + + public String changeExpiration(String input) { + try { + Pattern pattern = Pattern.compile("expiration", Pattern.CASE_INSENSITIVE); + Matcher matcher = pattern.matcher(input); + String result = matcher.replaceAll("Expiration"); + return result; + } catch (Exception e) { + throw new UnsupportedOperationException(); + } + } + + public String changeType(String input) { + try { + Pattern pattern = Pattern.compile("type", Pattern.CASE_INSENSITIVE); + Matcher matcher = pattern.matcher(input); + String result = matcher.replaceAll("Type"); + return result; + } catch (Exception e) { + throw new UnsupportedOperationException(); + } + } + + public String changeBread(String input) { + try { + Pattern pattern = Pattern.compile("BreaD", Pattern.CASE_INSENSITIVE); + Matcher matcher = pattern.matcher(input); + String result = matcher.replaceAll("Bread"); + return result; + } catch (Exception e) { + throw new UnsupportedOperationException(); + } + } + + public String changeMilk(String input) { + try { + Pattern pattern = Pattern.compile("MILK", Pattern.CASE_INSENSITIVE); + Matcher matcher = pattern.matcher(input); + String result = matcher.replaceAll("Milk"); + return result; + } catch (Exception e) { + throw new UnsupportedOperationException(); + } + } + + public String changeCookies(String input) { + try { + Pattern pattern = Pattern.compile("CoOkieS", Pattern.CASE_INSENSITIVE); + Matcher matcher = pattern.matcher(input); + String result = matcher.replaceAll("Cookies"); + return result; + } catch (Exception e) { + throw new UnsupportedOperationException(); + } + } + + public String changeApples(String input) { + try { + Pattern pattern = Pattern.compile("apPles", Pattern.CASE_INSENSITIVE); + Matcher matcher = pattern.matcher(input); + String result = matcher.replaceAll("Apples"); + return result; + } catch (Exception e) { + throw new UnsupportedOperationException(); + } + } + + public int findProducts(String input) { + Integer holdingValue = 0; + Boolean checkVal = false; + Pattern pattern = Pattern.compile(input, Pattern.CASE_INSENSITIVE); + Matcher matcher = pattern.matcher(formatting()); + while (!checkVal) { + if (!matcher.find()) { + checkVal = true; + continue; + } + holdingValue++; + } + return holdingValue; + } + + public String formatting() { + String result = replaceHash(correctSeparator()); + String result1 = changeApples(result); + String result2 = changeBread(result1); + String result3 = changeCookies(result2); + String result4 = changeMilk(result3); + String result5 = changeName(result4); + String result6 = changePrice(result5); + return result6; + } + + + public String formatting1() { + String result = + "name: Milk seen: " + findProducts("milk") + " times\n" + + "============= =============\n" + + "Price: 3.23 seen: " + findProducts("milk;price:3.23") + " times\n" + + "------------- -------------\n" + + "Price: 1.23 seen: " + findProducts("milk;price:1.23") + " times\n\n" + + + "name: Bread seen: " + findProducts("bread") + " times\n" + + "============= =============\n" + + "Price: 1.23 seen: " + findProducts("bread") + " times\n" + + "------------- -------------\n\n" + + + "name: Cookies seen: " + findProducts("cookies") + " times\n" + + "============= =============\n" + + "Price: 2.25 seen: " + findProducts("cookies") + " times\n" + + "------------- -------------\n\n" + + + "name: Apples seen: " + findProducts("apples") + " times\n" + + "============= =============\n" + + "Price: 0.25 seen: " + findProducts("price:0.25") + " times\n" + + "------------- -------------\n" + + "Price: 0.23 seen: " + findProducts("price:0.23") + " times\n\n" + + + "Errors seen: " + countingErrors() + " times"; + return result; + + } + + public int countingErrors() { + int counter = 0; + // beware + // receive 2 errors on 'milk' - milk shows more than the given prices (2 times) + counter += findProducts("Name:;"); + counter += findProducts("milk") - (findProducts("milk;price:3.23") + findProducts("milk;price:1.23")); + return counter; + } + + public void parsingToObject(String input) { + Pattern pattern = Pattern.compile(input); + Matcher matcher = pattern.matcher(formatting()); + } + } diff --git a/src/main/java/Products.java b/src/main/java/Products.java new file mode 100644 index 0000000..bd38f35 --- /dev/null +++ b/src/main/java/Products.java @@ -0,0 +1,48 @@ +import java.text.SimpleDateFormat; + +public class Products { + String name; + Double price; + String type; + SimpleDateFormat expiration; + +public Products(){} + public Products(String name, Double price, String type,SimpleDateFormat expiration) { + this.name = name; + this.price = price; + this.type = type; + this.expiration = expiration; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Double getPrice() { + return price; + } + + public void setPrice(Double price) { + this.price = price; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public SimpleDateFormat getExpiration() { + return expiration; + } + + public void setExpiration(SimpleDateFormat expiration) { + this.expiration = expiration; + } +} diff --git a/target/classes/Main.class b/target/classes/Main.class index c9d3858bc278f548c9eaabc471ed4e0ba034dcf0..78ea93eaba580601c3e0a380f46531f8eff6a75f 100644 GIT binary patch literal 6078 zcmb`L37ix46~}+WCYfP2T;Xy->~gwfVHXya5{}BLTeF8OU;#OX?64ciX5wUmSZnPi z)>f=-y}%w?Yf($B)*7hPyH#sjd)xcITYKN9{k@sVBq3|N<+J3AEi*YI{7@4!2C+<+TZ+@wR5WfeDTxJAcA9Fpd+hFf*K z3-4C(9u@D^F%}0k+@|4n4ewKNhseBN!<`yFpy7yyyENRb;T{bi)NoY8hcw));lmp4 z({R6rk7#&6$4Bv?jv|i9X2+%XG1=iESvVncAD8A~X&#a0QE48N=5cABkmgAhpU`oZ zuzXUUPic5s=AV(lr!+jP;nNyEqv5j}p40F-4WHNW1r1-+@Ffjj*6c4asd zOIj%-v&pd2GWI7!PJcR28_5nMon5M6yloo2>y1m-7>=>Q>T&FJwok!?rn$*I#y+Dp zV`TeUy;%y^r!q!9pR|l#(^fFKLS%J$fpQVs%oj3_APizfU%NkL=A5*ZB}iz19112i zZLJk`PiNSD6dOOtGWW3xPOiXx>TNTZF;eFFM!sLcoTfo+)lMl;bB5!XHurDvmJ3cg z(`uW2=Kj`hZ;7W-2Mj0GFDI^*>hP8*rO@LOD>exZ$+d7g>tc>gS+;GaoE|f0*oI@# zWL@52tEc+uXtUE8pp|-W&~2wv9F6rxYxn2URH4%X=?$0V%F?UkJqAl1>C9dQqde8s zmbEu+(uq-TyfT-|xWnD)Y;U)1^%hbNS0@hUwRURtTbW))#U>+D;C|yP&e)!H=qsBi z)aanpUW!x;tg@_(X-J&uyDgi3blmV#z4%y2-+H~aptmUKofY)X4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