CSE 131 Module 1: Intro and Types & Names

Studio


Read this before starting:

Studio Sessions Overview:

The results of your studio session are to be reported and documented in a file that you save in your workspace. You are to commit that report prior to leaving studio. In the descriptions of the studio exercises, verbs like report and document are indications of activities you should summarize and discuss in your report.

In your groups, take turns documenting results, looking over shoulders, and staffing the keyboard.

It is unacceptable to copy anything without understanding it. At any point, the TA or instructor can point to something you've done and ask you why it works, or change it and ask what would happen with the modification.



Warmup


Procedure


Some of the following exercises are adapted from Princeton University's COS 126 course, based on our text by Sedgewick and Wayne.

For each of the following exercises, find the file in your studio repository and complete it to do the assigned task.

HiOne
Say hello to the name supplied as input to this program. Sample output: Hello Ron! (assuming Ron was supplied as input)
Feel free to end the output with punctuation that indicates the level of enthusiasm associated with your greeting.
HiFour
Expand your hospitality to the four names supplied to this program. Sample output: Greetings Cormen, Leiserson, Rivest, and Stein.

Be sure to put in proper punctuation to separate the names.

Ordered
Define a boolean variable isOrdered whose value is true if the three values are either in strictly ascending order (x < y < z) or in strictly descending order (x > y > z), and false otherwise. Print out the variable isOrdered using System.out.println(isOrdered).
Some of you may already know some Java. We have not yet covered the if statement. You must use what has been taught so far (simple expressions and assignment) to accomplish this task.
Average
Complete this code so that it prints the average of its two integer inputs.
Sample output:
Average of 5 and 6 is 5.5

Note that the output is specified as a double, because the average of two integers is not necessarily an integer.

OK, for this one, you are on your own. We are not giving you code for this, but will instruct you how to create your own Java file from scratch:

  1. Right- (control-) click on the studio1 package, select New…Class.
  2. Type the name Average and check the box that indicates you want to create public static void main(String[] args):
  3. Click Finish and your new class shows up in the editor window.
  4. At the top of the main method, you need to insert the ArgsProcessor code to accept two integers: n1 and n2.
    • Refer to other studio code to see how this is done.
    • It is likely that when you type in the code, eclipse will flag your code with an error, because it doesn't know (yet) about ArgsProcessor.

      Silly eclipse.

      You can get eclipse to solve its own problem by mousing over the error, and using the first suggestion that pops up, namely to include ArgsProcessor from the cse131 package.

      Sometimes eclipse is über silly and won't tell you about that fix until you have saved your file. So save it.
    • Try to use meaningful messages to prompt for values. The units for the values will be interpreted as grams. For example, if 3 is specified for carbs, that means that this run of your program is for food that has 3 grams of carbohydrates.

      A not so nice prompt:

      int n1 = ap.nextInt("Yo, sup?");
      
      and a nice prompt:
      int n1 = ap.nextInt("The first of two integers to be averaged?");
      
    • Run your program and makes sure it prompts you correctly for its values.
    • Ask a TA to check your work at this point.
  5. Finish the class so it prints out the appropriate message.

Creative Exercise

As a group, brainstorm the best data type to represent the following situations:
Often, there is no right or wrong answer. Be prepared to defend your choices.

Submitting your work (read carefully)



Last modified 11:55:47 CDT 13 May 2014
When you done with this studio, you must be cleared by the TA to receive credit.

Last name WUSTL Key Propagate?
(or your numeric ID) Do not propagate
e.g. Smith j.smith
1 Copy from 1 to all others
2 Copy from 2 to all others
3 Copy from 3 to all others
4 Copy from 4 to all others

TA: Password: