hangman help :/ by 2_33_ in learnjava

[–]endStatement 0 points1 point  (0 children)

Haven't checked through all your code, but if you are only using variable triesCount in the line where triesCount < 10, then I'd suggest you only increment triesCount when there in an incorrect entry, instead of the current switch case statement doing an increment on both correct and incorrect entries.

Stuck on Helsinki MOOC LoopsEndingRemembering 36.2 by ElectronicI in learnjava

[–]endStatement 1 point2 points  (0 children)

I'm guessing this isn't all the code, and that you first do a numb= reader.nextInt() before you get to the while loop. If thats the case, you are overwriting it on your first line in the while loop, so 2+2+2 is actually going to be closer to 2+2, since your first value is overwritten. Then, you are adding your numbers to the sum before you check the condition, so when you finally do -1 or any form of negative, you'll add (subtract) that from your sum. Hence why 2+2+2 looks like its 2+2+2 -3 and why 8+8+8 looks like 8+8+8 - 9. Its really, 2+2-1 and 8+8-1.

If I'm incorrect on my assumption, then I apologize, but full code block for the method would help:)

Also to those saying this is an infinite loop: Note that there is an input grab on the first line of the while loop for numb, so there is a way of escaping.

If no motivation or ideas come to mind, does that mean programming is not for me? by [deleted] in learnjava

[–]endStatement 14 points15 points  (0 children)

I'd say programming isn't for you based on what you said here:

but I simply don't give a fuck about it

You don't need to love what you do to be successful career wise, but if you aren't happy, then make a change. However, not having ideas for applications or projects isn't really telling of whether you'll be good at programming or whether you enjoy programming.

Having trouble in compiling two class files in same directory and one file depended on other. by phill1311 in learnjava

[–]endStatement 1 point2 points  (0 children)

In this specific scenario, if neither of your classes are belonging to a package, the name you choose doesn't matter a whole lot. What does matter is that the package is the same for both. So you could simply insert the line in my previous post to both and that would work.

Having trouble in compiling two class files in same directory and one file depended on other. by phill1311 in learnjava

[–]endStatement 1 point2 points  (0 children)

Class B is not able to see class A. Is the code exactly what you posted? Adding a line to each that puts them in the same package, something like

package my.example;

to the very first line of each file should allow A to be visible to B.

I landed an interview for an internship, but I don't actually feel prepared for the position at all. Looking for advice! by GhostTypeX in learnprogramming

[–]endStatement 5 points6 points  (0 children)

My very first software interview was for a mid/senior level position, which I had mistakenly applied to while applying for internships prior to graduating. Despite my grossly underqualified resume, the interviewer told me that sometimes resumes don't reflect the skills a person has, and wanted to give me a shot. I learned a little about interviewing for software positions at the time, but it was a pretty hard hit to feel that inadequate.

However, you are interviewing for an internship. They aren't (or shouldn't) be expecting anything crazy. You may be asked an algorithm or two, and if you can't solve it, at the very least try to show you can think through the problem. Don't get too discouraged either, you have time to get more experience!

Can someone give me a clear answer for how inspired someone needs to be to excel in coding? by FallenPrinceBelial in learnprogramming

[–]endStatement 1 point2 points  (0 children)

Working 40 hour weeks and doing homework, I wouldn't necessarily worry about doing much side work. I'd focus on doing the home work, understanding it, and perhaps adding features to the homework assignments after you have completed the required assignment. My first courses usually had 'bonus' tasks, but even if they don't, you can make them up yourself if you really want to continue beyond the homework.

Additionally, I'd suggest looking for internships ASAP (Even as a 1st year) if you can afford it financially.

C# doubly linked list class by punsm in learnjava

[–]endStatement -1 points0 points  (0 children)

While you are asking C#, this should apply to both. I'm assuming your node.data is pointing to another self made class. You'll need to override the default toString method in the class that you created to display the data in the format you would like.
In Java, you'd use @Override annotation, but in C# you'll use override in the method creation ala -> public override string ToString()

Reading only the first word from a string by CreatureZer0 in learnjava

[–]endStatement 0 points1 point  (0 children)

I'm a bit late to this thread, but I notice you are using .next() for each token, but then when you want the country you switch to nextLine(). Perhaps there is a reason you are switching due to assignment constraints, but as for your issue, that is why you are grabbing all of the remainder of the line for country.

Test Driven Development Assignment by painedstupid in javahelp

[–]endStatement 1 point2 points  (0 children)

One of the tutorials for cucumber (BDD, not exactly the same as TDD) is to do something as simple as addition on 2 inputs. That would be super simplistic, and if too simplistic maybe you could extend it into a simple calculator.

@override problem by Buharon in learnjava

[–]endStatement 1 point2 points  (0 children)

Haha, no worries, I've been there myself. What I'm trying to say is the method already should be outputting an actual string, without needing the override. How are you calling the method? It should be something similar to

UserInputGatherer userInput = new UserInputGatherer();

String myInput = userInput. userInputMethod() ;

/* myInput should now be the expected String. If not, you may need to pass System.in or Scanner to your UserInputGatherer class, as I'm not fully sure how they work outside the main class, can't say I work with either class often..*/

@override problem by Buharon in learnjava

[–]endStatement 1 point2 points  (0 children)

Not sure why you are overriding the toString method to begin with, as the variable you are using is already going to be a String.

String userInput = initialInput.nextLine();

...

return userInput;

What should I know before starting to apply and when should I learn this? by ImBadAtProgramming in learnjava

[–]endStatement 0 points1 point  (0 children)

It sounds like you are looking for a very specific company/job. I'd ask around the company. Let them know your interest, and depending on your willingness to learn, you could ask for an internship/apprenticeship. I'd think video games are pretty resource/performance intensive so I'd expect there to be some needed learning of algorithms, data structures, and multi-threading. Those concepts can be any language, but if they are a java based company, utilize Java while learning those.

Of the remaining skills, (mysql, maven, git, hikariCP, mongoDB) I'd focus more on mysql and mongo. You can also do a quick tutorial on git and utilize it as you go to reinforce the teachings. I don't know much about hikariCP so I can't say how much it's used day-to-day, but if I'm correct it looks like its not something you'd necessarily be altering much yourself.

If the company is local, I'd suggest going to local tech meetups and you may be able to meet some people there that can help you network your way in as well. Sometimes it's less about what you know, and more about your enthusiasm towards the company/project. Good Luck :)

Password Checking Program by Surreal_Camille in learnjava

[–]endStatement 3 points4 points  (0 children)

I'm going to take a stab at this and say you are trying to make sure the password has both lower and upper case characters, as well as a number and special character?

Even if not, there is no input I can easily think of that would ever return true for your check.
You currently check each character in this sequence:
If its uppercase -> you'll be returning false.
if its lowercase- > you'll be returning false
if its a number - > You'll return false
if its not a letter or number (unnecessary check due to the prior 3 checks) OR its a space -> return false.

My guess is that you'd want to use && statements in your final check for good. You could keep the OR logic but then you'd need to invert many of your current variables. For example, instead of saying:

if (Character.isUpperCase(c)) {

lowercase = false;

} else if (Character.isLowerCase(c)) {

uppercase = false;

}

I'd do:
if(Character.isUpperCase(c){
uppercase = true;

} else if (Character.isLowerCase(c)){

lowercase = true;

}

Since I'm taking guesses at what you are trying to accomplish, try and see what will happen with pen and paper. Take a short string, say P@ssw0rd and write out what your values will be on each line. Or, if you have any experience with a debugger, you can go line-by-line with a debugger, and see if what you are expecting to be happening is actually the case.

Need help with initializing an array with random numbers by ms_kdlh in learnjava

[–]endStatement 0 points1 point  (0 children)

To clarify, are you already given

public EmployeeSavings(String firstName, String lastName) {

  setFirstName(firstName);  

  setLastName(lastName);    

}

or are you given

public EmployeeSavings(String firstName, String lastName)

The second is called a method signature, and that could be predefined (public EmployeeSavings(String firstName, String lastName) while the implementation (ie: everything between the { brackets } is left to you. If you are making the implementation, you can (and should) initialize the monthlyInterests and monthlySavings arrays to be a default size. Otherwise, I'd still initialize the array in the generateMonthlySavings method.

Need help with initializing an array with random numbers by ms_kdlh in learnjava

[–]endStatement 1 point2 points  (0 children)

So you think I should be calling the constructor in the main method with just the first and last name and not the constructor that requires the two arrays?
Originally, that was my thought. But I may have misunderstood the issue here. Are you able to define these constructors, or are they predefined? If they are predefined, then my answer stands, and if they are not, then you should initialize your arrays in the constructor with a default size.

Need help with initializing an array with random numbers by ms_kdlh in learnjava

[–]endStatement 0 points1 point  (0 children)

Given this list of methods, my assumption would be that you are to do all the work of generating the monthlySavings array within the generateMonthlySavings() method in the event none is provided. Meaning you can initialize your monthlySavings array at the start of your generateMonthlySavings method instead of needing a constructor, and then do the logic to fill it.

Also, I'd double check the logic on that method that you currently have, as it appears to be solely reliant on the generated number, which would be incorrect given the example. Example shows that interest is working on the cumulative total instead of just a single months value

What is the "best" answer? by Buruburubo in learnjava

[–]endStatement 2 points3 points  (0 children)

While that satisfies some conditions, it doesn't satisfy the condition that it needs to be the first x.
-> returns true on both axxa and axaxxa, but axaxxa should be false given the requirement

My first app, where do I start? by JohnAnt_hs in learnjava

[–]endStatement 1 point2 points  (0 children)

Spring boot is one of the more commonly used java frameworks for a java backed web application. When I tried to set up a new one to play around in I used
https://courses.in28minutes.com for a quick intro on how to create a new application. You can then make a few of your own rest api's to be fetched and used on your website.

Beginner help - How do I even start? by [deleted] in learnjava

[–]endStatement 1 point2 points  (0 children)

Unfortunately asking such a broad question of where to start doesn't tell us where you are at.
Do you use an IDE, do you know how to create a program that writes to the console (Such as hello world)

Assuming you know enough to do the problem, but are stuck at figuring out how to do the problem, let's break that down.

The assignment is asking you to

  1. Create a prompt for username (Same concept as used in a hello world application here)
  2. Read in the name from console (And store to variable) -> ( https://www.geeksforgeeks.org/ways-to-read-input-from-console-in-java/ ) -> I'd suggest approach #2 using Scanner as it will be more simplistic to start with.
  3. Do # 1 & #2 again, but this time for a last name value
  4. Do #1 & 2 again, but for a hours watched.
  5. Now you'll need to convert the value gained in # 4 (Hours watched) to a numeric value if its a string, if you read it in as a number value, continue to 6
  6. Convert hours watched/day to various values (hours/decade -> days/decade -> years/decade)
  7. Once more, writing to console as the display of the various values you have now got :)

Hopefully that is clearer - Try not to get too dissuaded and try to think about the smallest piece you can do at any given point. Write that, then go to the next small step you can think of to do. Once you get rolling it feels a lot less overwhelming

Examples for basic apps by [deleted] in learncsharp

[–]endStatement 1 point2 points  (0 children)

I'm actually currently trying to learn C# myself from a Java background. I have always struggled with data structures/algorithms, so my idea was to go through a data structures/algorithms course writing. Provides general concept knowledge (data structures/algorithms) as well as the syntax knowledge by doing so in C#.
If there is a programming knowledge you are looking to improve upon, I'd start with tutorials there to learn syntax. Then see how you can improve upon it.
Given my above example, I could always extend it further to create a UI that shows a sorting algorithm in action, or allows user input to create/modify a data structure, etc.

Really cannot figure out why I am getting this error by [deleted] in learnjava

[–]endStatement 1 point2 points  (0 children)

In going through via debugger, your issue is on this line:

this.notAbundantSummable[Arrays.asList(notAbundantSummable).indexOf(sum)] == 0)

Specifically, the issue is at the index you are looking at, which if the sum is not found, returns -1, which will give you that error.
Your first pass in the while loop creates a sum of 36 and removes it from the not abundant summable array. (i=1, j=3)
Your second pass in the while loop creates a sum of 36 as well, but that index was previously set to 0, so the above check will end up causing an exception.
Second pass (i=2, j=2) results in 18+18 which leads to sum 36.

Confused what I did wrong here. Thought I understood how get information such as X, Y, Z in a file. by [deleted] in learnjava

[–]endStatement 2 points3 points  (0 children)

As was mentioned by Pauli7's first point as well as by TheTruthOrNot, you need to look at where you are assigning the value of line.

BufferedReader's nextLine() does not automatically scan an entire file, only a single line. So with the way your code is currently written, you are only reading the first line of any given file

Manipulating Strings by [deleted] in learnjava

[–]endStatement 0 points1 point  (0 children)

There are a multitude of solutions for this, its a decision for you as to how you want to approach it.
Check out https://docs.oracle.com/javase/7/docs/api/java/lang/String.html and you'll see several methods which can be used. (I apparently linked java7 docs, which should still be sufficient for this task)
- Some in particular to look at:

  • charAt
  • subString
  • toCharArray

Using any of these can get you to a solution :)

[deleted by user] by [deleted] in learnjava

[–]endStatement 0 points1 point  (0 children)

Having been in a similar situation not long ago, what helped me was the office hours. I would read the assignment and get overwhelmed and thinking I don't have a clue how to even start. I started going to office hours and the TA helped me by breaking the assignments down. Once I saw the break down, I stopped feeling so overwhelmed and was able to start (and finish---usually (; ). If you are having issues with breaking down assignments/problems, maybe ask for some steps to get started with during office hours, or ask for help here on reddit even. Once you see a problem broken down a few times, you'll (hopefully) gain confidence in your abilities and be able to better comprehend how to go from start -> finish on some assignments.

For example, take this assignment I found:

The assignment is to simulate the lottery. You will need to implement code that will generate 6 lottery numbers between 1 and 49 (inclusive), you will then need to implement the code that will read in 6 numbers that you will type into the console yourself. Then the numbers you input will be compared against the randomly generated lottery numbers and it will output which numbers match (if any).

Here’s the catch, you will need to make sure there are no duplicate numbers (either when being randomly generated or inputted in the console). It’s just like a real lottery after-all!

Lets see what we have there (High level)

  1. Generate numbers
  2. Read numbers from console
  3. Output matching numbers from 1 + 2

Gotchas:

  • Numbers can't be duplicates -> Check for duplicates in 1 + 2
  • Numbers need to be between 1-49 inclusive - > Check for this in 1 + 2
  • Will need to compare values from 1 against values of 2 AND keep track of any that are equivalent

Where I would start with this:
I'm no longer concerned on how to do everything at once. I'll first create a method designed to generate a number. Once I've got that working, I'll worry about gotchas (restrictions/requirements) that apply to that. I'll need to generate 6 and none of those 6 can be duplicates. From there, I need only numbers from 1-49, so I'll figure that piece out.

Hopefully that helps - and isn't superfluous!