|
ok, so can i cast wordToFrquencyMap to an array, then reverse the order of the array?
|
# ? Oct 12, 2022 16:46 |
|
|
# ? May 20, 2024 07:28 |
|
None of the stuff google turns up is making me less confused about collectons.
|
# ? Oct 12, 2022 16:51 |
|
ok, looks like a collection cannot contain the key/value pairs I'm working with, so I'm back to square one.
|
# ? Oct 12, 2022 16:56 |
|
Yes, looking back at it, is the idea that the output for that part is that if the words "the" "bill" and "rights" appear 100, 200 and 150 times respectively, you get this output: 200: bill 150: rights 100: the ?
|
# ? Oct 12, 2022 17:12 |
|
Tesseraction posted:Yes, looking back at it, is the idea that the output for that part is that if the words "the" "bill" and "rights" appear 100, 200 and 150 times respectively, you get this output: yes, exactly.
|
# ? Oct 12, 2022 17:24 |
|
And what does it do if two words appear at the same frequency?
|
# ? Oct 12, 2022 17:25 |
|
prints "1 : " then each of the words.
|
# ? Oct 12, 2022 18:04 |
|
Right, so your teacher gave you a better hint:code:
code:
Oh, but a fair warning. value++ and ++value have different effects - something I picked up on while copying your code.
|
# ? Oct 12, 2022 18:13 |
|
Neither makes sense in this context, as the code doesn't use value again after replacing it in the map.
|
# ? Oct 12, 2022 18:35 |
|
Yeah I'm not sure why they both exist except the teacher testing what the student does.
|
# ? Oct 12, 2022 18:39 |
|
ok, almost there. It's getting information put in to the proper map, but it's not listing more than one value for the key. Is there another command I should be using besides put?code:
|
# ? Oct 12, 2022 18:45 |
|
Think about how you incremented the count, and how you can do something similar with a string.
|
# ? Oct 12, 2022 18:57 |
|
Tesseraction posted:Think about how you incremented the count, and how you can do something similar with a string. you can increment a string?
|
# ? Oct 12, 2022 19:01 |
|
No, but think about the mechanism of addition. You write value++ but that's just a shorthand for value + 1
|
# ? Oct 12, 2022 19:30 |
|
ok, i know what I'm trying to do, but I can't get it to work, it's just repeating the same word.code:
|
# ? Oct 12, 2022 19:35 |
|
You're using: String word = k; But you need another way of doing this. You're no longer using a Scanner, so you need to think about where you're getting the value of what is potentially being added vs. what has already been added. Remember what a Map lets you do.
|
# ? Oct 12, 2022 19:41 |
|
I'm stumped. I've got it so it's no longer replacing each new word, but it's not adding words either.code:
|
# ? Oct 12, 2022 19:48 |
|
How do you get a current value from a Map?
|
# ? Oct 12, 2022 20:50 |
|
Tesseraction posted:How do you get a current value from a Map? you give a key.
|
# ? Oct 12, 2022 21:35 |
|
Right, and look at where you are (or aren't) giving it a key.
|
# ? Oct 12, 2022 21:49 |
|
It might help if you comment each line of the code you just posted and tell me what it's doing, as far as you're concerned.
|
# ? Oct 12, 2022 22:02 |
|
Tesseraction posted:It might help if you comment each line of the code you just posted and tell me what it's doing, as far as you're concerned. code:
|
# ? Oct 12, 2022 22:09 |
|
Right, so you're thinking along the right lines, and you're handling v correctly. But if you look on code:
|
# ? Oct 12, 2022 22:14 |
|
Tesseraction posted:Right, so you're thinking along the right lines, and you're handling v correctly. word? I think?
|
# ? Oct 12, 2022 22:17 |
|
Right, so you're changing the new value of the value for key(v) to "word" + "word"
|
# ? Oct 12, 2022 22:21 |
|
Tesseraction posted:Right, so you're changing the new value of the value for key(v) to "word" + "word" so how do i hold the value of the current word and add it to the previous value of the key/value pair?
|
# ? Oct 12, 2022 22:22 |
|
When you needed to get the previous word count, how did you get value before you applied ++?
|
# ? Oct 12, 2022 22:25 |
|
Tesseraction posted:When you needed to get the previous word count, how did you get value before you applied ++? Welp, that didn't work either. code:
|
# ? Oct 12, 2022 22:28 |
|
Check your invocation of replace() - you're using the replace-if-matches replace(K,Vold,Vnew), while you only need replace(K,Vnew) You want this https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html#replace(K,V) not this https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Map.html#replace(K,V,V) I was actually curious why it wasn't throwing an error with three arguments, hence looking up the Javadoc.
|
# ? Oct 12, 2022 22:33 |
|
ok, that makes it work. well, this weeks homework is done. Thank you very much for your help.
|
# ? Oct 12, 2022 22:35 |
|
No worries. Just remember me when you're a billionaire.
|
# ? Oct 12, 2022 22:36 |
|
|
# ? Oct 12, 2022 23:54 |
|
Honestly, better than being forgotten.
|
# ? Oct 13, 2022 00:01 |
|
ok, so this weeks homework is manually creating a list object without using the inbuilt code object. So that means manually programming basic commands. Let's start with the first one.code:
code:
|
# ? Nov 1, 2022 10:25 |
|
When you use the name of a class like that (as in, MyClass.foo()), you're accessing things that are related to the class itself, rather than any particular object. These things are called static. The error message is telling you that you've written code that looks like it's trying to access a static thing, but the thing you're trying to access doesn't make sense to access statically - it needs a specific object to talk about. Since you're implementing a method, you can use the special this keyword to mean "the object that my method was called on" - so your loop would look something like this: code:
code:
|
# ? Nov 1, 2022 10:41 |
|
code:
|
# ? Nov 1, 2022 11:46 |
|
samcarsten posted:
There's a small mistake in your if-clause. e = this.get(i) tries to assign what is returned from the List to e. You want to compare the two, so the operator is ==.
|
# ? Nov 1, 2022 12:18 |
|
now it's saying it must return a boolean. I made it return something already, what is it talking about?
|
# ? Nov 1, 2022 12:20 |
|
samcarsten posted:now it's saying it must return a boolean. I made it return something already, what is it talking about? What does it return if the list does not contain the Object you're looking for?
|
# ? Nov 1, 2022 12:22 |
|
|
# ? May 20, 2024 07:28 |
|
Kuule hain nussivan posted:What does it return if the list does not contain the Object you're looking for? but if i change it to an if;else, the it doesn't iterate. Where should I put the return false?
|
# ? Nov 1, 2022 12:25 |