Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/edu/nd/se2018/homework/hwk1/Question1.java
Original file line number Diff line number Diff line change
@@ -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<Integer> hashSet = new HashSet();
for(int i=0; i<numbers.length; i++){
hashSet.add(numbers[i]);
}
for(int i:hashSet){
total += i;
}
return total;
}
/*
public static void main(String[] args){
int[] numbers= {1,2,3,2};
Question1 question1 = new Question1();
int res = question1.getSumWithoutDuplicates(numbers);
System.out.println(res);

}*/
}
47 changes: 42 additions & 5 deletions src/edu/nd/se2018/homework/hwk1/Question2.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,47 @@
package edu.nd.se2018.homework.hwk1;

import java.util.*;

public class Question2 {

public Question2(){}

public String getMostFrequentWord(String input, String stopwords){
return "";
}
public Question2() {
}

public String getMostFrequentWord(String input, String stopwords) {
String[] strs = input.split(" ");
Set<String> stopwordsArray = new HashSet(Arrays.asList(stopwords.split(" ")));
Map<String, Integer> 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<String> 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;
}
}
42 changes: 36 additions & 6 deletions src/edu/nd/se2018/homework/hwk1/Question3.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

2 changes: 1 addition & 1 deletion src/edu/nd/se2018/homework/hwk1/Question3Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/headfirst_design_patterns/ducks/fly/FlyBehavior.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
*
*/
public interface FlyBehavior {
public void performFly();
void performFly();
}
1 change: 0 additions & 1 deletion src/headfirst_design_patterns/ducks/fly/FlyNoWay.java
Original file line number Diff line number Diff line change
@@ -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!!!!");
Expand Down
4 changes: 4 additions & 0 deletions src/headfirst_design_patterns/ducks/fly/flyExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package headfirst_design_patterns.ducks.fly;

public class flyExample {
}