• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I program a love hate game in java?  RSS feed

 
Jeff Sak
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I am trying to program something where the user will type in something (ex: quizzes, gym, cars) and I will have the program respond whether it loves it or not. I want to make it so the program loves anything with that's double chartered (ex: quizzes has 2 z's next to each other). I'm really not sure how to eve start writing this function to have it look for double characters as opposed to a word that has the same to characters not next to each other. Such as differentiating quizzes with two z's, to paper with two p's but separated.
 
Junilu Lacar
Sheriff
Posts: 11164
160
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you tried so far? Just a reminder, Code Ranch is not a code mill.
 
Nigel Browne
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Before programming anything, write down the logical steps that you'll need to test for. For example
1) Get the length of a word
2) Check that length is greater than 1
3) Does the 1st character in the word equal the 2nd character (Yes/No)
4) if yes then love
5) If no then does 2nd character equal 3rd (yes/no)
6) repeat character test until length of word or a yes result occurs.

Once you are clear on your logical steps, start by writing small chunks of code ensuring that each step passes a basic step. i.e if the word is 'a' then hate, if word is 'zz' then love

You may also what to think about what happens when the user enters l8r or m8 as a word, how would you handle these?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!