Building a Guessing Game | Java | Tutorial 20

Поделиться
HTML-код
  • Опубликовано: 19 окт 2024

Комментарии • 44

  • @nathansmart5226
    @nathansmart5226 4 года назад +11

    Been on and off coding for years. You've literally made me understand everything i couldn't pick up as well so easily :)

  • @geenade5294
    @geenade5294 5 лет назад +11

    BROOOOO thank you ! saved me a boat load of time on my homework assignment! Keep it up!

  • @angieg7257
    @angieg7257 3 года назад +1

    Good example of a beginner game to program.

  • @Kickflips22
    @Kickflips22 3 года назад +1

    I paused the video before you set up the "lose" condition to see if I could figure it out, it works but I came up with something different and I'd like to know if there is any practical difference. While it functions the same, is the way I have it less efficient or does it matter? Here's where it differs:
    while(!guess.equals(secretWord)) {
    if(guessCount < guessLimit) {
    System.out.print("Enter a Guess: ");
    guess = keyboardInput.nextLine();
    guessCount++;
    }else {
    outOfGuesses = true;
    System.out.println("You lose :P");
    break;
    }
    }
    if(guess.equals(secretWord)) {
    System.out.println("You Win!");
    }
    P.S.
    This is my first time coding and your teaching style has made it so easy to grasp thank you!!

  • @milandave9735
    @milandave9735 6 лет назад +2

    oh man!!! you are genius........
    so easy to understand....
    thanks for explanation

  • @thelawgameplaywithcommenta2654
    @thelawgameplaywithcommenta2654 2 года назад

    I did it slightly differently. I put the if statement outside and after the loop, It's looking for if the guessCount

  • @Future12294
    @Future12294 5 лет назад +8

    I made some minor changes to the code so that the user guesses are not cap-sensitive and I decided to not used booleans as it confused me but the user still gets 3 guesses
    public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    String secretWord = "cowboys";
    String guess = "";
    int guessCount = 0;
    int guessLimit = 3;
    while (!guess.equals(secretWord)) {
    if (guessCount < guessLimit) {
    System.out.print("Enter a guess: ");
    guess = input.nextLine();
    guess = guess.toLowerCase();
    guessCount++;
    if (guessCount == guessLimit) {
    System.out.println("Out of guesses, You lose!");
    }
    }
    }
    System.out.println("You Win!");
    }
    }

  • @hakirawr964
    @hakirawr964 3 года назад

    THANK YOU VERY MUCH!!! my grades have hope now, because of you!

  • @halaramimido
    @halaramimido Год назад

    for the guess limit, could you also put the while loop inside a for loop that is = to the guess limit?

  • @dishabanerjee_chair6583
    @dishabanerjee_chair6583 4 года назад

    The only place I look for Computer Project solutions😁😁😁😁

  • @immer2470
    @immer2470 4 года назад +1

    What if i want to create 2 options:
    1.with no limited attempts
    2.with limited attempts
    ????

  • @norbertkulacin272
    @norbertkulacin272 6 лет назад +3

    wow amazing example, thanks so much!!!!

  • @tonydalov
    @tonydalov 6 лет назад +2

    Awesome explanation! Thanks

  • @yohohoyo5639
    @yohohoyo5639 5 лет назад +2

    Really great content, THANK YOU!

  • @itspossible5920
    @itspossible5920 4 года назад

    Simple and easy to understand. Thanks

  • @zoilavaca7015
    @zoilavaca7015 5 лет назад +4

    How can I add a list of words so that the "secret word"grabs a word from that list , and how can I validate that the user only uses strings when they are guessing ? Thanks from a noob 8)

    • @zoilavaca7015
      @zoilavaca7015 5 лет назад +1

      The list I want to add is in a .txt file - my guess is to import it? because there are too many words to make an array... Hope to hear from you soon! :)

    • @pritamdavis
      @pritamdavis 4 года назад +1

      @@zoilavaca7015 The game here is a very simple game... And that's the point of this tutorial. It's for explaining the concept of loop using a simple game. But if you still want to do it anyway, what you should do is:
      1. Read a .TXT file and convert it into an ArrayList of words
      2. Set the secretWord to a random word from the ArrayList

  • @joshuatruelen3908
    @joshuatruelen3908 4 года назад +1

    How could you add total score? For example you make 5 questions and it takes correct answer and it print (you got 3 out of 5) etc....

    • @pritamdavis
      @pritamdavis 4 года назад

      Make a int variable score, and each time the user gets a correct answer increase it by one... Then at last print the score

  • @chifuyu7902
    @chifuyu7902 3 года назад

    I made a different code but with same basics and here it is:
    import java.util.Scanner;
    public class game{
    public static void main (String[]args){
    Scanner sc = new Scanner (System.in);
    String SecretWord ="giraffe";
    String guess="";
    int count=0;
    while(!guess.equals(SecretWord)) {
    System.out.println("Enter a guess");
    guess= sc.nextLine();
    count++;
    if(guess.equals(SecretWord)){
    System.out.println("You Win!!");
    }else if(count==3){
    System.out.println("It is an animal");
    }else if(count==6) {
    System.out.println("This animal lives in forest");
    }else if(count==8){
    System.out.println("Hey loser!");
    break;
    }
    }
    }
    }

  • @mooncakeplaylist
    @mooncakeplaylist 3 года назад +1

    why won't it work for me?

  • @jedcatapang4917
    @jedcatapang4917 2 года назад

    what application is this?

  • @salonipatel7834
    @salonipatel7834 4 года назад

    how to add point for giving right answer and deduct point for wrong guess

  • @khfir6209
    @khfir6209 3 года назад

    Why didn’t you import random ?

  • @kishorkumar-ue9lj
    @kishorkumar-ue9lj 3 года назад

    Thank you so much for these exercises 💪

  • @PeiqiLi-RealLove
    @PeiqiLi-RealLove 4 года назад +3

    I just heard a dog barking Lol 7:48

  • @rusty6460
    @rusty6460 3 года назад

    coming from c++ basics, this is hell

  • @SaiKrishna-qp9jn
    @SaiKrishna-qp9jn 6 лет назад +1

    You are a genius

  • @aadyamehra4146
    @aadyamehra4146 4 года назад

    Thanks a lot!!!
    It was so useful

  • @iftakerahmed4263
    @iftakerahmed4263 5 лет назад

    How can i add hints?

  • @Yukino965
    @Yukino965 3 года назад

    Thank you so much

  • @freesauce7842
    @freesauce7842 3 года назад

    it says some are error

  • @shahrzadalbertsson9779
    @shahrzadalbertsson9779 5 лет назад

    Oh Thanks! :)

  • @NoNo-ud8zw
    @NoNo-ud8zw 3 года назад

    Thanks IDOL

  • @flashmash7051
    @flashmash7051 4 года назад

    You just did my homework for me 🤧🤧❤️❤️❤️❤️thank you

  • @LT5Production
    @LT5Production 4 года назад +1

    great - this is my code :)
    import java.util.*;
    public class Guessing_Game {
    public static Scanner input=new Scanner(System.in);
    public static void main(String[] args) {
    String question="SHE HAS BROWN HAIR & CURLLY HAIR, BROWN EYES,WHO IS SHE ? ";
    System.out.println(question);
    String guess="carmit";
    String SecretWord=input.nextLine();
    int i=3;
    while(!guess.equals(SecretWord) && i>=0) {

    System.out.println("You have another "+i+" guesses to guess");
    System.out.println("try again");
    SecretWord=input.next();
    i--;
    }
    if(i>=0) {
    System.out.println("you are right");}
    else
    System.out.println("you lose");
    }
    }

  • @tanasisyanev3760
    @tanasisyanev3760 6 лет назад +6

    he wrote 30line code and he said this was a lot of code in the program ? lol

    • @Future12294
      @Future12294 5 лет назад +2

      Well this is for beginners and this vid has the most code written in it so far of all the tutorials so yeah