Create Rock Paper Scissors in Java in 10 Minutes

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ต.ค. 2024
  • Complete Java course: codingwithjohn...
    Full source code available HERE: codingwithjohn...
    We'll create a Rock Paper Scissors game in Java completely from scratch! Learn user input, while loops, if/else conditions, random numbers, and more.
    This is a very beginner friendly beginner's Java coding lesson tutorial, where we'll create a Rock Paper Scissors game completely from scratch, beginning to end.
    Learn or improve your Java by watching it being coded live!
    Hey, I'm John! I'm a Lead Java Software Engineer who has been in the industry for more than a decade. I love sharing what I've learned over the years in a way that's understandable for all levels of Java developers.
    Let me know what else you'd like to see!
    Links to any stuff in this description are affiliate links, so if you buy a product through those links I may earn a small commission.
    📕 THE best book to learn Java, Effective Java by Joshua Bloch
    amzn.to/36AfdUu
    📕 One of my favorite programming books, Clean Code by Robert Martin
    amzn.to/3GTPVhf
    🎧 Or get the audio version of Clean Code for FREE here with an Audible free trial
    www.audibletria...
    🖥️Standing desk brand I use for recording (get a code for $30 off through this link!)
    bit.ly/3QPNGko
    📹Phone I use for recording:
    amzn.to/3HepYJu
    🎙️Microphone I use (classy, I know):
    amzn.to/3AYGdbz
    Donate with PayPal (Thank you so much!)
    www.paypal.com...
    ☕Complete Java course:
    codingwithjohn...
    codingwithjohn...

ความคิดเห็น • 122

  • @mastershonobi110
    @mastershonobi110 2 ปีที่แล้ว +8

    Thanks John! Trying to build on my own. This really helps with the application of knowledge and logic…

  • @ashishprakash2879
    @ashishprakash2879 3 ปีที่แล้ว +1

    Video was helpful love from INDIA
    I m cs student practicing java..
    Thanks for this video people like you are blessings to us..

  • @factoverfiction4699
    @factoverfiction4699 3 ปีที่แล้ว +62

    Thanks a lot! This video helped. I'm trying to switch careers and have been trying to learn Java on my own for a few months now and still have trouble with basic fundamentals (misplacing a bracket, forgetting a semi-colon, etc). Sometimes it's super frustrating and I want to give up. But videos like yours really help push me forward!!!

    • @mamamiyamama6461
      @mamamiyamama6461 2 ปีที่แล้ว +4

      Hows progress

    • @goldenstatew2399
      @goldenstatew2399 2 ปีที่แล้ว +1

      I have buddy who's 2 years in and he's been a great mentor to me, it really helps alot to have someone you can go over stuff with. That's my tip

    • @lroadzl1288
      @lroadzl1288 2 ปีที่แล้ว

      @@goldenstatew2399 I should try to do that lol but I'm not much of a social person and don't really have friends so it'll be very difficult for me

    • @turuus5215
      @turuus5215 2 ปีที่แล้ว +3

      Online courses will help you a lot. Sign up for a good one after you read reviews and stuff. It will cost you a few tens of bucks. Maybe, John's full Java course will help you even more.

  • @Blablabla01ify
    @Blablabla01ify 11 หลายเดือนก่อน +11

    Dude, you are the only one who made a video to build this game without having to use methods or class calls, and that is very helpful to learn. From experience, although class calls or method are used, it is not always good to use them and sometimes it is better to use everything in one class like in your video. Great!!

  • @newvemo
    @newvemo 3 ปีที่แล้ว +2

    Hi John, thanks for your good and straight tutorials in java.
    Please make a series on threads and multithreading in java。please and please do that, I think you are the only person I understand among all youtubers
    Thanks and god bless you

    • @CodingWithJohn
      @CodingWithJohn  3 ปีที่แล้ว

      Multithreading can be real complicated, but that's a nice idea for a video. Maybe I can start with a something simple there. Thanks a ton for watching!

    • @newvemo
      @newvemo 3 ปีที่แล้ว

      @@CodingWithJohn thanks for your reply John,
      I will be very very grateful for that, anyway I will be waiting for it

  • @georgeandary6064
    @georgeandary6064 ปีที่แล้ว +8

    You are the man for this one John.
    I literally had a cup of coffee this morning while reviewing this for my test tonight and though "I am having Java, while learning JAVA with John".
    Idk what that means I just want you to know you helped, Thanks.

  • @javalady
    @javalady 5 หลายเดือนก่อน

    i think you must close the scanner right before breaking the main loop or outside the main loop. but you closed it at the end of the loop and inside of it, so it only works for the first iteration!!

  • @marcos.a8814
    @marcos.a8814 2 ปีที่แล้ว +1

    Hey there, I know this video a bit old but I'm doing this as a sort of school project, but when you input
    System.out.println(playerMove + " is not a valid move!");
    it actually tells you that what you do input isn't a valid move, so idk if maybe I made a mistake or it was a mistake but just wanted to point that out. thank you for these videos I really appreciate them and you're an excellent guide in helping me get to know java

  • @karantodkar8251
    @karantodkar8251 3 ปีที่แล้ว +6

    Today I made this program on my own in morning and TH-cam recommended me this to me in evening. And after watching this video I am glad to notice that I am close to logic but still need to code like this guyyyy

  • @jybinu
    @jybinu 3 ปีที่แล้ว +8

    Hi John
    Many thanks for your infotainment videos. It is really fun learning through play.. I wonder whether you could make videos of coding out game that involves concepts of java like interface, enums, inheritance, polymorphism, encapsulation, abstraction etc.

  • @jual71
    @jual71 2 ปีที่แล้ว +2

    Did you just say this was simple 🤣🤣🤣🤣

  • @chaudharyu.8453
    @chaudharyu.8453 3 ปีที่แล้ว +8

    Please please continue with these kind of Java videos. Best Java related channel 🙏💪

  • @Muslim05879
    @Muslim05879 4 หลายเดือนก่อน +1

    can anyone suggests videos like this to practice OOP in java with projects like this ?

  • @lucianocampanelli7325
    @lucianocampanelli7325 2 ปีที่แล้ว +1

    Excelent video for begginers like me 😄

  • @captainsloth5895
    @captainsloth5895 2 ปีที่แล้ว +3

    One does not simply leave a "coding with John" video without liking..!

  • @CinemaReview001
    @CinemaReview001 9 หลายเดือนก่อน +8

    Bro u look like someone😅😅

  • @zabbarosa
    @zabbarosa 11 วันที่ผ่านมา +1

    Line 18, should be DENIED.😱

  • @DeQuilon
    @DeQuilon 2 ปีที่แล้ว

    Thank you, it was really helpful.

  • @RecapBoxing
    @RecapBoxing 2 ปีที่แล้ว

    Thanks for the help man!

  • @pumpk_1712
    @pumpk_1712 2 ปีที่แล้ว +2

    I learn this kind of stuff and just started java this way really helpfull as my first mini project
    By the way im a 9 year old

    • @doggo4
      @doggo4 5 หลายเดือนก่อน

      It is dangerous to reveal your age on the Internet unless you are over 13.

  • @sujinnnn2005
    @sujinnnn2005 2 หลายเดือนก่อน +1

    Just made my morning ha ☕

  • @NEO-wl9ox
    @NEO-wl9ox ปีที่แล้ว +1

    Hello mate , I wholeheartedly come across some of your vids brimming with scrumptious fascinations, sophistication and including making up game like tic tac toe , hangman game , word guessing game , sudoku game as well as scrabble game
    All of them are captivating , I even put them out into my practices and working pretty well and I kind feel like I can see light in tunnel with ur immaculate tutorial videos
    Thank you so much man ❤

  • @bhobhogameplay8226
    @bhobhogameplay8226 8 วันที่ผ่านมา

    Where do I upload the code onced I finished making it? I want to have the game be live and be playable by other people.

  • @kafychannel
    @kafychannel ปีที่แล้ว +1

    awesome thank you congrats with 200k subscribers!

  • @tosh_media39
    @tosh_media39 2 ปีที่แล้ว

    Appreciate it man...Thumps up

  • @durgabadarwada9470
    @durgabadarwada9470 4 หลายเดือนก่อน

    Can you please send the program in comments so that I can copy and then paste it in the java program, please can anybody do this for me

  • @prohiestcontent8907
    @prohiestcontent8907 ปีที่แล้ว

    It is vey complex but fun

  • @thekoalabear6580
    @thekoalabear6580 9 หลายเดือนก่อน

    would it not be better to throw an IllegalArgumentException instead of system.out.println("playermove + ""its not a valid move ") ?

    • @doggo4
      @doggo4 5 หลายเดือนก่อน

      No because that it's telling you that that is not a valid move and this tutorial is for new people in java and so that will probably not know what a Exception is.

  • @AirCrinkly
    @AirCrinkly 3 ปีที่แล้ว +1

    This man is so Underrated! Instead of going to coding school It's better to learn from this guy! It's so fun and easy while coding schools take so much money and It's hard.
    (That's my opinion)

    • @AirCrinkly
      @AirCrinkly 3 ปีที่แล้ว

      Eyyy thanks for hearting it!!!

  • @PersonPerson-vh2nc
    @PersonPerson-vh2nc 5 หลายเดือนก่อน

    tysm now i can add this to my portfolio and I'm going to show this off to my friends...
    @Coding With John - ur a great teacher and coder - make more videos pls - I would like to add this for my high school or uni profile

  • @rexcoyagbo2054
    @rexcoyagbo2054 2 ปีที่แล้ว

    Thanks this video that gived me a knowledge but Sr please explain why we used those code??? Because I dont ko all your explainations,,,,for all codes only please

  • @materjoby5092
    @materjoby5092 10 หลายเดือนก่อน

    wow, i have a project due for this in my java, it's not the same but it is similar. Overall you teach this so well. I understood each step. Be a professor bro.

  • @MortenPeterHaghJensen
    @MortenPeterHaghJensen 2 ปีที่แล้ว +1

    Amazing tutorial! I have learned more about Java from a few of your videos than from reading multiple articles, other Java videos, and even a 4 days on-site Java course! So thank you!
    An idea for a revisit of the video is to make a sleep (1 second) iteration like "1-2-3 GO!" and a scoring board! :)

  • @franzsanico8381
    @franzsanico8381 11 หลายเดือนก่อน

    how to find missing bracket? I can't run my code due to this issue

  • @ssamu756
    @ssamu756 11 หลายเดือนก่อน

    you should put the random outside while loop so the computer will not always move rock

  • @shoaibaltaf705
    @shoaibaltaf705 3 ปีที่แล้ว

    You are great my dear

  • @rdxdevil5083
    @rdxdevil5083 ปีที่แล้ว +1

    java is literally very hard, i don't know why most of the peoples like java even it have most complex syntax you see python how much it's easy to create syntax and other working

    • @doggo4
      @doggo4 5 หลายเดือนก่อน

      For me (A java coder) I find java easy but i get your point in python being easy in syntax.

  • @anilsevincc
    @anilsevincc 3 หลายเดือนก่อน

    BRO MADE IT SO EASY THAT I EMBARRASSED MYSELF

  • @nuratikahkamaruzzaman5570
    @nuratikahkamaruzzaman5570 2 ปีที่แล้ว

    if i want to put the computer and player have 3 health then if one of player finish health game over the health i should store in array or no need?

  • @delpepitozipepit1010
    @delpepitozipepit1010 2 ปีที่แล้ว

    You are the best, but I have a question for the last scanner why u dont use scanner.nextChar if we only write only y or n

  • @crowlovercicada
    @crowlovercicada 9 หลายเดือนก่อน

    SUPER GOOD VIDEO!! noise at the end goes bonkers

  • @anubhavtrivedi1283
    @anubhavtrivedi1283 3 ปีที่แล้ว

    Make video on asymptotic notation

    • @CodingWithJohn
      @CodingWithJohn  3 ปีที่แล้ว +1

      Hi YOURTUBE! I do see and appreciate your comments. Right now though I think something as complex as asymptotic notation is just on a bit of a higher level than I'm looking to make on the channel. There are certainly a few more seasoned programmers that watch, but I've found that the majority of viewers to the channel are just starting out with Java or even just starting with programming in general, so the videos for now tend to be for a solid, good understanding of basic concepts or full walkthroughs of small practice coding projects. I'll very likely get to those more complex topics in the future, but I think it will likely be a while before that stage.

  • @garethireson9155
    @garethireson9155 ปีที่แล้ว

    Hi John. I'm finding your videos incredibly easy to understand and follow along to. I have followed this and got a working Rock Paper Scissors game which I'm so super happy about considering i'm only a matter of weeks into my Java journey.
    I have one problem though. The scanner.close(); throws up an error and says cannot resolve symbol 'scanner' and expected. Why is this happening? the game functions fully without an error if scanner.close() is deleted/commented out.

  • @evanserickson
    @evanserickson 2 ปีที่แล้ว

    Why are you using curly brackets on line 6. Can you not use brackets for an array like in JS?

  • @zxlightning1
    @zxlightning1 7 หลายเดือนก่อน

    dude i didnt even know u can use while that why i keep losing my mind 💀my code used if else with boolean i almost correct but not the if else code

    • @doggo4
      @doggo4 5 หลายเดือนก่อน

      Yes the improved use thing JFrame,

    • @zxlightning1
      @zxlightning1 5 หลายเดือนก่อน

      @@doggo4 i didnt learn JFrame yet

  • @Poker_Dame
    @Poker_Dame 3 ปีที่แล้ว

    This video is a great help but I was wondering how you can implement a 2 out of 3 system with you vs the computer, can anyone help me out?

  • @kajalwankhede5214
    @kajalwankhede5214 2 ปีที่แล้ว

    There is one problem in code. Computers move is same until you did not run the code again. When you again run the program only that time computers move is changed. I tried lots of try but it did not resolve. Can anyone help me out

    • @kajalwankhede5214
      @kajalwankhede5214 2 ปีที่แล้ว

      My code is here:-
      Scanner sc = new Scanner(System.in);
      String var, q, quit = "QUIT", play = "PLAY";
      String[] ah = {"S","P","R"};
      String rs=ah[new Random().nextInt(ah.length)];
      System.out.println("Welcome a game ROCK, PAPER, SCISSORS");
      System.out.println("Enter 'R' for Rock, 'P' for Paper, 'S' for Scissors ");
      while (true) {
      System.out.println("Just Enter QUIT or PLAY");
      q = sc.next();
      if (q.equals(quit)) {
      System.out.println("Thanks for playing Rock, Paper, Scissors!");
      break;
      }
      else
      {
      System.out.print("Your choice:- ");
      var = sc.next();
      System.out.println("System Choose :- " + rs);
      if (var.equals(rs)) {
      System.out.println("DRAW");
      } else if (var.equals("P") && rs.equals("R") || var.equals("R") && rs.equals("S")
      || var.equals("S") && rs.equals("P")) {
      System.out.println("!!!YOU WIN!!!");
      } else {
      System.out.println("!!!System WIN!!!");
      }
      }
      }

  • @theviper5069
    @theviper5069 2 ปีที่แล้ว

    I need help John, I couldn't import java.util.Random package.
    it says I have to create a new class for that Random
    someone help me

    • @doggo4
      @doggo4 5 หลายเดือนก่อน

      Just use:
      import java.util.*;
      to import everything (including java.util.Random) in java.util

  • @YobeOllipse
    @YobeOllipse 2 ปีที่แล้ว

    How can I make a validation for that yes or no at the end sir? uhmm btw thank you for the tutorials!

  • @Ricolicious66
    @Ricolicious66 หลายเดือนก่อน

    hello everyone, i realize its an old video, but can anyone explain the "symbols he uses around 3:48 when he says "or". I´ve googled abit but cant seem to find it

    • @ymo_o
      @ymo_o 20 ชั่วโมงที่ผ่านมา +1

      ım not sure if you find or not but its being used to tell "or" || also this is "and" &&

    • @Ricolicious66
      @Ricolicious66 20 ชั่วโมงที่ผ่านมา

      @@ymo_o Thanks! I've started my studies shortly after commenting, so ive got the idea:)

  • @SuperPeteTV
    @SuperPeteTV 2 ปีที่แล้ว

    if people understand this then they don't need this video at all

  • @bhaweshpandey4306
    @bhaweshpandey4306 2 ปีที่แล้ว +1

    Now it's looks easy, thanks man🤘

  • @dadianacanales4394
    @dadianacanales4394 2 ปีที่แล้ว

    Thank you! This video really helps. Can you try Math Functions/Strings/Characters - LottoTexas java? Also a Loops - Math Tutor? I'm really having issues understanding this. Thank you for your videos!

  • @jasminazahirovic3901
    @jasminazahirovic3901 2 ปีที่แล้ว

    hi, thank u so much for the video! as a part of my programming course i got an assignment to programm a rock paper scissors game, but without Random() objects aka functions. what we need to do is to create a linear congruential generator with a cycle from 0 to 2 with a help of an equation and then restrict the cycle with a while loop. any ideas or tipps on how i can implement this? thank u :)

  • @johnnys3501
    @johnnys3501 2 ปีที่แล้ว

    My professor told us to only use "break" in a switch statement. Thoughts?

    • @CodingWithJohn
      @CodingWithJohn  2 ปีที่แล้ว +1

      You do need to use break in most switch statements, but I think it's silly to say it's the only place you should use them. They're incredibly useful in loops and often the best way to do what you want to do in a clean way.

  • @Cinemachoicefilms
    @Cinemachoicefilms 2 ปีที่แล้ว

    Thanks a million this will aide me in my Java class im taking this semester.

  • @teemolol3075
    @teemolol3075 4 หลายเดือนก่อน

    if (playerMove.equals(computerMove)) {
    System.out.println("Tie!");
    } else if (playerMove.equals("r") && computerMove.equals("s") ||
    playerMove.equals("p") && computerMove.equals("r") ||
    playerMove.equals("s") && computerMove.equals("p")) {
    System.out.println("You win!");
    } else {
    System.out.println("You lose!");
    }

  • @computer_gyata_9984
    @computer_gyata_9984 ปีที่แล้ว

    This will be my first game in java

  • @vedd2603
    @vedd2603 3 ปีที่แล้ว

    I didn't understand the 11th line code it's way too fast, could you explain what is rps[ ]

    • @CodingWithJohn
      @CodingWithJohn  3 ปีที่แล้ว +3

      Sure! Here are the relevant lines you're talking about:
      String[] rps = {"r", "p", "s"};
      String computerMove = rps[new Random().nextInt(rps.length)];
      This is all just to get a random move (rock, paper, or scissors) for the computer. To do that, I just created an array of Strings, with 3 values, "r", "p", and "s".
      Then on the next line, I'm getting a random element from that array, to use as the computer's move.
      rps.length returns 3 (the array has 3 items in it).
      new Random(someNumber) returns a random int between 0 and one less than the someNumber you pass in. So in this case, it would give us a random int between 0 and 2, since rps.length is 3. We use that random number as the index of the array to retrieve a random computer move.
      Since the random number could be 0, 1, or 2, the computer move could be:
      rps[0], which is "r" for rock
      rps[1], which is "p" for paper, or
      rps[2], which is "s" for scissors.

  • @HKEDITZ08
    @HKEDITZ08 4 หลายเดือนก่อน

    Thanks ❤

  • @SaamerAI
    @SaamerAI ปีที่แล้ว

    wow that was a really good video!

  • @roughgrass1212
    @roughgrass1212 3 ปีที่แล้ว

    about at 9:40, why we should closed scanner?
    is it important!*-*

    • @CodingWithJohn
      @CodingWithJohn  3 ปีที่แล้ว +2

      Good question! It's definitely best practice to always close your Scanners. For very small programs like this, it probably won't actually cause problems if you don't so it's easy to overlook. But if it's not explicitly closed, what can happen is that Java will keep that resource open and available when it doesn't have to. That's called a resource leak. It takes up resources that could be available to other parts of the program or the computer. So in a large program with a lot of sources of resource leak, it can start to cause problems with Java not having enough resources to do what it needs to do.
      For that reason, it's best to get in the habit of closing them. Plus, closing it gets rid of the warning in the IDE!

    • @luisriveragonzalez9052
      @luisriveragonzalez9052 2 ปีที่แล้ว

      @@CodingWithJohn Is this because closing it frees up more memory?

  • @gverweijen
    @gverweijen 3 ปีที่แล้ว

    There is a lot of repetition here. How would you refactor this?

    • @CodingWithJohn
      @CodingWithJohn  2 ปีที่แล้ว

      That's an interesting question - There's a lot of repetition of single lines that just print out who wins. There's probably a clever way to refactor all those "if"s to get fewer lines, but the ways I can think of would make the code more confusing.
      One thing you could do, if you wanted to not repeat the "print" lines, would be to instead have some kind of boolean for whether the player has won and initialize it to false:
      playerWins = false;
      Then you can check for just the situations where the player wins, and set it to true. Then you can print whether the player wins at the very end. Something like this:
      if (playerMove.equals(computerMove)) {
      System.out.println("The game was a tie!");
      }
      else {
      boolean playerWins = false;
      if (playerMove.equals("r")) {
      if (computerMove.equals("s")) {
      playerWins = true;
      }
      }
      else if (playerMove.equals("p")) {
      if (computerMove.equals("r")) {
      playerWins = true;
      }
      }
      else if (playerMove.equals("s")) {
      if (computerMove.equals("p")) {
      playerWins = true;
      }
      }
      if (playerWins) {
      System.out.println("You win!");
      }
      else {
      System.out.println("You lose!");
      }
      }
      I'm not sure this is better since it seems a bit harder to understand what's going on. But it does remove a couple of "if" checks and doesn't repeat the print statements anymore.
      Let me know if you have a better way, I'd be interested to see it!

  • @xXGlitchBoyXx
    @xXGlitchBoyXx 2 ปีที่แล้ว

    hi john,
    how can i make a win/lose counter for user and pc?

    • @doggo4
      @doggo4 5 หลายเดือนก่อน

      I know I am not john but here is an example:
      int plyrWin = 0;
      int plyrLoose = 0;
      //when the player has won
      //just adds one to the plyrWin variable
      plyrWin++;
      //when the player has lost
      //just adds one to the plyrLoose variable
      plyrLooser++;

  • @blueflamegaming7591
    @blueflamegaming7591 3 ปีที่แล้ว

    Thank u so much for this tutorial this is so perfect for beginners out there just like me and it only took me like about 15 or something but it is really easy so thank u again

    • @CodingWithJohn
      @CodingWithJohn  3 ปีที่แล้ว

      You're very welcome! If you have another simple beginner Java program I might cover here on the channel let me know! These kinds of programs don't take long to make, but to a beginner they can make you feel very empowered, being able to create something interactive like this.

  • @vedd2603
    @vedd2603 3 ปีที่แล้ว

    you could also put in the order (else if, if, else) right?

    • @CodingWithJohn
      @CodingWithJohn  3 ปีที่แล้ว +2

      You can check the various conditions in whichever order you like, but your if/else if/else checks always must be in that order. You can have "else if" first, since that doesn't make sense.
      You'll always have exactly one "if" first:
      if ( whatever ) {
      }
      That might be all you need. But if you need any "else"s, you can have
      0 or more else ifs:
      else if ( whateverElse) {
      }
      then exactly 1 else, again, only if needed:
      else {
      }
      These can be nested of course, which complicates things, but each layer of if/else nesting has to have that same kind of structure.

  • @Jeremy-m8r
    @Jeremy-m8r 9 หลายเดือนก่อน

    Can anybody one explain me the random and length plij

    • @doggo4
      @doggo4 5 หลายเดือนก่อน

      The random picks a random value from the rps array, and the length gets the length of the rps array. If you don't know what arrays are, they are variables that contain multiple values, kinda like a string with pieces of paper all along it, in which have different values.

  • @poe12
    @poe12 ปีที่แล้ว

    Should be "Play again? (y/any_other_key)"...

  • @tallswede80
    @tallswede80 ปีที่แล้ว

    what are you using as an ide?

    • @CodingWithJohn
      @CodingWithJohn  ปีที่แล้ว

      Eclipse in this video, intellij for a while now though

  • @drazzo777cod7
    @drazzo777cod7 ปีที่แล้ว

    Like soo many years of experience he has and this guys took 10 minutes to make a stupid game like this 😐nice

  • @EnriqueMoranG
    @EnriqueMoranG 2 ปีที่แล้ว

    I love your videos bro!

  • @ineshverma2666
    @ineshverma2666 2 ปีที่แล้ว

    THanks a lot!!

  • @shantiniselvam5879
    @shantiniselvam5879 ปีที่แล้ว

    is this java code for programming 1

    • @CodingWithJohn
      @CodingWithJohn  ปีที่แล้ว

      Well it's a good coding exercise for beginners, if that's what you mean

  • @wardy1989
    @wardy1989 ปีที่แล้ว

    what kind of app are you using?

    • @CodingWithJohn
      @CodingWithJohn  ปีที่แล้ว

      I'm using Eclipse here to write the program

    • @wardy1989
      @wardy1989 ปีที่แล้ว

      @@CodingWithJohn I use it too but there's a red "x" show side at the number even though there's nothing wrong and I can't run the code.

  • @JanetNapiza
    @JanetNapiza 2 ปีที่แล้ว

    How to make this in python?

    • @doggo4
      @doggo4 5 หลายเดือนก่อน

      This is a java channel, not a python channel, so you can research python yourself and try to convert the java code into python code.

  • @shekhardhami6831
    @shekhardhami6831 3 ปีที่แล้ว +3

    ❤️🎉

  • @jeremyrubio1531
    @jeremyrubio1531 2 ปีที่แล้ว

    What I did with this program is I assign it as (scissors as 1 , rock as 2 , paper as 3)
    then just use if statement that will evaluate the if(playersChoice > computersMind)
    You win!.. if( same) then draw , else you lose..
    if I choose 2 (rock) , and the random value pick 1(scissors) then mine is greater than the computer therefore I win. thats what I did with my program.
    Okay this program is wrong lol. Don't listen to this idea 🙏 it got corrected already.

    • @CodingWithJohn
      @CodingWithJohn  2 ปีที่แล้ว +1

      With your rules, doesn't that mean paper would beat scissors, since 3 > 1?
      It sounds like the logic might look simpler, but not actually work how it should.

    • @jeremyrubio1531
      @jeremyrubio1531 2 ปีที่แล้ว

      @@CodingWithJohn Ow ! I see thanks for that correction, I thought I was doing fine there. Sorry I'll do better next time 🙏

    • @CodingWithJohn
      @CodingWithJohn  2 ปีที่แล้ว

      No worries at all! That section of the code is a bit weird, so I'm very open to ideas about cleaning up that logic. Just remember to test thoroughly!

  • @just_aguy999
    @just_aguy999 3 ปีที่แล้ว

    How would you implement a way to keep track of the scores?

    • @CodingWithJohn
      @CodingWithJohn  3 ปีที่แล้ว +9

      Good question. What you could do is have a variable for the number of player wins, and number of computer wins, declared just outside of the outer while loop (by the Scanner declaration):
      int playerWinCount = 0;
      int computerWinCount = 0;
      Then, in each "if" where the player wins, increment playerWinCount by 1:
      playerWinCount++;
      And in each "if" where the computer wins, increment computerWinCount by 1:
      computerWinCount++;
      So that will keep track of the scores, but you probably want to actually print out the scores too. A good place is probably right after all the "if/else" checks, and just before the "Play again?" print out. It could be something like:
      System.out.println("Current score");
      System.out.println("Player: " + playerWinCount);
      System.out.println("Computer: " + computerWinCount);

  • @ildemonedelladiarrea1965
    @ildemonedelladiarrea1965 ปีที่แล้ว

    Proco Dio mondiali calcio 2022

  • @dominiksycha7994
    @dominiksycha7994 5 หลายเดือนก่อน

    I failed. kurwa