48

!rant

I managed to do a chunk of programming in class today without my partner to hold my hand through it. It may be simple, but I am proud of it nonetheless.

Comments
  • 5
    Use rating.equals("asd") for readibility

    Also rating.toLowerCase().equals("asd")
    Would be the best
  • 27
    This is Java but it's tagged as learning JavaScript.
    ?
  • 10
    @YousifMansour Autocorrect + too late to modify. Feels bad.
  • 8
    @RazorSh4rk fixed values should always come before variables to avoid a possible NullPointerException. That's more important than readability.
  • 9
    Don't feel bad. You even thought about using the right comparison order "constant".equals() instead of var.equals() which many beginners get wrong. Keep it up! :-)
  • 2
    @JerreMuesli thats why you declare strings as ""
  • 2
    @RazorSh4rk #equalsIgnoreCase()
  • 2
    Nice work OP, keep at it!
  • 4
    Nice, java, you chose the right programming language, trust me :D
  • 3
    @SirWindfield i find that claim debatable, but to each their own
  • 4
    @Redrield Nana, nothing to debate about here, JAVA BEST LANGUAGE! UGAUGA!
  • 0
    @RazorSh4rk but what if rating == null? It would crash. The way he did it will not crash if rating is null.
  • 0
    @SirWindfield let's just say i refuse to do JVM things without Kotlin and leave it at that :)
  • 1
    Next time don't add a comment like the one on line 29. It describes what is being done on line 30 and thus it is redundant. You did a pretty good job btw.
  • 0
    @CodeMasterAlex if you declare rating as rating = "", then it won't be null. Also, some teachers require that stupid comment, I've lost points when I left it off.
  • 0
    @iam13islucky I know that. In this case it is fine to declare them as an empty string. In many cases, like when calling a method that has a string argument, it can be valid to pass null to indicate that some value is not known. If in that method you want to compare some string value against a passed in argument you can avoid a null check in that way.
  • 0
    More and more girls coding in Java, I'm gonna be ios so ladies we can be together ios and Android dev couple hahaha
  • 1
    Wish I could find a girl who actually codes lol
    There is a huge sausage party going on right now at my uni
  • 1
    @SirWindfield on mine Uni too but i was on Java workshops and four girls with better skills than me came with bfs haha
  • 1
  • 1
    Congrats!!

    One suggestion for the future- more of an "extra credit" project- make the rating an enumeration defined as excellent, good and poor, each being constructed with the message you print out.

    There are different ways to convert the string value passed in by the user to be an enum.

    By doing this, you can easily add new types of ratings and messages without editing the business logic in the method. Also the code becomes really simple to read and understand- input, find rating, print rating message. Lots of ifs get a little overwhelming.
  • 0
    Good job! My suggestion: rethink those comments. If you declared a variable called raise, you don't need a comment explaining what it is. However if there's logic that needs explanation (and you should try to have as little as possible of that) then you can think about commenting. Always try to make the code speak for itself, try to make it read like a book.
  • 0
    @brainlessdev it looks like an early class on the curriculum, and many require excessive comments for full points. Excessive never loses points, fewer does
  • 0
    @iam13islucky Well that sucks! Comments should be used as little as possible and only when it's critical.
  • 0
    @xenonth Meant to write learning Java, phone felt like I meant Javascript, bad tag ensued.
Add Comment