CPSC 240 — OOA&D — Spring 2024

Star Wars Name Generator

Due: Thursday, Feb 1 Saturday, Feb 3, midnight

(Thanks to Dr. Zeitz, who originally created this assignment.)

Back into the swing of things...

Let's just make sure everyone can get a basic Java program running in the Linux environment. Your program will continually prompt the user for information about individuals in this galaxy: their first and last name, their mother's maiden name, and their birth city on Earth. It will continue in this fashion indefinitely, until the user types "done" (or "Done") for the first name, at which point it will stop prompting for input.

At that point, the program will print the corresponding name in the Star Wars galaxy (see below) for each individual, including any Sith Lords (see below).

"Star Wars names"

Your program will generate the "Star Wars name" for ordinary individuals. Here are the basic rules (but see exception, below):

For instance, my Star Wars name is "Steda Sleng" since my mother's maiden name is "Sloan" and I was born in Englewood, Colorado. Dr. Zeitz's is "Jesze Badot" since she was born in Dothan, Alabama and her mother's maiden name is "Bacon."

Exception: Sith Lords

Out of the entire list of individuals the user enters, one or more will be designated "Sith Lords." This is the individual (or individuals, in case of ties) with the greatest number of vowels in their name. (Note that "name" means "first and last name," not mother's maiden name or city. Note also that some common names, like "Olivia" and "Anderson," begin with vowels.) For purposes of this assignment, we will count the five letters a, e, i, o, and u, as vowels (never y).

A Sith Lord's "Star Wars" name is generated as follows:

Assumptions

You may assume that every first name, last name, maiden name, and city the user enters will have at least three characters. There is no need (unless you want to) to check for that and handle exceptions gracefully.

You may not assume that the user will capitalize their entries, nor that they will not capitalize their entries. Your program should function identically regardless of whether the user enters "filbert", "Filbert", "FILBERT", "fIlBeRt", or anything else. The outputs should always be comprised of 5-letter words with initial capitals and lower-case letters everywhere else.

Example

Here's an example of the program in action (blue letters are what the user types):

Enter first name #1 (or "done"): stephen
Enter last name #1: davies
Enter mother's maiden name #1: sloan
Enter city of birth #1: englewood

Enter first name #2 (or "done"): Jessica
Enter last name #2: Zeitz
Enter mother's maiden name #2: Bacon
Enter city of birth #2: Dothan

Enter first name #3 (or "done"): Ada
Enter last name #3: Lovelace
Enter mother's maiden name #3: Milbanke
Enter city of birth #3: London

Enter first name #4 (or "done"): Alan
Enter last name #4: TURING
Enter mother's maiden name #4: stoneY
Enter city of birth #4: lOnDoN

Enter first name #5 (or "done"): Done

Your Star Wars names are:
1. Steda Sleng
2. Jesze Badot
3. Darth Adalo
4. Alatu Stlon

Design

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

I'm happy to give additional guidance on what specific stuff should go in each of these two classes; just ask!

Tips

Btw, here are some methods in the Java API that I found useful in writing my own Star Wars Name Generator (you do not have to use all or any of these, and you are free to use others):

"Gitting" started

The first time you use git, you have to tell it who you are, and set your default editor, by configuring three settings. (If you've already done this, skip this step.) Simply 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  nameGeneratorProject

and go there:

$ cd  nameGeneratorProject

and create the 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  NameGenerator.java
$ vim  Person.java

A good candidate for "initial contents" is an empty class declaration for Person.java:

class Person {

}

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

class NameGenerator {
    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  NameGenerator.java  Person.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: NameGenerator.class and Person.class. These are the compiled versions of your source files.

Finally, to run your program, you type:

$ java  NameGenerator

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.

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!

When you're finally ready to test your bullet-proof program on something really tough, you can run it on a sample input (and correct output) of my generating. To do this:

  1. Download the two files earthlings.txt and galaxylings.txt to your cpsc workspace. (The command "wget" is nice for this: you just type "wget" followed by some URL, and it will download that file and put a copy of it in your directory.) The first of these files is a set of 1000 randomly-created Earthlings that you will feed into your program as input. The second is the correct Star Wars names for each (including all the Darths.) (If you don't use wget to obtain these files, you can do a two-parter: first download them to your own local machine, then upload them to your cpsc workspace.

  2. At this point, you should have the files earthlings.txt and galaxylings.txt in your project directory. (If they're not in your project directory, use the mv command to carefully move them there.) Before actually testing with them, use vim to open each of these files (they're just plain text files, after all) and poke through them to see what they contain.
  3. Now, run your program like this:
    $ java  NameGenerator  <  earthlings.txt  >  myoutput.txt
    
    This command says: "Run my NameGenerator program as usual. But instead of getting input from the keyboard, get it from the earthlings.txt file. And instead of writing output to the screen, write it to a new file called myoutput.txt."
  4. Now, the output you generated is in myoutput.txt, and the output you should have generated is in galaxylings.txt. The way to auto-compare these two files is the diff command (which means "show the diffeferences between files.")
  5. Before actually doing this, you probably want to vim your myoutput.txt file and manually get rid of all the prompt lines ("Enter first name #1.......") Those thousands of prompts should all be on one line, and to delete them you can just position your cursor at the start of it and use the "dd" command in vim. (Typing two d's deletes the current line.) Then, write out the revised file and quit vim.
  6. Finally, run diff as follows:
    $ diff  myoutput.txt  galaxylings.txt
    
    If you get no output, it means that your output file and my output file are identical, and your program worked with no errors! If there is any output, it will show you (in a bit of a cryptic way) which lines yours differs from mine, and how. Then you'll know which names you mis-generated and can commence debugging your program.

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 Star Wars Name Generator 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 Star Wars Name Generator turnin". In the body of the email, use your Star Wars name in a funny haiku of your own original composition.

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  testme
$ cd  testme/src
$ javac  *.java
$ java  NameGenerator

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 in your home directory:

$ mkdir  ~/pretendImStephen
$ cp  yourUmwUsername.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 if you want to by typing "cd .." followed by "rm -rf ~/pretendImStephen".)

Bonus: starting early and often

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

I need help!

Come to office hours, or send email with subject line "CPSC 240 Star Wars Name Generator HELP!!!"