Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: Please help me with my project

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool Please help me with my project

    Guys, i'm having a hard problem in this one. It is a typing game code that the program will show a word and the person will write the word. 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);
           System.out.println(words[roll]);
           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("Type the word");
     
        		while (!type.equals(roll)){
        			type = sc.next();
        			try {
        				if (!type.equals(roll)){
        					System.out.println("Type again");
        					error++;
     
     
        				}
        				else {
        					if (!type.equals(type))
        					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");
        }
     
    }

    The "Type Again" is always showing up even if the word is correct. I need to make "next word" and "would you like to play again". Thank you in advance!!!
    Last edited by mrprogrammer; August 20th, 2012 at 10:40 AM.


  2. #2
    Junior Member
    Join Date
    Aug 2012
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please help me with my project

    First Tell me what does this program actually do.
    I'M not able to understand about the working of that program.

  3. #3
    Junior Member
    Join Date
    Aug 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please help me with my project

    sorry if i didn't mention what the program is doing. it's a typing game. the program will reveal a word and the person should write the word correctly.
    but i'm finding it hard to figure out why is it always saying type again even if the word i wrote is correct.

  4. #4
    Member
    Join Date
    Jun 2012
    Location
    Left Coast, USA
    Posts
    451
    My Mood
    Mellow
    Thanks
    1
    Thanked 97 Times in 88 Posts

    Default Re: Please help me with my project

    Quote Originally Posted by mrprogrammer View Post
    ...The "Type Again" is always showing up even if the word is correct...
    So: Make the program tell you what is seeing when it decides to print "Type again"


    .
    .
    .
                        System.out.prinln("roll: " + roll + ", type: " +  type);
                        if (!type.equals(roll)){
                            System.out.println("Type again");
                            error++;
    .
    .
    .


    Cheers!

    Z
    Last edited by Zaphod_b; August 20th, 2012 at 08:03 AM.

  5. #5
    Junior Member
    Join Date
    Aug 2012
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please help me with my project

    Actually in your code their is a error..
    if (!type.equals(roll)){
    System.out.println("Type again");
    error++;

    in if function "type" is a string and "roll" is a integer.
    so it will never be equal..

    I hope you may recognize this.
    If not then reply again.
    I'LL try again to solve your Problem

  6. #6
    Junior Member
    Join Date
    Aug 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please help me with my project

    Quote Originally Posted by maz3r View Post
    Actually in your code their is a error..
    if (!type.equals(roll)){
    System.out.println("Type again");
    error++;

    in if function "type" is a string and "roll" is a integer.
    so it will never be equal..

    I hope you may recognize this.
    If not then reply again.
    I'LL try again to solve your Problem
    I can't recognize. Can you please solve my problem? I'll really appreciate it. Thanks

  7. #7
    Junior Member
    Join Date
    Aug 2012
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please help me with my project

    I have modified that code.
    So try to run that code. And tell me that Is it function as you want or not?

    If not then tell What is the functioning you need in that code.

    ...removed by moderator
    Last edited by copeg; August 20th, 2012 at 02:20 PM.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,360
    Thanks
    49
    Thanked 2,206 Times in 2,179 Posts

    Default Re: Please help me with my project

    @maz3r Please don't do the OPs homework for him. On this forum we try to help OPs learn how to program with java. We don't post solutions for their homework.

    See: The Problem with Spoon-feeding
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,297
    Thanks
    180
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: Please help me with my project

    @maz3r, you've been told in another one of your posts to read the Forum Rules. Please do so at this time. Your post has been edited due to spoonfeeding.

  10. #10
    Junior Member
    Join Date
    Aug 2012
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please help me with my project

    so mprogrammer in your code you are comparing a string with a integer so it will never true.
    Code is in which error occur:
    if (!type.equals(roll)){
    System.out.println("Type again");
    error++;

    Here type is string and Roll is integer
    so you must use words[roll] in place of roll.

    and the another problem is

    reply = sc.nextLine();

    here you have to use sc.next(); not sc.nextLine();

    If you still have any problem then post here

Similar Threads

  1. need help on my project..
    By jikoy in forum What's Wrong With My Code?
    Replies: 10
    Last Post: March 21st, 2012, 11:57 AM
  2. Need some help on my HS Project
    By ntilli in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 12th, 2011, 09:22 PM
  3. Help with Project
    By rawrxeroes in forum Object Oriented Programming
    Replies: 1
    Last Post: October 12th, 2011, 07:12 AM
  4. Can anyone help me on my project?
    By alesana514 in forum Paid Java Projects
    Replies: 1
    Last Post: December 16th, 2009, 08:24 AM
  5. Need Help With Project
    By jstew132 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 11th, 2009, 06:15 PM

Tags for this Thread