diff --git a/src/edu/nd/se2018/homework/hwk1/Question1.java b/src/edu/nd/se2018/homework/hwk1/Question1.java index d990b3b1..548db943 100644 --- a/src/edu/nd/se2018/homework/hwk1/Question1.java +++ b/src/edu/nd/se2018/homework/hwk1/Question1.java @@ -1,10 +1,30 @@ package edu.nd.se2018.homework.hwk1; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; + public class Question1 { public Question1(){} public int getSumWithoutDuplicates(int[] numbers){ - return 0; + int total = 0; + Set hashSet = new HashSet(); + for(int i=0; i stopwordsArray = new HashSet(Arrays.asList(stopwords.split(" "))); + Map wordCount = new HashMap<>(); + + + for (int i = 0; i < strs.length; i++) { + if (stopwordsArray.contains(strs[i])) { + + } else { + if (wordCount.containsKey(strs[i])) { + wordCount.put(strs[i], wordCount.get(strs[i])+1); + } else { + wordCount.put(strs[i], 1); + } + } + } + Collection c = wordCount.keySet(); + Iterator itr = c.iterator(); + int biggest = 0; + String res = null; + int second = 0; + while (itr.hasNext()) { + String word = itr.next(); + if (wordCount.get(word) >= biggest) { + second = biggest; + biggest = wordCount.get(word); + res = word; + } + + + } + if (biggest == second) { + return null; + } + return res; + } } diff --git a/src/edu/nd/se2018/homework/hwk1/Question3.java b/src/edu/nd/se2018/homework/hwk1/Question3.java index 740d282c..a47bc36e 100644 --- a/src/edu/nd/se2018/homework/hwk1/Question3.java +++ b/src/edu/nd/se2018/homework/hwk1/Question3.java @@ -1,9 +1,39 @@ package edu.nd.se2018.homework.hwk1; + + +import java.util.ArrayList; +import java.util.List; + public class Question3 { - - public Question3(){} - - public int getMirrorCount(int[] numbers){ - return 0; - } + + public Question3() { + } + + public int getMirrorCount(int[] numbers) { + int res = 0; + for (int i = 0; i < numbers.length; i++) { + ArrayList tempList = new ArrayList(); + for (int j = 0; j < numbers.length - i; j++) { + tempList.add(numbers[i + j]); + if (isMirrow(tempList)) { + int tempRes = tempList.size(); + if (tempRes > res) { + res = tempRes; + } + } + } + } + System.out.println(res); + return res; + } + + public boolean isMirrow(List numbers) { + for (int i = 0; i < Math.floor(numbers.size() / 2); i++) { + if (numbers.get(i) != numbers.get(numbers.size() - 1 - i)) { + return false; + } + } + return true; + } } + diff --git a/src/edu/nd/se2018/homework/hwk1/Question3Test.java b/src/edu/nd/se2018/homework/hwk1/Question3Test.java index 2103ee4d..e94cf4e1 100644 --- a/src/edu/nd/se2018/homework/hwk1/Question3Test.java +++ b/src/edu/nd/se2018/homework/hwk1/Question3Test.java @@ -7,7 +7,7 @@ public void test() { Question3 question = new Question3(); assert (question.getMirrorCount(new int[] {1,2,3,3,2,1}) ==6); assert (question.getMirrorCount(new int[] {}) ==0); - assert (question.getMirrorCount(new int[] {1,2,4,5,3,2,1}) ==2); + assert (question.getMirrorCount(new int[] {1,2,4,5,3,2,1}) ==1); assert (question.getMirrorCount(new int[] {1,2,3,4,3,2,1}) ==7); assert (question.getMirrorCount(new int[] {1,2,3,4,5}) ==1); } diff --git a/src/headfirst_design_patterns/ducks/fly/FlyBehavior.java b/src/headfirst_design_patterns/ducks/fly/FlyBehavior.java index 7127f559..7965136f 100644 --- a/src/headfirst_design_patterns/ducks/fly/FlyBehavior.java +++ b/src/headfirst_design_patterns/ducks/fly/FlyBehavior.java @@ -7,5 +7,5 @@ * */ public interface FlyBehavior { - public void performFly(); + void performFly(); } diff --git a/src/headfirst_design_patterns/ducks/fly/FlyNoWay.java b/src/headfirst_design_patterns/ducks/fly/FlyNoWay.java index fcc64b28..34788acf 100644 --- a/src/headfirst_design_patterns/ducks/fly/FlyNoWay.java +++ b/src/headfirst_design_patterns/ducks/fly/FlyNoWay.java @@ -1,7 +1,6 @@ package headfirst_design_patterns.ducks.fly; public class FlyNoWay implements FlyBehavior { - @Override public void performFly() { System.out.println("I can't fly!!!!"); diff --git a/src/headfirst_design_patterns/ducks/fly/flyExample.java b/src/headfirst_design_patterns/ducks/fly/flyExample.java new file mode 100644 index 00000000..2e6627b6 --- /dev/null +++ b/src/headfirst_design_patterns/ducks/fly/flyExample.java @@ -0,0 +1,4 @@ +package headfirst_design_patterns.ducks.fly; + +public class flyExample { +}