CSE 131 Module 1: Types & Names
Read this before starting:
Studio Sessions Overview:
- We gather as a community in studio session to learn from each other.
Our community includes:
- Our community is egalitarian in terms of learning: all of us will
and all of us should try to provide answers.
- The idea is to challenge each other
and to share what we discover.
- You are free (downright encouraged) to collaborate in this
- Primarily within your small group of 2-4 people
- Secondarily with any group in the class
- As much as you like with the instructor and TAs
- In studio, the instructor's mission is to observe, interact,
and work with groups.
- How you think, work, and arrive at a solution is
more important than getting the right answer. Thus, the instructor
and TAs will observe you throughout the exercise and offer
- The help you receive may be incomplete at any given time, so that
you can work through more of the solution on your own. Do not
hesitate to ask for more help.
- In studio, the student's mission is to acquire new knowledge
and skills by the collaborative solving of problems.
- You are not graded on whether you get wrong
or right answers on this exercise.
- You are graded on your level of participation in studio.
- Participation is defined as
- Asking questions, at any level, of any person in the studio
- Discussing possible solutions with people in the studio
- Helping somebody in the studio solve a problem
- Presenting or demonstrating your solution to people in the studio
- Documenting your group's experiences in studio
- Please eliminate external stimuli (cell phones, IM, Facebook)
during studio. Please devote yourself to learning, mastering, and
extending the material for the session.
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.
To receive credit for a studio, your team must
cleared by a TA using the green box at the bottom of this page.
Be careful how you use the web. You are required to develop solutions
as a group by thinking not by finding solutions that have been thought
out by others. You must be able to explain anything that you have done.
First, form a group:
- If you are at a table with a large, wall-mounted screens, a group of 3-4 people is fine.
- If you are seated at a table without a large screen, a group of 2 people is better.
- All but one member of your group should have this web page open so you can follow along
and see the instructions as you work.
- All members of the group should update their repositories:
- Open your repository in eclipse
- Right-click (control-click on a mac) on your repository name
- Drag down to Team...
- Choose Update
- Supply your WUSTL key and password as necessary
- Plan to have one computer at which your team does its work. Initially,
one of you will be in charge of typing at that computer.
- Throughout the studio, you should trade who is in charge of the keyboard. Before doing so,
commit your work to make sure your work is saved.
- You will complete a series of simple Java programs, and run each program
to ensure it performs its task correctly.
- The files for this program
are in the studio1 package of the repository you loaded.
- There are two ways to run programs in this course:
- Directly in eclipse:
To run a program, right- (control-) click on the file's name, choose
Run As…Java Application. The program will then
launch and prompt you for the inputs it needs.
Try this now on the Hello class. When it asks you how you
are feeling, enter whatever comes to mind.
The tools we use are replete with buttons and menus to make programming
easier. One such button near the top of your eclipse window is a green
circle containing a white triangle:
Clicking on this button will run the program again.
Try running the program using the button. Isn't that more fun?
- Command line: This method simulates how you would run your
program from outside eclipse. You should see a usecommandline.jar
file in your studio repo. Double-click it to run the program, and
a window should appear.
If you click in the lower part of that window, you can type commands into that window, including a command that will run
your Java program.
For example, to run the Hello example, included in this studio,
you would type:
and hit enter.
On the command line, you can supply the program's inputs directly, instead
of being prompted for them one at a time.
In the command line window, type:
java studio1.Hello spunky
and hit return.
Notice that the program now uses spunky as its input.
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.
- Say hello to the name supplied as input to this program.
Sample output: Hello Ron! (assuming Ron was supplied
Feel free to end the output with punctuation that indicates the level
of enthusiasm associated with your greeting.
- 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.
- Define a boolean variable isOrdered whose value is
true if the three values are either in strictly ascending
(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.
- Complete this code so that it prints the average of its two integer inputs.
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:
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.
- Right- (control-) click on the studio1 package, select
- Type the name Average and check the box that indicates
you want to create
public static void main(String args):
- Click Finish and your new class shows up in the editor window.
- At the top of the main method, you need to insert the
ArgsProcessor code to accept two integers:
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.
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
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.
- Finish the class so it prints out the appropriate message.
As a group, brainstorm the best data type to represent the following
Often, there is no right or wrong answer. Be prepared
to defend your choices.
Submitting your work (read carefully)
- If your studio contains a feedback.txt file, respond to
the questions and supply any requested information.
- You must commit all of your work to your repository. It's best to do this
from the top-most level of your repository, which bears your name and student ID.
- Follow the instructions in the green box below to receive credit for your work.
Last modified 08:59:37 CST 09 January 2015
When you done with this studio, you must be cleared by the TA to receive credit.
- Commit all your work to your repository
- Fill in the form below with the relevant information
- Have a TA check your work
- The TA should check your work and then fill in his or her name
- Click OK while the TA watches
- If you request propagation, it does not happen immediately,
but should be posted in the next day or so