CS 161 Homework 5 - Dialect Converter

Due Fri Oct 18 at 5:00pm

Overview

In this assignment you will create a program to convert text files into into amusing dialects--in particular, into Pig Latin and Swedish Chef-ese (also here). Your program will be run on the terminal. It will first prompt the user to select a dialect, and then to input some text. This text can include multiple words--indeed, it could be an entire paragraph! Your program will convert the text into the previously choosen dialect, and then output the results. Your program will continue asking the user for text to convert until the user hits "enter" (gives a blank entry), at which point the program will exit. Examples of what your program might look like can be found below:

Welcome to the dialect converter!
Choose a dialect: 'Pig Latin', 'Swedish Chef'
Dialect: Pig Latin
Phrase: Hello World
  "elloHay orldWay"
Phrase: all your base are belong to us
  "allway ouryay asebay areway elongbay otay usway"
Phrase: the quick brown fox jumped over the lazy dog
  "hetay uickqay rownbay oxfay umpedjay overway hetay azylay ogday"
Phrase: I love computer science!!
  "Iway ovelay omputercay ciencesay!!"
Phrase: 
Goodbye!

Or from an alternate run, selecting the Swedish Chef dialect:

Welcome to the dialect converter!
Choose a dialect: 'Pig Latin', 'Swedish Chef'
Dialect: Swedish Chef
Phrase: Hello World
  "Helloo Woorld"
Phrase: all your base are belong to us
  "ell yoouor bese-a ere-a beloong too us"
Phrase: the quick brown fox jumped over the lazy dog
  "zee quoeeck broon foox juomped ofer zee lezy doog"
Phrase: I love computer science!!
  "I loofe-a coompuoter sceeence-a!!"
Phrase: 
Goodbye!

Note that these are fine "test" cases for your program!

This assignment should be completed individually.

Objectives

Necessary Files

You will need a copy of the Hwk5.zip file. The BlueJ project in this file includes the beginnings of a provided Dialectizer class. You will be filling in and completing this class (as well as adding comments to existing code!) in order to complete your program.The project also contains the README.txt that you will need to fill out and turn in along with your assignment.

Remember to extract the files from the zip folder before proceeding!

Dialects

Helpful Advice: Iterative Development

You should work to complete this assignment iteratively---you should build a small piece, test that it works, and then move on to the next bit. Below is a suggested order of steps, as well as good deadlines for getting each step working (if you haven't figure something out by the listed date, definitely ask for help!!):

  1. Dialectizer initialization: Tue 10/08
  2. pigLatinWord() method: Wed 10/09
  3. swedishChefWord() method: Thu 10/17
  4. DialectConversion class: Fri 10/18

Assignment Details

For this assignment you will modifying one existing class and creating one new class. The first class (Dialectizer) will be your "object class" (with instance variables, a constructor, etc)--it will represent a "machine" that can take in Strings and output versions converted into a dialect. The beginnings of this clas, complete with some helpful methods, has been provided for you. The second class (DialectConversion) you will create your self. This will be your "main class" that includes a user interface for soliciting text from the user and displayed the translated version of that text.

Overall, you should start by creating the Pig Latin functionality, then add the Swedish Chef functionality, then create the User Interface for using these functions.

Dialectizer

Your very first order of business should be filling in the Dialectizer class and making sure it can compile and be used. You'll need to make the following changes:

This should get you set up to be able to test your code (constructing a Dialectizer and calling convertText()).

A note about capitalization: The current methods do not handle capitalization--as you can see from the example outputs, the capitalization may not remain constant. That is acceptable for this assignment. However, you are welcome to add in functionality to correctly handle capitalization. One simple solution might be to make all the text either capital or lowercase, such as by using the String.toUpperCase() or String.toLowerCase() methods.

Pig Latin

The next thing you should do is add the ability to convert text to Pig Latin to your Dialectizer class.

  1. In order to make a word into Pig Latin, you'll first need to figure out if that word is a vowel. Since you'll be doing this a lot, it might be helpful to have a helper method to perform this functionality. Create a method called isVowel that takes in a single char and returns whether or not that character is a vowel.
    • The easiest way to do this is to define a String that is a list of the vowels, and then use the String.indexOf() method to check whether the given char is inside the String. If it is not, the .indexOf() method will return -1.
  2. Because Pig Latin rules are applied at the "word" level, you'll be completing a helper method named pigLatinWord that will make a single word into Pig Latin. This method should take in a single word as a parameter, and return a Pig Latin version of that word.
    • Start by writing down the algorithm---the series of steps---you might need to go about this method. This is a good stage to check in with others; make sure you understand how the process will work, even beore you write the code!
    • You can use the built-in String.charAt() method to figure out what the "first" character of the word is.
    • You can use the substring() method to get the word without the first letter, and use String concatenation (with the + operator) to add new endings to the word.
    • Remember to return the word when you are done!
  3. Note that this method will not work if your text has punctuation (like periods, etc). That's okay--we're handing punctuation in the getNextWord() method. Do you see how? Nevertheless, this is good to keep in mind for testing.
  4. Be sure and text your method thoroughly to make sure it works! You can either create a tester, or simply test it through the BlueJ UI.

Swedish Chef

Once you have written your Pig Latin converter, you'll need to write your Swedish Cheferizer. Again, rules for converting text to chefese will be applied at the word level, so you will need to create a method named swedishChefWord that will convert a single word. This method should take in a single word as a parameter, and return a Swedish Chef version of that word.

User Interface

Finally, once you've got your Dialectizer working, create a DialectConversion class to provide a user interface for using your generator. This class will be a "main" class--it will have a main method that prompts the user for input and provides output.

NOTE: You are welcome to write this class first before you finish the Dialectizer, and then to use it for testing.

Extensions

There are a number of potential extensions you might consider for this assignment. You can earn up to 5 points of extra credit for extensions on this assignment. Be sure to finish the rest of your program first!

Submitting Your Assignment

Grading

This assignment will be graded on approximately the following criteria: