Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!

Ares Xena

Greenhorn
+ Follow
since Jan 16, 2018
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ares Xena

Miroslav Lehotsky wrote:

...This is what I wrote based on your original comment...



The code there was just simplified pseudocode. You just copied reference to the same list... You need to make really a separate list object (eg. List<?> listCopy = new ArrayList<>(list);) And regarding second scenario, see post above, it's not safe operation performed like that, it can work for you, but it's undefined behavior when adding list to itself... So in that case you should go with the copies as well...


Awesome, cool. Thanks for clarifying!
2 months ago

Miroslav Lehotsky wrote:Actually, for second scenario it could be even better, by not using copy of the original list at all, and just append by addAll to the originalList same originalList, eg: originalList.addAll(originalList).


Hi! Thanks for the replies. From what I understand scenario 1 is more likely. Your approach worked in my IDE. Probably made it more complicated in my head than it actually was. Unfortunately, the challenge doesn't accept the code I wrote.

This is what I wrote based on your original comment:



For some unknown reason, it outputs as   a, b, c:

Failed. Wrong answer

This is a sample test from the problem statement!

Test input:
ListMultiplicator class

Correct output:
Well done!

Your code output:
[a, b, c, a, b, c]
Assertion failed: Multiplication error



Scenario 2 didn't seem to work. If I replace with   it says there is an incompatible type issue. Either way scenario 1 that you wrote worked for me. So thanks, really appreciate it!


2 months ago
Hi folks,

Been absolute ages since I went on this website. Currently going through Generics in Java (https://hyperskill.org/learn/step/2641) and I got stuck at a code challenge question. It's a challenge following information about Generics and Wildcards.




Code Challenge — Write a program
You are provided with the backbone of ListMultiplicator class that has multiple methods that take list and multiplies its content specified number of times. The original list content should be changed after method returns. The task is to add implementation to the method without changing its signature.


You are guaranteed that:

list is not null
n equals or greater than zero
n stands for the number of times the original list repeated in the result. So if n equals zero the resulting list should be empty.

For the original list:

[1, 2, 3]
and n equals 2 the result should be:

[1, 2, 3, 1, 2, 3]




From what I gather from the hints tab, you can use a helper method to store the original array. However, I'm just completely lost on writing the logic for this challenge after about an hour. If anyone could be of use to explain how to solve it, that'd be great!
2 months ago

Daniel Demesmaecker wrote:
I would remove the actionlistener on the textfield en move it's code to the actionlistener of the button.
My guess is you use the button and the actionlistener on the textfield isn't being called.


Yes, I'm Dutch. For the sake of everyone else going through these comments though I'll be using English. Removing the actionlistener and moving the parse to the jButton did manage to get me closer. However, when I press the button, the sentence:
"A number has been entered" is spammed a few billion times and won't stop. I've never experienced a System.out decide to produce an infinite amount of words or sentences. Do you have a suggestion on how to resolve that particular bit?
In terms of the main focus of this thread I'll test a few things for that tomorrow.
2 years ago

Daniel Demesmaecker wrote:The parsing you did right, are you able to start your program and to fill in a number? I'm not so familiar with swing, I always use javafx


I'm able to fill in a number. I believe it registers the number, but doesn't handle it correctly. Despite of the input, it still sends a message to the console that no input has been entered (System.out.println("You didn't enter a number. Please try again.");
2 years ago

Daniel Demesmaecker wrote:And I haven't really red your code, put if you expecting an int you have to parse it, cause it will return a string.


I've updated the syntax and tried to play around with it based on what you mentioned regarding the parse. Hopefully I did that correctly, but it's doubtful, as I still get the same message. At this stage I'm not even trying to get the math generator to work, just trying to get it to register the numbers.
2 years ago

Dave Tolls wrote:

Can you explain what the above code is doing and when you expect it to run?


I was hoping it would get the user input and hold it in a variable. Though I must admit it was more of a ''well, let's see what this does'' move.
2 years ago

Norm Radder wrote:

it claims not not receive any numbers.


How is that reported?  

If there are any error messages, copy the full text and paste it here.


Hi! Cheers for the reply. It's right underneath the jButton1 method I believe.
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
       if (j == 0) //conditional checking if j is 0
       {
           System.out.println("You didn't enter a number. Please try again.");
         
        }
I'm having System.out.println(); handle it because I'm still testing.
2 years ago
Hello everyone,

I'm having trouble with a Math Quiz application. The user is supposed to enter a number of questions they'd like to do based on an existing number generator method. However, this is proving to be a bit difficult. As it doesn't actually generate the numers. Upon my research into this frustrating issue I stumbled upon a source code that (without Swing)  actually does generate the questions the user inputs. Great! Or, no? Sort of. I'm having trouble translating what I just learned into my Math Quiz with Swing. This is the source code that actually does generate the amount of questions.


For my application I'm using the Netbeans IDE with JFrame form(clicking, dropping, assigning a code). I've tried to create a scanner object that registers the number a user would input. However, it claims not not receive any numbers.
I made a rather awkward attempt to try and show what I have thus far:
A lot of that is automatically generated by Netbeans. And yes the libraries are imported.
If anyone could assist me on this matter that would be incredibly helpful.
2 years ago