Eirik Lauritsen

Greenhorn
+ Follow
since Sep 12, 2017
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Eirik Lauritsen

Figured out the solution, I just forgot to update the new directions to and updating the x and y posistion was solved with a simple
DIdn't think enough about the solution I assume, but thanks for the input, will look into it!

6 years ago
Hello!
I'm trying to write the turnLeft/Right methods, but I don't completely understand how I should make that work. I assume it's okay to use the code that i've started writing, but how should I finish it?


6 years ago
Seeing as quite a few people started to discuss the output of that spesific line I thought I could post the complete program to show what it actually prints in this instance.


6 years ago
Hello! I'm having some formatting issues with the toString method. I can't quite seem how to print a "%" after the part. How can i do that?
6 years ago
Thanks for the help! Is this a reasonable solution?

6 years ago
So I can just have this? But i'm still not hitting the values from the cooldownSamples method, and that's the point that's confusing me the most. Is it because the methods are running another "iteration" of the array as the numbers vary for each time i run the program? Say the array is created once in the first method, then again for the seconds and another time for the third?

6 years ago
I'm currently working on a school assignement, but i'm stuck at writing the methods that give me the max and min values of the array from the first method. I'm getting numbers that are close to the actual numbers, but they're missing by small margines. I'm having a hard time noticing the mistake i've made, so any help would be much appriciated!

6 years ago
I started the class about 1 month ago, so we're still learning the basic functions and methods of Java. This task was divided into 5 parts and and each part added something new to the code. Started with just the xLocation and slowly added new parts to the code. I guess it would come more naturally if I started with the complete program, but as we have to hand in 1 program for each part it's structured like this. It's more like 5 small programs turned into 1 bigger rather than 1 program fractured into smaller part. That's why i'm trying to ask people that know more than me so they can guide me and give tips on how to improve
6 years ago
Thanks for the desriptive replies, will try to implement your guidelines into my coming programs, learning by doing i guess. Do you have any tips on how to practise methods or should i just write programs and then restructure them so it includes different methods?
6 years ago
I understand why I should use methods and I guess it's especially useful when the programs get even more complex so you don't clutter the code with too much information at once. Right now i would say that inside the for statement i have one part that initialises and resets the location and steps after each iteration of the while loop. One part that generates a random number and then uses it to determine the new value of xLOcation or yLocation, it repeats this until either x- or yLocation goes outside the boundaries. After this it adds the number of steps to the sumOfSteps and starts over again.

Seeing as I haven't properly learned how to write methods i'm looking for some guidelines on how to do it in this program. So if you're able to give me any pointers it would be much appreciated

6 years ago
That's my bad on the thread, didn't see your suggestions before I posted it :/ Now, i followed you suggestions and ended up with a code that looks like this, how would you go about to create a method of everything inside the for statement now? I know that i have to copy the current code and replace it with the name of the new method, but I get stuck there. DO i have to move alle the variables down to the method so it can reach them?

6 years ago
I'm trying to move the part within the for statement to it's own method, but i'm unsure about how to do this. The first thing that strikes me is that copying and pasting it should do the job, but then i'm getting problems with the values not beeing defined inside the new method. How can i work around this?

6 years ago
Thanks for the help! Now I ended up with a code that looks like this. Are there any changes that you would make? I'm new to the world of Java so still in the learning process

6 years ago
Hello! I'm trying to make this program print the average number of steps after 100000 iterations, but i'm having some issues saving the number of steps after each repetition of the while loop.
I know that i have to make a value that divides the total number of steps over 100000 iterations by the number of iterations and print that at the end, but I don't see any need to make that before i figure out how to extract the steps value after each iteration

6 years ago