Problem Solving Assignment 3


Due Oct 10, midnight

There are two problems in this PSA. Here is the overview. Note, there is an interview process required for this PSA. Details at bottom after turning instructions. This work should be done in it's own directory (psa3). NEW You must include some specific comments with your code. See details below.

This homework requires skills from Chapters 1,2, and 3.

  1. Coin Tossing Write a program that accepts information about 8 coin tosses and outputs some statistics on them.
  2. String manipulation Write a program that parses a String input (a single sentence) and does some wild and crazy things depending on what the user types in.

Details

You must put a comment at the top of your code with the following three things in it: Use a multi-line comment (/* */).

In order to be able to use the turnin script easily, start by creating a directory (folder) in your ieng6 cs8f account. After you log in, create a directory by typing the command (don't type < enter > just hit the key) :

  mkdir psa3 < enter >
Go into that directory (like double clicking to open a folder) with the command:
  cd psa3 < enter >

You MUST name your files as indicated in the problem descriptions for the turnin program to work.

Coin Tossing

Write a program that will print out statistics for eight coin tosses. The user will either input an 'h' for heads or a 't' for tails for eight tosses. Then the program will print out the total number and percentages of heads and tails. Use the increment operator to count each 'h' and 't' input. DO THIS WITHOUT USING A LOOP! For example, a sample dialog might be (user input in bold, though it doesn't look very bold -- it's the h's and t's):

For each coin toss enter either 'h' for heads or 't' for tails.

First toss: h
Second toss:  t 
Third toss:  t
Forth toss:  h 
Fifth toss:  t 
Sixth toss: h 
Seventh toss: t
Eighth toss: t

Statistics:
-----------
Number of heads: 3
Number of tails: 5
Percent heads of valid inputs : 37.5
Percent tails of valid inputs: 62.5 

Notes:

String manipulation

Write a program that takes a one-line sentence as input and then outputs the following response:
If the sentence ends with the question mark '?' and the input contains an even number of characters, then output the word "Yes".
If the sentence ends with the question mark '?' and the input contains an odd number of characters then output the word "No".
If the sentence ends with an exclamation mark '!', then output the sentence "Wow, that's incredible!".
In all other cases, your program will output "I don't understand what you mean by " followed by the input string WITHOUT THE FIRST WORD enclosed in quotes.

For example, the input

Hello there Jose.
Should produce the output
I don't understand what you mean by "there Jose." 
With the quotes. Your program only has to accept one sentence. If your input sentence has only one word, it will print out I don't understand what you mean by "". You should prompt the use to enter the sentence with an appropriate comment printed out on the screen (for example: Please enter a sentence:)

NOTES:

How to turnin your homework electronically

When you are ready to turn in your homework, run bundle-psa2 from your psa1 directory. The session should look like this:

-bash-2.05b$ cd ~/psa2
-bash-2.05b$ bundle-psa2
Good; all required files are present:

        SimpleMath.java
        ChnageMaker.java

Do you want to go ahead and turnin these files? [y/n]y
OK.  Proceeding.


Performing turnin of approx. XXXX bytes 
Copying to /home/linux/ieng6/cs8f/turnin.dest/cs8fzz.psa2
.
Done.
Total bytes written: XXXX 
Please check to be sure that's reasonable.
Turnin successful.

If you want to make changes after you've turned in your homework, make the changes and run bundle-psa2 again. The program will warn you that a "previously turned-in file exists" and ask if "you wish to over-write this existing file". Respond in the affirmative by typing y and pressing the Enter key.

Getting your interview done

10% of your grade on this assignment will come from an interview you will have with one of the tutors during Open Lab Hours. You have 48 weekday hours after the electronic turnin deadline to get your interview done. The deadline for the interview for PSA2 is Wed Oct 5 (theoretically at midnight, but actually by the end of the last tutor hour scheduled).

You get an interview by going into B250 during a scheduled tutor hour. Find the tutor, ask them if you can interview for PSA2. If they have others who are waiting for interviews, your name will go on the end of the list of people waiting. Interviews take about 5 minutes each. It is your responsibility to go in early enough that you can get your interview completed. If everyone waits until the last hour on Wed, this will not work.

The tutor will ask you to log in, change to the directory where your work is (psa2) and then to follow their directions. They will ask you to run your program to show that it works, open files in your favorite editor, and ask you questions about HOW your code works. Additionally, they may question you as to how you would (theoretically) make small changes to the program to have it do something slightly different. You will not actually be required to change your code.

Learning to be able to explain your problem solving process and discuss code with another human being is a very important professional skill. We hope that this process will help you develop this skill.

Learning to use text editors

Vim
Run vimtutor, a separate program that will teach you to use Vim.
Emacs
Use the built-in tutorial by running emacs and, within the editor, typing CTRL-h t.
Pico
You can reach Pico's built-in help by typing CTRL-g. If you want further instruction, look at this Pico tutorial from NC State.

Which editor should I use?

For most of us, the choice of a text editor is a matter of preference (or, more likely, familiarity). It happens that Beth Simon and Dana Dahlstrom use Vim, but many other computer scientists use Emacs. Pico is a simpler editor designed to be easy for beginners. Pico is much less powerful than Emacs or Vim once you learn to use them.