CPSC 240 — OOA&D — Fall 2024

Program #1 — "Igpay"

Due: Thursday, Sep. 12th, midnight

Igpay

You will write a program that will translate English to Pig Latin. When it runs, your program should continually prompt for lines of input until the user enters the word done on a line by itself. Each line should begin with the prompt "Eng:", after which the user can type anything they like. It should then present a line beginning with "Pig:", and a translation. Here's an example session (text in blue is what the user types):

$ java  Translator
Eng: stephen
Pig: ephenstay
Eng: betty boop
Pig: ettybay oopbay
Eng: scrambled egg sandwiches
Pig: ambledscray eggway andwichessay
Eng: where is my blueberry muffin
Pig: erewhay is my ueberryblay uffinmay
Eng: done
$

Rules

Here are the rules we'll use for Pig Latin:

All punctuation and other non-alpha characters should be stripped:

Eng: is it cool that i said all that?
Pig: is it oolcay atthay i aidsay allway atthay 
Eng: is it chill that you're in my head?
Pig: is it illchay atthay oureyay in my eadhay 
Eng: i don't know about you, but i'm feeling 22
Pig: i ontday owknay aboutway ouyay utbay im eelingfay

You may assume that there will be no upper-case letters in the inputs.

Design

Your program must consist of two source files, one called Translator.java and the other called Sentence.java.

Translator.java will contain a class called Translator with a main() method. It may also include whatever (static) helper functions you deem necessary.

Sentence.java will contain the Sentence class. Each object of type Sentence should represent one line that the user typed. It should contain the following methods:

Hint: the main() method of Translator should instantiate and use Sentence objects to accomplish its task.

"Gitting" started

If you completed the development environment setup assignment you've probably already configured git. If not, type these three commands (substituting actual values for the first two placeholders, of course):

$ git  config  --global  user.email  "you@example.com"
$ git  config  --global  user.name  "Your Name"
$ git  config  --global  --replace  core.editor  vim

(You'll never have to do that part again.)

Okay, now you must create a git repo in which to house your project. First, create a project directory:

$ mkdir  igpayProject

and go there:

$ cd  igpayProject

and create an empty repo by running:

$ git  init  .

Then, create a src ("source") directory to hold your source code:

$ mkdir  src

go there:

$ cd  src

Now you're ready to add code. Create each of your two files with vim, and add some initial contents:

$ vim  Translator.java
$ vim  Sentence.java

A good candidate for "initial contents" is an empty class declaration for Sentence.java, plus stubs for the methods specified above:

class Sentence {

    Sentence(String english) {
    }

    String translate() {
        return null;   // placeholder for now
    }
}

and the same plus an empty main() for Translator.java:

class Translator {
    public static void main(String args[]) {

    }
}

Save the initial contents to each of these files using the ":w" command, quit out of vim using the ":q" command, and then add them to version control via:

$ git  add  Translator.java  Sentence.java

From now on, any time you come to a reasonable stopping point, commit your files to git via:

$ git  commit  -a  -m  "A descriptive comment of your changes."

Compiling and running Java

To compile your code, type:

$ javac  *.java

which, if there are no compile errors, will produce two files: Translator.class and Sentence.class. These are the compiled versions of your source files.

Finally, to run your program, you type:

$ java  Translator

If all has worked well to this point, the previous command should silently complete with no errors. Add a System.out.println("yo!") to your main(), and recompile and run, to verify your code is being reached.

Please please please read and do this

Far and away the number one problem I have seen CPSC 240 students create for themselves over the years, which always results in non-working programs, is this: trying to code their entire program, including all possible cases it has to handle, all at once, before ever verifying that they can get a simpler version of it working first. This mistake spells utter doom to every student that makes it.

Pro tip: no one, not even (or especially not) expert programmers, actually successfully codes like that. All successful coders code incrementally, progressively getting more and more of the whole enchilada done over time.

For this reason, I strongly strongly strongly strongly strongly strongly strongly strongly strongly strongly strongly strongly strongly strongly urge you to use something like the following procedure for this assignment:

  1. Write a main() function in Translator.java that just prints out a greeting, nothing more. Get that working, then commit it to git.
  2. Add the ability to prompt the user for a single English phrase, then just print it back to them and exit the program. Get that working, then commit it.
  3. Add a loop around your prompt-and-respond code, along with the ability to detect when the user types "done". Get that working, then commit it.
  4. Assume that the user's input will be exactly one word long, and that that word will have at least three letters and begin with a vowel. Under those assumptions, write the code to translate the user's phrase (word, actually) to Pig Latin. Get that working, then commit it.
  5. Now make it work for words that begin with a single consonant. Get that working, then commit it.
  6. Now make it work for words that begin with multiple consonants in a row. Get that working, then commit it.
  7. Now make it work for multiple words. Get that working, then commit it.
  8. Now make it ignore punctuation. Get that working, then commit it.
  9. Now make it leave as-is (not translated) the special words "and" and "the". Get that working, then commit it.
  10. Now make it leave as-is (not translated) any word with fewer than three letters. Get that working, then commit it.
  11. Test the snot out of your program, then commit it and turn it in.

Testing your program

To determine whether your program functions properly in all cases you will need to test it with a wide variety of inputs and make sure it gives the correct outputs. Don't underestimate how important this process is, nor how long it will take! Any sentences you mistranslate are going to result in fewer points than you would otherwise have received.

I will be testing your program on a huge file of test cases that I have concocted in sinister and abominable fashion. You will not receive this file ahead of time, of course. However, out of the goodness of my heart, I do provide you with a test harness and a small number of test cases. To use them, download both of the above files to your Cloud instance, and put them in the same directory that your .java files are. You can do that with the very useful wget command:

$ wget http://stephendavies.org/cpsc240/tester.py
$ wget http://stephendavies.org/cpsc240/cases.json

Then, type:

$ ./tester.py

to discover which test cases your program passes.

(Btw, if that doesn't work the first time, you may need to execute this command to make sure the script has permissions to run:)

$ chmod  a+x  tester.py

Turning it in

You will turn this assignment in by attaching a git bundle to an email. (A "git bundle" is essentially a portable, zipped-up git repo.) The subject line of the email should be "CPSC 240 Igpay turnin".

To do this, first make sure that all your code is checked into git. Running "git status" and ensuring your workspace is clean is a great way to do that. Then, bundle up your git repo:

$ git  bundle  create  yourUmwUsername.git  --all

(Please do not name it literally "yourUmwUsername.git" Substitute your actual UMW username. For instance, "jsmith7.git".)

Next, download the yourUmwUsername.git file from your Google Cloud instance to your own machine.

Finally, send the yourUmwUsername.git file as an email attachment to cpsc240submissions@gmail.com with subject line "CPSC 240 Igpay turnin". In the body of the email, include a haiku which you think sounds particularly funny in Pig Latin.

To receive full credit, I must be able to type the following commands in sequence, verbatim, with no variations, to run your program:

$ git  clone  the-name-of-the-repo-you-sent-in-your-email.git  temporary
$ cd  temporary/src
$ javac  *.java
$ java  Translator

If I have to do any extra fiddling because these four commands, verbatim, in sequence, did not work, it's coming out of your grade.

Hint: test that this works before submitting your assignment. You can test it by creating a little temporary practice directory:

$ mkdir  pretendImStephen
$ cp  the-name-of-your-repo.git  pretendImStephen
$ cd  pretendImStephen

and then typing those four commands, above, to make sure they have the desired effect. (You can then get rid of that directory by typing "cd .." followed by "rm -rf pretendImStephen".)

Warning!!

One of the following two things must be true for you to get any credit for this assignment. Either:

  1. your program must, to your knowledge, work perfectly in all aspects, or
  2. you explicitly tell me, in your submission email, exactly what doesn't work about it.

In this latter case, you must prefix your explanation with the word WARNING!! and then give a concise but complete description of what your program does not do correctly. For instance, here's a sample:

Dear Stephen,

Please find attached my Homework #1 submission.

WARNING!! I could only get it to work for single-word inputs, not
anything with punctuation or multiple words.

If your program contains bugs or errors that you don't tell me about, you will receive a zero.

Bonus: starting early and often

Note: the definition of "non-trivial" is "whatever Stephen deems is non-trivial."

I need help!

Send me (stephen AT umw DOT edu) email with subject line "CPSC 240 Igpay HELP!!!"