Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Paul MaudDib
May 3, 2006

TEAM NVIDIA:
FORUM POLICE

hooah posted:

This is the kind of thing that makes me really glad I don't have to devise algorithms for my job. I do not miss this kind of crap from school.

algorithms aren’t too bad until you get into the “aha but if we take the median of medians then we can guarantee n^(sqrt(2)) worst-case running time instead of n^2!” poo poo, which absolutely is a pain in the rear end. Not a fan of leetcode interviews at all.

But a surprising amount of the algorithmic work nowadays is on managing worst-case complexity, things like timsort. And some of that stuff there isn’t an algorithmic basis at all for the heuristics, it’s just “we ran a bunch of tests and this worked best”.

Adbot
ADBOT LOVES YOU

samcarsten
Sep 13, 2022

by vyelkin
ok, we're learning lambda expressions. I have to modify some code using this method to give a pass/fail for the contents of an array. The rules are
"Only the fruits that meet the following criteria will pass:
1. at least 15 grams in weight.
2. 30 days of age or younger unless it has a hardshell
3. color cannot be black"

I am given three fruit types: kiwis, banannas, and coconuts. My initial lambda expression looks like this: FruitInspector goodInspector = (x.getweight >= 15, x.getage >= 30, !(x.getcolor)equals("brown"))) -> {return true;};

but that doesn't excuse hardshells like coconuts and is throwing all sorts of errors. Please help me understand lambda expressions.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
When I'm having trouble with lambdas I first try to write things as a function and then turn them into a lambda. In this case you just have a really convoluted boolean expression,

Java code:
boolean isGoodFruit(Fruit x){
	return x.getWeight() >= 15 && (x.getAge() <= 30 || x.hasHardShell()) && !"brown".equals(x.getColor())
}
Note that your age check was backwards, and I switched the color check (this is safer in case x.getColor() returns null). Also I'm not sure what the hardshell check should do, pass all fruits that have a hard shell regardless of age or not pass any of them.

If you're sure that functions passes all the criteria you want, then you can convert it into a lambda easily.
Java code:
Fruit[] goodFruits = Arrays.stream(fruits).filter(x -> x.getWeight() >= 15 && (x.getAge() <= 30 || x.hasHardShell()) && !"brown".equals(x.getColor())).toArray();

samcarsten
Sep 13, 2022

by vyelkin

Janitor Prime posted:

When I'm having trouble with lambdas I first try to write things as a function and then turn them into a lambda. In this case you just have a really convoluted boolean expression,

Java code:
boolean isGoodFruit(Fruit x){
	return x.getWeight() >= 15 && (x.getAge() <= 30 || x.hasHardShell()) && !"brown".equals(x.getColor())
}
Note that your age check was backwards, and I switched the color check (this is safer in case x.getColor() returns null). Also I'm not sure what the hardshell check should do, pass all fruits that have a hard shell regardless of age or not pass any of them.

If you're sure that functions passes all the criteria you want, then you can convert it into a lambda easily.
Java code:
Fruit[] goodFruits = Arrays.stream(fruits).filter(x -> x.getWeight() >= 15 && (x.getAge() <= 30 || x.hasHardShell()) && !"brown".equals(x.getColor())).toArray();


That last bit throws an error: The method stream(T[]) in the type Arrays is not applicable for the arguments (List<Fruit>) Here is some of the provided code:

code:
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

public class InspectFruit {

	public static void main(String[] args) {
		List<Fruit> fruits = Arrays.asList(
			new Banana(35.0, 20, "yellow"),
			new Banana(37.5, 100, "black"),
			new Banana(5.5, 5, "green"),
			new Banana(37.2, 20, "yellow"),
			new Kiwi(25.1, 19),
			new Kiwi(6.4, 3),
			new Kiwi(21.6, 10),
			new Kiwi(9.9, 5),
			new Kiwi(33.0, 9),
			new Coconut(67.0, 30),
			new Coconut(100.0, 100),
			new Coconut(45.9, 20),
			new Coconut(21.9, 2),
			new Coconut(9.0, 30)
		);
		
		FruitInspector goodInspector = Arrays.stream(fruits).filter(x -> x.getWeight() >= 15 && (x.getAge() <= 30 || x.hasHardShell()) && !"brown".equals(x.getColor())).toArray();
		FruitInspector badInspector = x -> {return true;};
		
		System.out.println("Let's inspect some fruits...");
		System.out.println("Good inspector: ");
		System.out.println("---------------");
		performInspection(fruits, goodInspector);
		System.out.println("Bad inspector: ");
		System.out.println("---------------");
		performInspection(fruits, badInspector);
	}
	
	private static void performInspection(Collection<Fruit> fruits, FruitInspector fruitInspector) {
		fruits.forEach(f -> {
			System.out.println("Inspection result of " + f + ": " + (fruitInspector.pass(f) ? "PASS" : "FAIL"));
		});
	}

}

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
It seems like there is a specific type for the FruitInspector that has a pass method. Lambdas let you create a quick implementations of these simple interfaces and I'm guessing in this case this should work

Java code:
FruitInspector goodInspector = (x) -> x.getWeight() >= 15 && (x.getAge() <= 30 || x.hasHardShell()) && !"brown".equals(x.getColor());

Hippie Hedgehog
Feb 19, 2007

Ever cuddled a hedgehog?
Is it just me or does this problem not really make a very convincing case for lambda functions?

I mean, they want to teach you how to use them, sure, but I hope there’s a future problem to teach you /when/ to use them.

RandomBlue
Dec 30, 2012

hay guys!


Biscuit Hider

samcarsten posted:

ok, we're learning lambda expressions. I have to modify some code using this method to give a pass/fail for the contents of an array. The rules are
"Only the fruits that meet the following criteria will pass:
1. at least 15 grams in weight.
2. 30 days of age or younger unless it has a hardshell
3. color cannot be black"

I am given three fruit types: kiwis, banannas, and coconuts. My initial lambda expression looks like this: FruitInspector goodInspector = (x.getweight >= 15, x.getage >= 30, !(x.getcolor)equals("brown"))) -> {return true;};

but that doesn't excuse hardshells like coconuts and is throwing all sorts of errors. Please help me understand lambda expressions.

You shouldn't have code in the left side of the expression, those are the variables you're passing into the function, which in this case would just be x, then put your logic on the right side inside a code block, like:

Java code:
FruitInspector goodInspector = x -> (boolean expression);
Also since it's a lambda with a single argument that just returns true/false it can be considered a Predicate, so this would work as well:

Java code:
Predicate<Fruit> goodInspector = x -> (boolean expression);
Which lets it know it's a lambda function with a single Fruit argument that returns true/false. Some of your other errors are probably syntax errors if that code you posted is literal because !(x.getcolor)equals("brown") is not valid. Also when comparing against a literal value or constant, always compare from the literal/constant to avoid null pointer exceptions, like:

Java code:
!"brown".equals(x.getColor())
Because if getColor() returns null then x.getColor().equals("brown") would throw a null pointer exception whereas the opposite way will always return true or false since the literal/constant won't ever be null.

RandomBlue fucked around with this message at 23:07 on Sep 30, 2022

Tesseraction
Apr 5, 2009

Hippie Hedgehog posted:

Is it just me or does this problem not really make a very convincing case for lambda functions?

I mean, they want to teach you how to use them, sure, but I hope there’s a future problem to teach you /when/ to use them.

It could be the bullshit hard question in the homework where most aren't expected to succeed but the teacher wants to see how they try (and likely fail) to solve it.

RandomBlue
Dec 30, 2012

hay guys!


Biscuit Hider
Just telling them the answer isn't going to help them understand lambdas.

e:

These two tutorials don't look bad:

https://javabeginnerstutorial.com/core-java-tutorial/java-lambda-beginners-guide/
https://www.educative.io/blog/java-lambda-expression-tutorial

RandomBlue fucked around with this message at 23:26 on Sep 30, 2022

Tesseraction
Apr 5, 2009

RandomBlue posted:

Just telling them the answer isn't going to help them understand lambdas.

Oh absolutely - when I say bullshit hard I don't mean that the teacher shouldn't set them, it's that the student is right to find it bullshit hard, and learn from what they couldn't manage to achieve. Sometimes you learn more from failing than you do from succeeding.

Pedestrian Xing
Jul 19, 2007

Anyone have strong opinions on getting the Oracle Java 17 cert? Is it worth it if I already have a strong resume (aiming for senior/principal level)? If anyone has taken it, how much study should I plan to do?

MrQueasy
Nov 15, 2005

Probiot-ICK

Pedestrian Xing posted:

Anyone have strong opinions on getting the Oracle Java 17 cert? Is it worth it if I already have a strong resume (aiming for senior/principal level)? If anyone has taken it, how much study should I plan to do?

I'd vote that an Oracle Java cert is a net neutral at best for an early career, with perhaps a net negative IMO for senior+ types. But I'm idiosyncratic and really only respect the OSCP.

Twerk from Home
Jan 17, 2009

This avatar brought to you by the 'save our dead gay forums' foundation.
I'm curious if H2 has some benefits that I'm missing, or if I've somehow been using it wrong?

I make some little toy apps in Spring Boot just because I'm very familiar with it, but I've learned the hard way over the years that H2 is not to be trusted in the long run with data, because it seems to be very vulnerable to corruption if the process ever has a dirty shutdown in a way that I haven't seen other databases fail. I've seen this basically as long as I've attempted to use H2, and I get the impression that H2 is only ever used for testing applications locally with transient data.

I've compensated by replacing H2 with SQLite, but sqlite usage seems to be outside of the (non-android) Java culture, and I'm curious to hear what people are reaching for in an embedded database. Is SQLite king of the space like I think it is, or should I check out any other options?

Objective Action
Jun 10, 2007



The trick with embedded databases is in the long run they all have that problem. I've had plenty of SQLite databases eat themselves over the years too. I use H2 a lot and it has lots of really nice features a lot of the other embedded ones don't, like multithreaded access modes, BLOB compression options, Postgres mode, optional embedded web-gui, ability to support multiple clients and transport protocols, etc.

That being said it might be using a sledgehammer to swat a fly depending on what you are doing. SQLite can be fine if you just need table storage without sweating the bells and whistles or if you just want a more cross-language supported way to store data. For instance I do have one application that has both a C/C++ app and a Java app so we standardized on SQLite instead of trying to support an interface or service layer abstraction. Not optimal but given the scope of that app it made the most fiscal sense.

No matter which database you embed though you will eventually want to have a set of startup routines to attempt auto recovery and run any maintenance functions the DB in question provides to clean up transaction files/etc.

The only one I wouldn't really recommend is probably Derby, its been flakier than either H2 or SQLite for me and the recovery options always seemed worse. Just a personal opinion though.

Pedestrian Xing
Jul 19, 2007

H2 also has a handful of weird incompatibilities with T-SQL that make it a pain in the rear end to use as a test DB. Thankfully there's testcontainers now.

RandomBlue
Dec 30, 2012

hay guys!


Biscuit Hider
I like H2 but the 2.x upgrade that uses a new DB format with no upgrading of existing databases is pretty lovely. You have to export your data with the old version, create a new DB with the new version and import the data.

Migrating to that automatically in our app is going to be a PITA for us.

samcarsten
Sep 13, 2022

by vyelkin
ok, new assignment. I have to write code based on the following template which takes a file and lists misspelled words and word frequency using maps and sets. I have no idea how to begin. to start with, it has code already to load the dictionary file. The file I am given to analyze is a plain text file of the bill of rights. I know what the output should look like. How do you do something like this?

code:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;

public class WordCountWithSpellCheck {
    private static final String DICTIONARY_FILE = "dictionary.txt";
    private static final Collection<String> dictionaryWords = new ArrayList<>();
    private static final Map<String, Integer> wordToFrequencyMap = new TreeMap<>();
    private static final Map<Integer, String> frequencyToWordMap = new TreeMap<>(Collections.reverseOrder());
    private static final Set<String> misspelledWords = new TreeSet<>();

    public static void main(String[] args) throws FileNotFoundException {
        // Check command line argument
        if (args.length != 1) {
            System.out.println("ERROR: Missing input file. Please specify the file you want to process.");
            System.exit(1);
        }

        // Check if source file exists
        File file = new File(args[0]);
        if (!file.exists()) {
            System.out.println("Specified file " + args[0] + " does not exist");
            System.exit(2);
        }

        loadDictionaryWords();
        process(file);
        printResult();
    }

    private static void printResult() {
        System.out.println("*** Misspelled words listed in alphabetical order:");
        misspelledWords.forEach(x -> System.out.println(x));
        System.out.println("*** Correctly spelled words with frequency in descending order, same frequency in alphabetical order:");
        frequencyToWordMap.forEach((k, v) -> {
            System.out.println(k + ": " + v);
        });
    }

    private static void process(File file) throws FileNotFoundException {
	// To be implemented by students...
    }

    private static void loadDictionaryWords() throws FileNotFoundException {
        Scanner input = new Scanner(new File(DICTIONARY_FILE));
        while (input.hasNext())
            dictionaryWords.add(input.next());
        input.close();
    }

}

ulmont
Sep 15, 2010

IF I EVER MISS VOTING IN AN ELECTION (EVEN AMERICAN IDOL) ,OR HAVE UNPAID PARKING TICKETS, PLEASE TAKE AWAY MY FRANCHISE

samcarsten posted:

The file I am given to analyze is a plain text file of the bill of rights. I know what the output should look like. How do you do something like this?

Well, the only part you have to write is the process(File file) method:

samcarsten posted:

code:
    private static void process(File file) throws FileNotFoundException {
	// To be implemented by students...
    }

And the only thing you really need to figure out are the misspelled words, in two different sorted orders, based on that output.

samcarsten posted:

code:
    private static void printResult() {
        System.out.println("*** Misspelled words listed in alphabetical order:");
        misspelledWords.forEach(x -> System.out.println(x));
        System.out.println("*** Correctly spelled words with frequency in descending order, same frequency in alphabetical order:");
        frequencyToWordMap.forEach((k, v) -> {
            System.out.println(k + ": " + v);
        });
    }

So, your task boils down to:

1. Take a File object, read it, and decide for each word if that word is spelled correctly.
2. If not spelled correctly, add it to a list of misspelled words.
3. If spelled correctly, update the count of number of times you've seen that word.
4. Sort the list of misspelled words alphabetically.
5. Sort the list of times of you've seen each word in descending numerical order.

ulmont fucked around with this message at 16:11 on Oct 11, 2022

RandomBlue
Dec 30, 2012

hay guys!


Biscuit Hider
Read through the existing code, there's already code there showing you how to load a file one word at a time. Copy that and for each word being loaded figure out if it's in the dictionaryWords collection and if it is add it to the wordToFrequency map, checking if it exists first. If it does exist, increment the frequency, if not, add it with a frequency of 1. If it's not in the dictionary you add it to the misspelledWords set. Then afterwards you loop through your wordToFrequencyMap and add each entry to the frequencyToWordMap.

Why they chose a Set for mispelledWords and not dictionaryWords is beyond me though, dictionaryWords should obviously be a HashSet since you're searching it frequently and searching lists is slow in comparison.

samcarsten
Sep 13, 2022

by vyelkin
How do I increment a value in treemap? I googled it, but most people are talking about hashmaps.

Tesseraction
Apr 5, 2009

They should be interchangeable as both are subclasses of AbstractMap.

crimedog
Apr 1, 2008

Yo, dog.
You dead, dog.

samcarsten posted:

How do I increment a value in treemap? I googled it, but most people are talking about hashmaps.

It doesn't matter the specific implementation, what we're working with is a Map<String, Integer>

You find the key-value pair using the key (String) and then change the value (Integer) to value++

samcarsten
Sep 13, 2022

by vyelkin
ok, that's done. How should I go about turning word to frequency to frequency to word? Also I'm getting an error input file not found and I don't know how to fix it.

code:
package csc251lab9;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;

public class WordCountWithSpellCheck {
    private static final String DICTIONARY_FILE = "dictionary.txt";
    private static final Collection<String> dictionaryWords = new ArrayList<>();
    private static final Map<String, Integer> wordToFrequencyMap = new TreeMap<>();
    private static final Map<Integer, String> frequencyToWordMap = new TreeMap<>(Collections.reverseOrder());
    private static final Set<String> misspelledWords = new TreeSet<>();

    public static void main(String[] args) throws FileNotFoundException {
        // Check command line argument
        if (args.length != 1) {
            System.out.println("ERROR: Missing input file. Please specify the file you want to process.");
            System.exit(1);
        }

        // Check if source file exists
        File file = new File(args[0]);
        if (!file.exists()) {
            System.out.println("Specified file " + args[0] + " does not exist");
            System.exit(2);
        }

        loadDictionaryWords();
        process(file);
        printResult();
    }

    private static void printResult() {
        System.out.println("*** Misspelled words listed in alphabetical order:");
        misspelledWords.forEach(x -> System.out.println(x));
        System.out.println("*** Correctly spelled words with frequency in descending order, same frequency in alphabetical order:");
        frequencyToWordMap.forEach((k, v) -> {
            System.out.println(k + ": " + v);
        });
    }

    private static void process(File file) throws FileNotFoundException {
    	Scanner input = new Scanner(new File("BillofRights.txt"));
    	while (input.hasNext()) {
    		if (dictionaryWords.contains(input.next())) {
    			if (wordToFrequencyMap.containsKey(input.next())) {
    				Integer value = wordToFrequencyMap.get(input.next());
    				wordToFrequencyMap.replace(input.next(), value++);
    			}
    			else {
    				wordToFrequencyMap.put(input.next(), 1);
    			}
    		}
    		else {
    			misspelledWords.add(input.next());
    		}
    			
    	}
    	
    }

    
    private static void loadDictionaryWords() throws FileNotFoundException {
        Scanner input = new Scanner(new File(DICTIONARY_FILE));
        while (input.hasNext())
            dictionaryWords.add(input.next());
        input.close();
    }

}

samcarsten fucked around with this message at 13:23 on Oct 12, 2022

Tesseraction
Apr 5, 2009

How are you invoking the program / specifying the input file? It looks like main is opening it and looking for the file specified as a single argument, however in process(File file) you've hard-coded the Bill of Rights.

Is BillofRights.txt in your classpath? You should be able to drag and drop it into your IDE to help with getting it linked correctly.

Additionally where is DICTIONARY_FILE aka dictionary.txt?

samcarsten
Sep 13, 2022

by vyelkin

Tesseraction posted:

How are you invoking the program / specifying the input file? It looks like main is opening it and looking for the file specified as a single argument, however in process(File file) you've hard-coded the Bill of Rights.

Is BillofRights.txt in your classpath? You should be able to drag and drop it into your IDE to help with getting it linked correctly.

Additionally where is DICTIONARY_FILE aka dictionary.txt?

both files are in the src folder of my eclipse workspace of this project. I have no idea why its not finding them.

necrotic
Aug 2, 2005
I owe my brother big time for this!

samcarsten posted:

both files are in the src folder of my eclipse workspace of this project. I have no idea why its not finding them.

Should you not be attempting to read the File object provided to you?

samcarsten
Sep 13, 2022

by vyelkin

necrotic posted:

Should you not be attempting to read the File object provided to you?

those are the files i am supposed to be reading. maybe i'm not understanding you.

Tesseraction
Apr 5, 2009

Can you post the text of the Exception? It should have the name of the .java file you've got plus its line numbers - if you could also supply those line numbers we can figure out where the error is happening.

edit, picking out a screenshot I posted in this thread a decade ago :corsair: you should have something like this:

samcarsten
Sep 13, 2022

by vyelkin
it's triggering the "check command line" exception built into main.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
You need to specify the filename you want to run it over as a command-line argument.

I haven't used Eclipse in about a decade but there should be somewhere that you set up a launch configuration, including what command-line arguments it uses when running your program.

Tesseraction
Apr 5, 2009

Open the Run settings (Run -> Run... in Eclipse as I remember it) and go to Java Application -> Main -> Arguments -> Program arguments and put in

./BillofRights.txt

samcarsten
Sep 13, 2022

by vyelkin

Tesseraction posted:

Open the Run settings (Run -> Run... in Eclipse as I remember it) and go to Java Application -> Main -> Arguments -> Program arguments and put in

./BillofRights.txt

hmm, it says no such file exists when i do that.

Tesseraction
Apr 5, 2009

Should've known - if you go to the physical file structure where is BillofRights.txt relative to Main.java (or whatever you've called it)

I vaguely recall that it'll be like src/Main.java and then something like files/BillofRights.txt or maybe even just ./BillofRights, in which case the argument should be ../BillofRights.txt

Java shouldn't be arsey about / vs \ as long as you use them consistently.

samcarsten
Sep 13, 2022

by vyelkin
ok, moved stuff and it found the file. Now i'm getting a new error: Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.lang.Integer.intValue()" because "value" is null
at csc251lab9.WordCountWithSpellCheck.process(WordCountWithSpellCheck.java:47)
at csc251lab9.WordCountWithSpellCheck.main(WordCountWithSpellCheck.java:28)

code:
package csc251lab9;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;

public class WordCountWithSpellCheck {
    private static final String DICTIONARY_FILE = "dictionary.txt";
    private static final Collection<String> dictionaryWords = new ArrayList<>();
    private static final Map<String, Integer> wordToFrequencyMap = new TreeMap<>();
    private static final Map<Integer, String> frequencyToWordMap = new TreeMap<>(Collections.reverseOrder());
    private static final Set<String> misspelledWords = new TreeSet<>();

    public static void main(String[] args) throws FileNotFoundException {
        // Check command line argument
        if (args.length != 1) {
            System.out.println("ERROR: Missing input file. Please specify the file you want to process.");
            System.exit(1);
        }

        // Check if source file exists
        File file = new File(args[0]);
        if (!file.exists()) {
            System.out.println("Specified file " + args[0] + " does not exist");
            System.exit(2);
        }

        loadDictionaryWords();
        process(file);
        printResult();
    }

    private static void printResult() {
        System.out.println("*** Misspelled words listed in alphabetical order:");
        misspelledWords.forEach(x -> System.out.println(x));
        System.out.println("*** Correctly spelled words with frequency in descending order, same frequency in alphabetical order:");
        frequencyToWordMap.forEach((k, v) -> {
            System.out.println(k + ": " + v);
        });
    }

    private static void process(File file) throws FileNotFoundException {
    	Scanner input = new Scanner(new File("BillofRights.txt"));
    	while (input.hasNext()) {
    		if (dictionaryWords.contains(input.next())) {
    			if (wordToFrequencyMap.containsKey(input.next())) {
    				Integer value = wordToFrequencyMap.get(input.next());
    				wordToFrequencyMap.replace(input.next(), value++);
    			}
    			else {
    				wordToFrequencyMap.put(input.next(), 1);
    			}
    		}
    		else {
    			misspelledWords.add(input.next());
    		}
    			
    	}
    	
    }

    
    private static void loadDictionaryWords() throws FileNotFoundException {
        Scanner input = new Scanner(new File(DICTIONARY_FILE));
        while (input.hasNext())
            dictionaryWords.add(input.next());
        input.close();
    }

}

Tesseraction
Apr 5, 2009

Threw that into Notepad++ to get the line number it's this line:
code:
    				wordToFrequencyMap.replace(input.next(), value++);
Been a while since I've used scanner but doesn't input.next() iterate with each call?

Try locally assigning input.next() to a variable.

code:
 private static void process(File file) throws FileNotFoundException {
    	Scanner input = new Scanner(new File("BillofRights.txt"));
    	while (input.hasNext()) {
                currentWord = input.next()
    		if (dictionaryWords.contains(currentWord)) {
    			if (wordToFrequencyMap.containsKey(currentWord)) {
    				Integer value = wordToFrequencyMap.get(currentWord);
    				wordToFrequencyMap.replace(currentWord, value++);
    			}
    			else {
    				wordToFrequencyMap.put(currentWord, 1);
    			}
    		}
    		else {
    			misspelledWords.add(currentWord);
    		}
    			
    	}
    	
    }

samcarsten
Sep 13, 2022

by vyelkin
ok, that fixed that. Now, how do i turn word to frequency into frequency to word? It won;'t let me use a for loop, as it's not an iterable.

samcarsten fucked around with this message at 16:11 on Oct 12, 2022

Tesseraction
Apr 5, 2009

I believe your teacher granted a hint with this:

code:
private static final Map<Integer, String> frequencyToWordMap = new TreeMap<>(Collections.reverseOrder());
All Maps can provide a collection: https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Collection.html

samcarsten
Sep 13, 2022

by vyelkin
i'm not sure how to use collections. the documentation is a little confusing.

CPColin
Sep 9, 2003

Big ol' smile.
Welcome to software development!

Adbot
ADBOT LOVES YOU

Tesseraction
Apr 5, 2009

Ah good, I still have Eclipse installed. You keep trying to work your way around collections and I'll play around with them too and refresh my memory. With any luck you won't need my help.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply