id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

orion.a.smith@gmail.com hcs-chatbots

Description:Honors Computer Science - String processing problems to build a chatbot

This page of String problems exists to replicate some of the skills developed by the Magpie lab, which is one of the stock labs provided for the AP Computer Science A course. No, these problems are not as interesting as the chatbot but they do work on String processing skills.


Very useful introduction! Once you get to a problem in this series, scroll to the bottom of the page and you will see several links to great tutorials about Strings right here on the CodingBat site.

How to use a for loop with a String

If the input is named str (and it will be, most of the time), here's a simple for loop that goes through all characters and checks an individual character using str.substring(i, i+1).
for (int i = 0; i < str.length(); i++)
{
  if (str.substring(i, i+1).equals("A"))
  {
    // do something when we find the character 'A' inside str
    // note, substring returns String and thus compares using .equals
  }
}

Alternately, you could also do this inside the loop (using charAt instead of substring)

for (int i = 0; i < str.length(); i++)
{
  if (str.charAt(i) == 'A')
  {
    // do something when we find the character 'A' inside str
    // note, charAt returns char and thus compares using ==
  }
}
About Words

Many problems in this set will have specialized definitions of what a word is in a String.  Sometimes, a very loose definition is used like "anything that isn't a space character is part of a word."  Other times, you will see more specific restrictions like "letters count as parts of words, but numbers do not."  Pay attention to these definitions when doing the problems.  There's a reason for this: in real language processing, it's important to figure out this question especially when you think about characters like apostrophes, periods, commas and exclamation marks.

Harder problems, and challenges

Some of these problems are more difficult and are marked with "Hard" at the end of the method name.  You should try them, but also feel free to move on if you have trouble and come back later.  Some of the problems also have challenges listed with them, worth extra credit if you can do them.  The challenges are significantly harder than anything else we have done so far, though.

Indexing problems

apcsaChatbotsFindSpace  apcsaChatbotsNumSpaces  apcsaChatbotsCountWords  apcsaChatbotsCountWordsHard 

Word detection problems

apcsaChatbotsFirstWord  apcsaChatbotsWordExists  apcsaChatbotsPunctuatedWord  apcsaChatbotsLastWordHard 


Re-arranging problems

apcsaChatbotsRearrangeStartsIAm  apcsaChatbotsRearrangeContainsIAm  apcsaChatbotsRearrangeContainsIYou 
Authoring docs

Copyright Nick Parlante 2017 - privacy