10 Replies - 3872 Views - Last Post: 21 August 2012 - 09:34 PM Rate Topic: -----

#1 mrprogrammer14  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 21-August 12

Typing Game Problem Here!

Posted 21 August 2012 - 04:26 AM

Hey guys!!! I'm making a typing game for my sister and i need some help from you guys. I have some problems making the next word appear after you get the first one. And can also help me guys on how to put a 2 minute timer? Here's the code:
import java.util.Random;
import java.util.Scanner;

public class Easy {
    
    public static void main (String []args){
        
        String words[]={"Love", "Hate", "Truth", "Happy", "Pressure", "Burp", "Vampire"
        , "Surf", "Believe", "Slime", "Dream", "Religion", "Rhythm", "Disco", "Honey",
        "Star", "Armies", "Zombie", "Heart", "Break", "Docks", "Multiply", "Mace", "Moustache"
        , "Wizards", "Sports", "Blind", "Riddle", "Business", "School", "Blood", "Promenade",
        "Vault", "Spray", "Eternal", "Dress", "Abstain", "Controls", "Circuit", "Forever",
        "Dangerous", "Skunk", "House", "Wives", "Flashlight", "Console", "Awesome", "Scared",
        "Hormones", "Promise", "Angel", "Baggage", "Duck", "Destroy", "Tissue", "Ketchup",
        "Picture", "Basket", "Basketball", "Fan", "Dough", "Thief", "Female", "Family", "Normal",
        "Wireless", "Empty", "Cycles", "Banana", "Eggplant", "Samba", "Jumble", "Flush", "Beach",
        "Driver", "Queen", "Mommy", "Fade", "Kitten", "Spring", "Interest", "Debts", "Horse",
        "Tomorrow", "Discount", "Faithful", "Midnight", "Epic", "Calendar", "Roses", "Funeral",
        "Badminton", "Spirit", "Water", "Pizza", "Science", "Cabinet", "Apple", "Television",
        "Profile", "Wine", "Sedan", "Luxury", "Firewall", "Computer", "Tablet", "Giraffe", "Ring",
        "Shut", "Vision", "World", "War", "High", "School", "Fantasy", "Warfare", "Incognito",
        "Loading", "Penguins", "Fright", "Night", "Diary", "Mega", "Submit", "Hold", "Statue",
        "Boat", "Mobile", "Invisible", "Visible", "Ground", "Space", "Dragon", "Spade", "Clover",
        "Senior", "Junior", "Sophomore", "Freshman", "Twilight", "Dawn", "Eclipse", "Moon",
        "Hair", "Spray", "Camp", "Jazz", "Rock", "Eggs", "Hustle"};
        
       Scanner sc = new Scanner(System.in); 
       Random a = new Random();
       int roll = a.nextInt(149);
       String type = "";
       String reply = "yes";
       int error = 0;
       
       System.out.println(words[roll]);
    
    while (!reply.equalsIgnoreCase("no")){
    	if (!reply.equalsIgnoreCase("yes"))
    		System.out.println("Yes and No are the only acceptable answers");
    	
    	else {
    		System.out.println("Type the word");
    		
    		
    		
    		
    		while (!type.equals(words[roll])){
    			type = sc.next();
    			try {
    				if (!type.equals(words[roll])){
    					System.out.println("Type again");
    					error++;
    					}
    				else {
    					if (!type.equals(words[roll]))
    					System.out.println("next word");
    					      
    				}
    					
    			}catch(Exception e){
    				
    				System.out.println("lallalala");
    			}
    			
    		}
    	}
    	type = "";
		System.out.println("Would you like to play again? Yes/No");
		reply = sc.nextLine();
		roll = a.nextInt(149);
		
		
		
    }
    System.out.println("Thank you for playing");
    }
}


Hope you'll be able to help me ASAP because her birthday is already fast approaching. Thanks :)

Is This A Good Question/Topic? 0
  • +

Replies To: Typing Game Problem Here!

#2 ILoveJava  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 389
  • Joined: 12-March 12

Re: Typing Game Problem Here!

Posted 21 August 2012 - 05:36 AM

Moving the word call just above "Type the word" fixes your problem. Now your problem is that prompting for a yes/no appears twice.
import java.util.Random;
import java.util.Scanner;

public class Easy {

    public static void main (String []args){

        String words[]={"Love", "Hate", "Truth", "Happy", "Pressure", "Burp", "Vampire"
        , "Surf", "Believe", "Slime", "Dream", "Religion", "Rhythm", "Disco", "Honey",
        "Star", "Armies", "Zombie", "Heart", "Break", "Docks", "Multiply", "Mace", "Moustache"
        , "Wizards", "Sports", "Blind", "Riddle", "Business", "School", "Blood", "Promenade",
        "Vault", "Spray", "Eternal", "Dress", "Abstain", "Controls", "Circuit", "Forever",
        "Dangerous", "Skunk", "House", "Wives", "Flashlight", "Console", "Awesome", "Scared",
        "Hormones", "Promise", "Angel", "Baggage", "Duck", "Destroy", "Tissue", "Ketchup",
        "Picture", "Basket", "Basketball", "Fan", "Dough", "Thief", "Female", "Family", "Normal",
        "Wireless", "Empty", "Cycles", "Banana", "Eggplant", "Samba", "Jumble", "Flush", "Beach",
        "Driver", "Queen", "Mommy", "Fade", "Kitten", "Spring", "Interest", "Debts", "Horse",
        "Tomorrow", "Discount", "Faithful", "Midnight", "Epic", "Calendar", "Roses", "Funeral",
        "Badminton", "Spirit", "Water", "Pizza", "Science", "Cabinet", "Apple", "Television",
        "Profile", "Wine", "Sedan", "Luxury", "Firewall", "Computer", "Tablet", "Giraffe", "Ring",
        "Shut", "Vision", "World", "War", "High", "School", "Fantasy", "Warfare", "Incognito",
        "Loading", "Penguins", "Fright", "Night", "Diary", "Mega", "Submit", "Hold", "Statue",
        "Boat", "Mobile", "Invisible", "Visible", "Ground", "Space", "Dragon", "Spade", "Clover",
        "Senior", "Junior", "Sophomore", "Freshman", "Twilight", "Dawn", "Eclipse", "Moon",
        "Hair", "Spray", "Camp", "Jazz", "Rock", "Eggs", "Hustle"};

       Scanner sc = new Scanner(System.in);
       Random a = new Random();
       int roll = a.nextInt(149);
       String type = "";
       String reply = "yes";
       int error = 0;

    while (!reply.equalsIgnoreCase("no")){
    	if (!reply.equalsIgnoreCase("yes"))
    		System.out.println("Yes and No are the only acceptable answers");
    	else {
        System.out.println(words[roll]);
    		System.out.println("Type the word");
    		while (!type.equals(words[roll])){
    			type = sc.next();
    			try {
    				if (!type.equals(words[roll])){
    					System.out.println("Type again");
    					error++;
    					}
    				else {
    					if (!type.equals(words[roll]))
    					System.out.println("next word");
    				}
    			} catch(Exception e){
    				System.out.println("lallalala");
    			}
    		}
    	}
    	type = "";
		System.out.println("Would you like to play again? Yes/No");
		reply = sc.nextLine();
		roll = a.nextInt(149);



    }
    System.out.println("Thank you for playing");
    }
}

Also, for a bit of a saver in your code, you could remove the word list, place it into a .txt file, and call the file upon execution load the file into an arraylist, also you could use a GUI, to save yourself/sister the hassle of running the program inside an environment.

This post has been edited by ILoveJava: 21 August 2012 - 05:39 AM

Was This Post Helpful? 1
  • +
  • -

#3 mrprogrammer14  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 21-August 12

Re: Typing Game Problem Here!

Posted 21 August 2012 - 05:47 AM

View PostILoveJava, on 21 August 2012 - 05:36 AM, said:

Moving the word call just above "Type the word" fixes your problem. Now your problem is that prompting for a yes/no appears twice.
import java.util.Random;
import java.util.Scanner;

public class Easy {

    public static void main (String []args){

        String words[]={"Love", "Hate", "Truth", "Happy", "Pressure", "Burp", "Vampire"
        , "Surf", "Believe", "Slime", "Dream", "Religion", "Rhythm", "Disco", "Honey",
        "Star", "Armies", "Zombie", "Heart", "Break", "Docks", "Multiply", "Mace", "Moustache"
        , "Wizards", "Sports", "Blind", "Riddle", "Business", "School", "Blood", "Promenade",
        "Vault", "Spray", "Eternal", "Dress", "Abstain", "Controls", "Circuit", "Forever",
        "Dangerous", "Skunk", "House", "Wives", "Flashlight", "Console", "Awesome", "Scared",
        "Hormones", "Promise", "Angel", "Baggage", "Duck", "Destroy", "Tissue", "Ketchup",
        "Picture", "Basket", "Basketball", "Fan", "Dough", "Thief", "Female", "Family", "Normal",
        "Wireless", "Empty", "Cycles", "Banana", "Eggplant", "Samba", "Jumble", "Flush", "Beach",
        "Driver", "Queen", "Mommy", "Fade", "Kitten", "Spring", "Interest", "Debts", "Horse",
        "Tomorrow", "Discount", "Faithful", "Midnight", "Epic", "Calendar", "Roses", "Funeral",
        "Badminton", "Spirit", "Water", "Pizza", "Science", "Cabinet", "Apple", "Television",
        "Profile", "Wine", "Sedan", "Luxury", "Firewall", "Computer", "Tablet", "Giraffe", "Ring",
        "Shut", "Vision", "World", "War", "High", "School", "Fantasy", "Warfare", "Incognito",
        "Loading", "Penguins", "Fright", "Night", "Diary", "Mega", "Submit", "Hold", "Statue",
        "Boat", "Mobile", "Invisible", "Visible", "Ground", "Space", "Dragon", "Spade", "Clover",
        "Senior", "Junior", "Sophomore", "Freshman", "Twilight", "Dawn", "Eclipse", "Moon",
        "Hair", "Spray", "Camp", "Jazz", "Rock", "Eggs", "Hustle"};

       Scanner sc = new Scanner(System.in);
       Random a = new Random();
       int roll = a.nextInt(149);
       String type = "";
       String reply = "yes";
       int error = 0;

    while (!reply.equalsIgnoreCase("no")){
    	if (!reply.equalsIgnoreCase("yes"))
    		System.out.println("Yes and No are the only acceptable answers");
    	else {
        System.out.println(words[roll]);
    		System.out.println("Type the word");
    		while (!type.equals(words[roll])){
    			type = sc.next();
    			try {
    				if (!type.equals(words[roll])){
    					System.out.println("Type again");
    					error++;
    					}
    				else {
    					if (!type.equals(words[roll]))
    					System.out.println("next word");
    				}
    			} catch(Exception e){
    				System.out.println("lallalala");
    			}
    		}
    	}
    	type = "";
		System.out.println("Would you like to play again? Yes/No");
		reply = sc.nextLine();
		roll = a.nextInt(149);



    }
    System.out.println("Thank you for playing");
    }
}

Also, for a bit of a saver in your code, you could remove the word list, place it into a .txt file, and call the file upon execution load the file into an arraylist, also you could use a GUI, to save yourself/sister the hassle of running the program inside an environment.

Yeah, there is a GUI i made for that app. Do you also know how can I put a 2 minute timer for that game? Thank You!
Was This Post Helpful? 0
  • +
  • -

#4 ILoveJava  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 389
  • Joined: 12-March 12

Re: Typing Game Problem Here!

Posted 21 August 2012 - 05:49 AM

I have never used Timers, but go here while you wait, if you can't get it, come back and someone will be able to help you. :)

This post has been edited by ILoveJava: 21 August 2012 - 05:52 AM

Was This Post Helpful? 0
  • +
  • -

#5 mrprogrammer14  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 21-August 12

Re: Typing Game Problem Here!

Posted 21 August 2012 - 05:53 AM

View PostILoveJava, on 21 August 2012 - 05:49 AM, said:

Fairly certain there is a Swing Timer, personally I have never worked with Swing Timer's, but you could always give it a Google, or wait until someone with more experience to come in. You would definitely need the GUI for the Timer, though.

Thank you so much for all of your help. Just one last question, where will i move the type again?

View Postmrprogrammer14, on 21 August 2012 - 05:51 AM, said:

View PostILoveJava, on 21 August 2012 - 05:49 AM, said:

Fairly certain there is a Swing Timer, personally I have never worked with Swing Timer's, but you could always give it a Google, or wait until someone with more experience to come in. You would definitely need the GUI for the Timer, though.

Thank you so much for all of your help. Just one last question, where will i move the type again?

type the word i mean :)
Was This Post Helpful? 0
  • +
  • -

#6 ILoveJava  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 389
  • Joined: 12-March 12

Re: Typing Game Problem Here!

Posted 21 August 2012 - 05:55 AM

That's perfectly fine where it is, man. You're only problem was the word list call was outside of the loop, so it never went back to it to call it again.

You should also change your code to
    			} catch(Exception e) {
    				e.printStackTrace();
    			}

So if something is caught, you know.
Was This Post Helpful? 0
  • +
  • -

#7 mrprogrammer14  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 21-August 12

Re: Typing Game Problem Here!

Posted 21 August 2012 - 05:55 AM

View Postmrprogrammer14, on 21 August 2012 - 05:53 AM, said:

View PostILoveJava, on 21 August 2012 - 05:49 AM, said:

Fairly certain there is a Swing Timer, personally I have never worked with Swing Timer's, but you could always give it a Google, or wait until someone with more experience to come in. You would definitely need the GUI for the Timer, though.

Thank you so much for all of your help. Just one last question, where will i move the type again?

View Postmrprogrammer14, on 21 August 2012 - 05:51 AM, said:

View PostILoveJava, on 21 August 2012 - 05:49 AM, said:

Fairly certain there is a Swing Timer, personally I have never worked with Swing Timer's, but you could always give it a Google, or wait until someone with more experience to come in. You would definitely need the GUI for the Timer, though.

Thank you so much for all of your help. Just one last question, where will i move the type again?

type the word i mean :)

sorry if i messed up. i saw the code you wrote already. Thanks for helping me! I'm sure my sis will be so happy
Was This Post Helpful? 0
  • +
  • -

#8 ILoveJava  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 389
  • Joined: 12-March 12

Re: Typing Game Problem Here!

Posted 21 August 2012 - 06:03 AM

No problem! Welcome to D.I.C, also!
Was This Post Helpful? 0
  • +
  • -

#9 mrprogrammer14  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 21-August 12

Re: Typing Game Problem Here!

Posted 21 August 2012 - 07:30 AM

View PostILoveJava, on 21 August 2012 - 06:03 AM, said:

No problem! Welcome to D.I.C, also!

how will i insert the .txt file into the code? Thanks
Was This Post Helpful? 0
  • +
  • -

#10 ILoveJava  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 389
  • Joined: 12-March 12

Re: Typing Game Problem Here!

Posted 21 August 2012 - 04:38 PM

To use a .txt file, you'll need to read up on Scanner's. You'll need to Google for a tutorial though. They are very easy to learn.
Was This Post Helpful? 0
  • +
  • -

#11 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10700
  • View blog
  • Posts: 39,813
  • Joined: 27-December 08

Re: Typing Game Problem Here!

Posted 21 August 2012 - 09:34 PM

NeoTifa covers Scanner in one of her tutorials.

http://www.dreaminco...ortant-classes/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1