Win a copy of liveProject: Protecting User Data with Spring Security and OAuth2 this week in the Spring forum!

Jason Edwards

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

Recent posts by Jason Edwards

Jason Edwards wrote:Hi Mike Simmons,
Thanks for looking over my code and giving me some help.

Well, perhaps the first thing to do is compile and run your program - you will see that it does compile, which is good, and then you get an error message when you run it - which may or may not have been intentional, if you were testing what happens for different input values.
I was paying around with inputs, testing my code and checking the errors.

My IntelliJ shows "import kotlin.random.Random" greyed out - you don't need it.  Maybe it was needed in some older version of Kotlin.  But nowadays Random is directly available without that.
My workplace is quiet for the next 2 weeks. So I was using https://play.kotlinlang.org/ to build the app(spent about 3 hours on the code)


IntelliJ also shows messages indicating that each of your var declarations can actually be a val, since you never reassign a variable to be something else.  This is good practice - use val rather than var whenever you can, to minimize unexpected changes.  If you need something to be a var, fine, make it a var.  But don't do it if you don't need it.
Will do from now on.

You seem to be doing the same thing several different ways. The one I like best is this one:


I really like this code but from what I can tell, its read only!, you can print the full list or an element, looked online for random list but could not find any post talking about .sorted() or .forEach({print("$it ")})
so moved the numbers over to an array I could sort and edit the list.

Thank you for the help.
I really enjoy reading code like this, makes perfect sense.











1 day ago
Hi Mike Simmons,
Thanks for looking over my code and giving me some help.

Mike Simmons wrote:Well, perhaps the first thing to do is compile and run your program - you will see that it does compile, which is good, and then you get an error message when you run it - which may or may not have been intentional, if you were testing what happens for different input values.


I was paying around with inputs, testing my code and checking the errors.

Mike Simmons wrote:My IntelliJ shows "import kotlin.random.Random" greyed out - you don't need it.  Maybe it was needed in some older version of Kotlin.  But nowadays Random is directly available without that.


My workplace is quiet for the next 2 weeks. So I was using https://play.kotlinlang.org/ to build the app(spent about 3 hours on the code)


Mike Simmons wrote:IntelliJ also shows messages indicating that each of your var declarations can actually be a val, since you never reassign a variable to be something else.  This is good practice - use val rather than var whenever you can, to minimize unexpected changes.  If you need something to be a var, fine, make it a var.  But don't do it if you don't need it.


Will do from now on.

Mike Simmons wrote:You seem to be doing the same thing several different ways. The one I like best is this one:



I really like this code but from what I can tell, its read only!, you can print the full list or an element, looked online for random list but could not find any post talking about .sorted() or .forEach({print("$it ")})
so moved the numbers over to an array I could sort and edit the list.

Thank you for the help.
I really enjoy reading code like this, makes perfect sense.

Mike Simmons wrote:(1..maxNumber).shuffled().take(totalNumbers).sorted().forEach({print("$it ")})











1 day ago
Any small challenges like making a small app in kotlin would be really helpful, I have been trying to build a small program that you can pick a few random numbers, don't repeat any numbers and prints the numbers in order ( 1..150)
Is this code effective and how could I improve the code?

import kotlin.random.Random

fun main(args: Array<String>) {
 
   /** Random number picker with no repeating numbers.
    * will display them in number order.
    * Random numbers upto 150.
    * Upto 150 numbers balls.
    *
    * randomList(max number int 1..) ( how many numbers/ balls)
**/
   randomList( 27, 30)
    }


    fun randomList(maxNumber : Int, totalNumbers : Int){
    if (totalNumbers > 150){
        print("please pick a lower number")
       }else if (totalNumbers > maxNumber){
            print("maxNumber has to be same or higher than totalNumbers")
               }else{  
       
   var list = mutableListOf<Int>()
   var totalNumbersMinus1 = totalNumbers-1
 
    var randomList = (1..maxNumber).shuffled().take(totalNumbers)
     for(I in 0..totalNumbersMinus1){
     
    var number = randomList[I]
 
   list.add(number)
  }
 list.sort()
 for(I in 0..totalNumbersMinus1){
     print("${list[I]} ")
     }
   }
   
 }
1 day ago

Hugge Nilsson wrote:Yes Jason it's not completely my code but I use it as a base to get all the functions. I'm still an absolute beginner.



If your absolute beginner, you need to start from the beginning, I would start off with this course https://www.youtube.com/watch?v=uRyvNKRkwbs
I have been building apps on android studio for a few years, If you get stuck let me know and I will do my best to help.








3 days ago

Hugge Nilsson wrote:Thank you! And how do I add that to a Listview in the other activity. I can't wrap my head around it


Your welcome Hugge Nilsson.
Just wondering, have you developed android Applications on Android Studio?

As you need code for the GUI (xml), and Java/Kotlin code for the back end. The code you put up looks like a coffee app built in Java code, only as a test( online android course).

For Android development, most developers are moving over to kotlin, its faster and and easier to work with.





3 days ago


To move a string from 1 activity to another,



5 days ago
hi all,
(commit 5) Improved the code, put a few comments for easy reading
(commit 6) removed most the code, looked into Concepts of OOP Languages(starts about 1 hour in), and I must say, I am very happy going from Java to Kotlin so far.
feels like you can build the same apps with less code, been writing some code and seeing what I can do.
Took me about 1 hour to build the app and fix all the bugs.
Its a lotto lucky dip to pick your numbers.






5 days ago
So far I have 4 commits:
First one, is the blank activity and java class.
Second one is a basic kotlin hello world app.
Third one's a toast message when you click the button.
Fourth one, counts the button clicks and displays it to the textview.
6 days ago
Hi all,
I have started going through the tutorial and put my code up on github.(https://github.com/JasonEdwardesUk/FollowAndroidTutorialWithKotlin). Often I use Linearlayout, only program in code, never use android studio layout editor.






1 week ago

Campbell Ritchie wrote:

Jason Edwards wrote:. . . move my posts to the android section . . . .

Done. Complete with spelling mistake in thread title.


Thanks Campbell.
1 week ago

Campbell Ritchie wrote:Welcome to the Ranch

Use the new topic button towards the upper right.
Did you write that tutorial yourself? I don't have the time to go through it.



Thanks Campbell Ritchie, could you move my posts to the android section as a new thread?

It's not my tutorial, just looks up-to-date and a good tutorial on YouTube, I would like to use github and push myself to write clean short code. Would be great to help other developers and inturn they can make comments about my code.
1 week ago
Hello Coderanch, I can see this thread is a month old but it has a good title, and I don't know how to start my own thread.

Have been using android studio for the last 4 years and really enjoy building applications in my spare time( have a young demanding family and a full time job(in catering) so only spending 5-10 hours a week on coding).

Love using java to develop applications but kotlin looks more productive in the long run.

This course on YouTube looks great  (https://youtu.be/uRyvNKRkwbs )

Does anyone want to join me on this course over the next month?


1 week ago