I am new to programming and I am not sure what to do next? Any ideas?

I am new to programming and I am not sure what to do next? Any ideas?

import java.util.*; public class HangMan2 { char guess; String userInputs; static Scanner scan = new Scanner(System.in); static Random rand = new Random();

    // The following routine will determin if the character c
    // is inside the String str.  A true is returned if it is inside.

    static boolean isIn(char c, String str)
    {

        if(str.length()==0)
            return false;

        for(int i=0;i<=str.length();i++)

            if (c==str.charAt(i));
        return true;
    }

    // If userInputs contains "ard" and strToGuess contains "aardvark" then
    // the following routine prints out an output that looks something like:
    //
    // Current Status for userInpts=ard
    // a a r d _ a r _

    // This routine returns true if all letters were guessed, otherwise false is returned.


    static boolean printCurrStatus(String strToGuess, String userInputs){


        char guess = userInputs.charAt(0);

           if(isIn(guess, strToGuess)==true){

            strToGuess = "";
            char current;
            for (int i = 0; i < strToGuess.length(); i++)
            {
            current = strToGuess.charAt(i);
            if (current == '_' || current == ' ') 
            {
                strToGuess = strToGuess + "_";
            }
            else
            {
                strToGuess = strToGuess + current;
            }

            }
            return true;

            }
            else 
                return false;
    }




    // The following routine will return a random String from the list of words:
    // elephant, tiger, monkey, baboon, barbeque, giraffe,  simple, zebra, 
    // porcupine, aardvark

    static String getNextWordToGuess()
    {

             Random generator = new Random();
              String[] array  = { "aardvark","porcupine","zebra","simple","giraffe","barbeque","baboon", "monkey","tiger","elephant"};
              int rnd = generator.nextInt(array.length);

              return array[rnd];




        //********** Fill in Details
        // HINT: a switch statement can be quite useful here
    }

    // The following routine plays the hangman game. It calls getNextWordToGuess to
    // get the word that should be guessed.  It then has a loop which outputs the 
    // following prompt:
    // Enter next letter
    //
    // A String named userInputs stores all letters selected already.  
    // Then the routine printCurrStatus is called to print out the current status of
    // the guessed word.  If printCurrStatus returns true, we are done.

    static void playGame()
    {  
        boolean current=false;
        String word = HangMan2.getNextWordToGuess();

    String userInputs;

        do{
            System.out.println("Hello, and welcome to Hangman!");
                System.out.println("Enter next letter");
                userInputs= scan.next(); 
                current= HangMan2.printCurrStatus(word,userInputs);
        }while(printCurrStatus(word, userInputs)==true);

    }

//********** Fill in Details


// main will call playGame to play the hangman game.
// Then main will issue the prompt:
// Do you want to play again (y or n)
// If the answer is "y", then call playGame again, otherwise exit

public static void main(String[] args)
{
    playGame();
    String retry_ans;
      boolean retry= true;


    System.out.println("Would you like to try again?");
    retry_ans = scan.next();
    if(retry_ans.equalsIgnoreCase("yes"))
    {
        retry = true;
        System.out.println("Please enter a new secret word:");
        String newWord = scan.next();
        HangMan2.getNextWordToGuess();

    }
}
}
View Answers









Related Tutorials/Questions & Answers:
I am new to programming and I am not sure what to do next? Any ideas?
Not sure what I am missing ? Any ideas?
Advertisements
I am new to ML/AI. Where do I start learning?
How do I start machine learning with Python? What should I do if I am a beginner?
How do I start machine learning if I am a beginner in the programming language?
How do I do this program? I'm new to Java programming...
Hi i am new to J2ee Technology and struts - Struts
I am getting this exception
I am good in programming. Can I make career in Big Data and Hadoop?
ModuleNotFoundError: No module named 'will-i-am'
I am new to java applets. When i run this code on applet viewer status is displayed that applet not initialized
i am Getting Some errors in Struts - Struts
:( I am not getting Problem (RMI)
How do I learn Java programming in one day from zero?
How do I learn Java programming in one day from zero?
What skills do I need to be a data analyst?
What skills do I need for machine learning?
I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, what’s the problem?
I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, what’s the problem?
I am trying to develop a Image Sliding application but unfortunately its not working... Can any one help me in this
i am confused here on what to write can some 1 help out here - Java Beginners
I am beginner and want to learn Java fast
I am beginner and want to learn Java fast
ModuleNotFoundError: No module named 'i-am-malicious'
ModuleNotFoundError: No module named 'Sam_I_Am'
ModuleNotFoundError: No module named 'i-am-utils'
ModuleNotFoundError: No module named 'Sam_I_Am'
ModuleNotFoundError: No module named 'i-am-malicious'
what is java and why do i need it?
Find a project or skill I am interested in learning
i am getting multiple values in listbox
I am from .net background, I want to learn SOA.
what should i do next?? - Java Beginners
What do I need to do to use a MSSQL-Server with Web-Harvester?
I am Java programmer. Should I learn Java Script or Python?
i am unable to identify the error in my code
i am unable to identify the error in my code
Am i convetrting the code right ? - Java Beginners
Where can I learn R programming in New Delhi?
Where can I learn R programming in New Delhi?
I am getting error.How can i get details
i am getting the problem when i am downloading the pdf file from oracle 10g database - Struts
unable to display image using html tag in servlet.(image src is in a variable.....). i am using netbeans IDE. plz..........do help
Hi ..I am Sakthi.. - Java Beginners
Java web development, what skills do I need?
Java web development, what skills do I need?
What changes I have to do in php.ini file for file uploading?
I am having problem with configuring Hibernate sessionfactory. Please Help
i am getting an error in adding a menu item to a menu.
How can I access databse through JSP. I am using postgresql-8.4.4-1-windows as database and jboss-4.0.5.GA as server.

Ads