Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

package pa1; import edu.princeton.cs.algs4.In; import edu.princeton.cs.algs4.StdOut; import edu.princeton.cs.algs4.ST; import edu.princeton.cs.algs4.SeparateChainingHashST; import edu.princeton.cs.algs4.LinearProbingHashST; import edu.princeton.cs.algs4.SequentialSearchST; import java.util.Dictionary; import static javax.swing.UIManager.get; public class TestPerf { // this

package pa1; import edu.princeton.cs.algs4.In; import edu.princeton.cs.algs4.StdOut; import edu.princeton.cs.algs4.ST; import edu.princeton.cs.algs4.SeparateChainingHashST; import edu.princeton.cs.algs4.LinearProbingHashST; import edu.princeton.cs.algs4.SequentialSearchST;

import java.util.Dictionary;

import static javax.swing.UIManager.get; public class TestPerf { // this is used to read a file and build table private ST lh; private SeparateChainingHashST ch; private LinearProbingHashST sc; private SequentialSearchST lp; private ST st; private long timer, sth, sths, Sequential;

public TestPerf() { lh = new ST<>(); ch = new SeparateChainingHashST<>(); lp = new SequentialSearchST(); sc = new LinearProbingHashST(); }

// this is used to read a file and build table public static long LinearProbingHashST(String x[]) { var st = new LinearProbingHashST(); long start = System.currentTimeMillis(); for (int i = 0; i < x.length; i++) { String key = x[i]; if (!st.contains(key)) st.put(key, 1); else st.put(key, st.get((key) + 1)); } long finish = System.currentTimeMillis(); return (finish - start); } public static long SeparateChainingHashST(String x[]) { var st = new SeparateChainingHashST(); long start = System.currentTimeMillis(); for (int i = 0; i < x.length; i++) { String key = x[i]; if (!st.contains(key)) st.put(key, 1); else st.put(key, st.get((key) + 1)); } long finish = System.currentTimeMillis(); return (finish - start); }

public static long ST(String x[]) { var st = new ST(); long start = System.currentTimeMillis(); for (int i = 0; i < x.length; i++) { String key = x[i]; if (!st.contains(key)) st.put(key, 1); else st.put(key, st.get((key) + 1)); } long finish = System.currentTimeMillis(); return (finish - start); } public static long SequentialSearchST(String x[]) { var st = new SequentialSearchST(); long start = System.currentTimeMillis(); for (int i = 0; i < x.length; i++) { String key = x[i]; if (!st.contains(key)) st.put(key, 1); else st.put(key, st.get((key) + 1)); } long finish = System.currentTimeMillis(); return (finish - start); }

public TestPerf(String filename) { In in = new In(filename); st = new ST(); while (in.hasNextLine()) { String line = in.readLine(); String[] words = line.split("\\s+"); for (int i = 0; i < words.length; i++) { String lcWord = words[i].toLowerCase(); if (st.contains(lcWord)) { st.put(lcWord, st.get(lcWord) + 1); } else { st.put(lcWord, 1); } } } } public int getTotalWords() { int count = 0; for (String key : st.keys()) { count += st.get(key); } return count; } public int getUniqueWords() { return st.size(); } public String getMostUsedWord() { String mostUsedWord = ""; int maxOccurrence = 0; for(String key : st.keys()){ if (st.get(key) > maxOccurrence) { maxOccurrence = st.get(key); mostUsedWord = key; } } return "mostUsedWord"; } public int getMaxOccurrence() { int maxOccurrence = 0; for (String key : st.keys()) { if(st.get(key) > maxOccurrence) { maxOccurrence = st.get(key); } } return maxOccurrence; }

public void printStats() {

System.out.println(timer); System.out.println(+sth); System.out.println(sths); System.out.println(Sequential); System.out.println(getMostUsedWord()); System.out.println(getTotalWords()); System.out.println(getUniqueWords()); System.out.println(getMaxOccurrence() + "" + getMostUsedWord()); }

//main function public static void main(String[] args) { TestPerf test = new TestPerf(args[0]); test.printStats(); } }

whAT AM I DOING WRONG HERE AND IT IS NOT COMPILING OR RUNNING I CAN NOT FIGURE THIS OUT i AM STUCK

in JAVA HW

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transport Operations

Authors: Allen Stuart

2nd Edition

978-0470115398, 0470115394

Students also viewed these Programming questions

Question

List and respond to the social criticisms of marketing.

Answered: 1 week ago