Skip to content

project done #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
79 changes: 79 additions & 0 deletions src/main/java/io/zipcoder/ParenChecker.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,83 @@
package io.zipcoder;

import java.util.Stack;

public class ParenChecker {
private Stack charStack;

public ParenChecker() {
this.charStack = new Stack<Character>();
}

public void add(String input) {
for (int i = 0; i < input.length(); i++) {
if (input.charAt(i) != 32) {
charStack.add(input.charAt(i));
}
}
}

public String getCharString() {
StringBuilder result = new StringBuilder();
result.append(charStack);
return result.toString();
}

public boolean isOpen() {
boolean result = true;
int openCount = 0;
int quoteCount = 0;
for (int i = 0; i < charStack.size(); i++) {
char input = charStack.get(i).toString().charAt(0);
switch (input) {
case '(':
openCount++;
break;
case ')':
openCount--;
break;
case '{':
openCount++;
break;
case '}':
openCount--;
break;
case '[':
openCount++;
break;
case ']':
openCount--;
break;
case '<':
openCount++;
break;
case '>':
openCount--;
break;
case 34:
if (quoteCount == 1) {
openCount--;
quoteCount--;
break;
}
openCount++;
quoteCount++;
break;
case 39:
if (quoteCount == 1) {
openCount--;
quoteCount--;
break;
}
openCount++;
quoteCount++;
break;
}
}
if (openCount == 0) {
result = false;
}
return result;
}

}
40 changes: 38 additions & 2 deletions src/main/java/io/zipcoder/WC.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Iterator;
import java.util.Scanner;
import java.util.*;

public class WC {
private Iterator<String> si;
private Map<String, Integer> wordsAndCounts = new LinkedHashMap<String, Integer>();

public WC(String fileName) {
try {
Expand All @@ -20,4 +20,40 @@ public WC(String fileName) {
public WC(Iterator<String> si) {
this.si = si;
}

public WC() {}

public void program(){
ArrayList<String> words = new ArrayList<String>();
do{
words.add(si.next());
}while(si.hasNext() == true);
fillTreeMap(words);
printInfo();
}

private void printInfo() {
for(Map.Entry entry : wordsAndCounts.entrySet()){
System.out.println(String.format("Word: %-20s | Occurrences: %s", entry.getKey().toString(), entry.getValue().toString()));
}
}

public void fillTreeMap(ArrayList words){
Collections.sort(words, Collections.reverseOrder());
for(Object element : words){
int occ = getOccurrences(element, words);
wordsAndCounts.put(element.toString(), occ);
}
}

public int getOccurrences(Object element, ArrayList words){
int wordCount = 0;
for(Object word : words){
if(word.equals(element)){
wordCount++;
}
}
return wordCount;
}

}
2 changes: 2 additions & 0 deletions src/main/resources/documentationDef.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a : the provision of documents in substantiation; also : documentary evidence
b : the use of historical documents : conformity to historical or objective facts : the provision of footnotes, appendices, or addenda referring to or containing documentary evidence
Empty file.
Loading