Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

pottersheep Group Title

Beginner Java Program help please!

  • 3 years ago
  • 3 years ago

  • This Question is Closed
  1. pottersheep Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    I'm really confused in what I have to do... Basically we create a word game. The user enters a word, like "Apartment" Then our program checks to see if any of the words in it's "dictionary" can be created from the letters in the word just entered. The words in my dictionary are: hat, pool, math, bita, sheep, cap, dog, cat, one, eat, ear; We haven't learnt how to use arrays yet and are not supposed to use them. Im not sure what to do after the user enters the word.. :s

    • 3 years ago
  2. Narsat Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    You could store them all inside a large String. String dictionary = "hat pool math bita sheep cap dog cat one eat ear"; Then do something like: if( dictionary.indexOf(input) > 0) System.out.println("Word exists"); else System.out.println("Word doesn't exist"); Look into indexOf, im pretty sure you can send a string as argument, what it does it check inside the String dictionary for a certain char or String of chars you send it, if it finds it, it'll return the position where it found it. If it doesn't, it'll return -1.

    • 3 years ago
  3. sbuser Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    That's good stuff. It doesn't print out the word it found, though. You have the index, just look for the first space. Print out the substring from index of the word to the next space.

    • 3 years ago
  4. dmancine Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Without arrays it's a real PITA. Here's one way to do it. You'll need these functions: int getLetterCount(String word, char letter); // return the number of times letter occurs in word boolean testLetter(String userWord, String dictionaryWord, char letter); // return true if userWord has more of letter than dictionaryWord boolean containsWord(String userWord, String dictionaryWord); // return true if userWord has more of every letter than dictionaryWord void printMatchingWords(List<String> dictionary, String userWord); // for each word in dictionary, prints it if containsWord(userWord, word) returns true I don't know how you're storing the dictionary, but it's hard to do without an array or a Collection. In main you'd get the user's word, then call printMatchingWords with that word and the dictionary. This is incredibly inefficient. If you could use an array it would be much better. I don't know what other data types you can use, so I assumed you could only use individual primitives.

    • 3 years ago
  5. pottersheep Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks

    • 3 years ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.