Homework 0: Hello, World
Goals
The purpose of this assignment is to introduce you to
programming in Java and familiarize you with the mechanics of
preparing and submitting assignments. The specific goals are to:
- Familiarize yourself with the course web site and
booksite;
- Set up and use DrJava for editing, compiling, and
executing programs;
- Edit, compile, and execute a Java program;
- Learn your way around our electronic submission system.
Part I: Collaboration Policy
Technical Difficulties: Our quiz
system is currently experiencing technical difficulties. It will
currently only let you submit when at least one answer is wrong.
Follow the directions below, except
do not submit the quiz
until we announce that the problem is resolved.
Complete the collaboration policy quiz here.
The collaboration policy is
extremely important to ensuring you learn as much as possible from the
homeworks, and this quiz is designed to make sure you understand it.
It will take only a few minutes. You will not be able to submit until
all answers are correct.
Part II: Registering for Piazza
The class discussion board is
hosted on Piazza. In addition to being an important forum for
discussing material,
we make all course announcements through
piazza.
- Read the instructions for
using piazza. They are complicated because posting code to piazza
is a bit of a pain, but it works well once you learn the
system. Don't worry if you don't understand everything
yet. You can always find these instructions by clicking the
Piazza link in the sidebar, and they will make more sense as the
semester progresses.
- Click the link at the bottom of the piazza directions to sign
up for the class message board.
Part III: Getting Started
This part of the homework will walk
you through setting up the necessary software on your computer, and
making sure that it works. The purpose of this step is to set up your
computer for developing Java programs. The software you need is all
freely available, and the booksite provides a handy installer to set
it up for you. It is also installed on the Moore computer labs,
but you will need to configure certain aspects of the software
yourself.
- Using the booksite's installer The booksite provides
installation programs for
both Windows,
and Mac
that install the Java compiler, DrJava editor, and several
additional tools that you will need throughout the semester.
Click the appropriate link above for your computer, and follow the
directions to run the installer and write a test program. The
installer also configures java so it can access the booksite's
standard library, which you will need for later homeworks. You
must run this installer even if you already have a Java
environment on your computer.
- A note on path names In the installation directions, you
will see references to a folder named "username".
Replace this with the account name you log onto your
computer with. If you log in to your computer as
"bjbrown", you should substitute this for
"username" everywhere that it appears. More concretely,
"C:\Users\username\introcs" (Windows) and
"/Users/username/introcs" (Mac) refer to a folder named
"introcs" inside your home directory. The installer
creates this folder automatically.
- Installation on Linux If you run Linux,
follow these
instructions to install DrJava and checkstyle. You will need
to configure them manually. Make sure to run
the config.sh to set up your CLASSPATH.
- Using the Moore Computer Labs The Java compiler and
DrJava editor are installed in the Moore computer labs (Moore 100
and Moore 207).
- You must have a SEAS account to use these computers.
Engineering students should already have a SEAS account. All
other students can request an
account here.
As per SEAS policy, SEAS accounts are available only to
registered students (including P/F), but not to auditors.
- On the Windows machines, you will find DrJava in the CIS110
course-specific folder in the start menu.
- On the Linux machines, you can run DrJava by opening a
terminal and typing the command "drjava".
- Configuring DrJava. The lab machines do not
reliably save DrJava configuration settings, and you may need
to configure it properly every time you run it. First,
open the Preferences dialog in the Edit menu.
- In the Display Options category, make
sure Show All Line Numbers and Display Right
Margin are checked. Set Right Margin Position
to 80.
- In the Miscellaneous category, set the Indent
Level to 4.
- Later homeworks will make use of libraries provided by the
booksite, such as StdIn and StdDraw. On
those homeworks, you will need to download the library files
into your homework directory if you work on the lab machines,
because they are not configured to find them
automatically.
Frequently Asked Questions:
- Can I use the booksite instead of the textbook? No, the
booksite is a super-condensed version of the textbook; it is
suitable for reference while online (for example, while
programming), and is a great source of exercises. The textbook is
intended for use when initially learning new material and when
reinforcing your understanding of that material (for example, when
reviewing for an exam).
- What preparation do I need to complete this homework?
Read Section 1.1 and 1.2 of the textbook. If you don't understand
something, post to Piazza or visit your TA for assistance. Don't
be bashful about asking for help.
- How can I download a program from the textbook? The
corresponding section in the booksite contains links to
all of the Java programs in the textbook. The link goes to a
.java.html file (such as UseArgument.java.html)
that is suitable for display in a browser. You can cut-and-paste
the code into DrJava as needed. The .java.html file also contains
a link to the .java file (such as UseArgument.java);
you can right click this link and save the file to your
computer.
- I don't understand all of the jargon in HelloWorld.java.
Should I drop the course? Don't worry—we'll explain
this in the first weeks of the course. Do the readings and bring
any lingering questions to recitation.
- Do I have to use DrJava? No, you may use any editor you
like. However, we do not have the resources help you set up and
use a different editor. DrJava is specifically designed as a very
simple Java editor geared to academic use. It lacks the project
management features of more powerful environments like Eclipse,
but also avoids their complexity.
Part IV: Hello, World
This part of the homework walks you
through completing your first program. Traditionally, the first
program anyone writes in a new language just prints, "Hello, World."
- You should have created a HelloWorld.java file and
compiled it as part of setting up your environment in Part II. If
you haven't done so, refer to the directions in either the Windows
or Mac installer page.
- Add a file header comment to HelloWorld.java that
documents the author, date, program purpose, and brief
instructions for use. Every project and company has its own
guidelines for creating file headers; we follow the booksite's
format, but require you to add your Name, PennKey, and Recitation
at the top. Every .java file you submit must have a complete
file header. Here is an example header that you can adapt
for HelloWorld.java as well as all future programs:
/*************************************************************************
* Name: Benedict Brown
* PennKey: bjbrown
* Recitation: 200
*
* Compilation: javac HelloWorld.java
* Execution: java HelloWorld
*
* Prints "Hello, World". By tradition, this is everyone's first program.
*
* % java HelloWorld
* Hello, World
*
*************************************************************************/
Part V: More Programs
In addition to
HelloWorld, you must
write two additional programs.
- HiFive.java
- Read Section 1.1 of the textbook.
- Modify UseArgument.java
to make a program HiFive.java that takes five names
as command-line arguments and prints out a proper sentence
with the names in the reverse of the order given. For example,
the command,
% java HiFive Jackie Tito Jermaine Marlon Michael
might print
Michael, Marlon, Jermaine, Tito, and Jackie formed the original Jackson 5.
in which case the command,
% java HiFive Madam in Eden Im Adam
would print
Adam, Im, Eden, in, and Madam formed the original Jackson 5.
- You program may print out any sentence you like. Have
fun!
- You may assume your program will always be run with exactly five
arguments. You do not need to perform any error checking.
- Your program must read input using command-line arguments,
just like UseArgument.java. Command-line arguments
are described in Section 1.2 of the textbook.
- You must include a file header, but you do not need to
include any other comments in your program.
- SumThree.java
- Read Section 1.2 through page 22 of Intro to Programming.
- Write a program SumThree.java that reads three
integers from the command line, assigns them to three
variables, then outputs all three numbers and their sum. For
example, the command,
% java SumThree 2 5 8
should output
2 + 5 + 8 = 15
- You output must match the example exactly, including
the spaces around the "+" and "=" signs. Common sense does
not apply to computers, so it is essential to slavishly follow
every detail of specifications.
Otherwise bad
things can happen.
- You may assume your program will always be run with exactly
three, integer arguments. You do not need to perform any error checking.
- You must include a file header, but you do not need to include
any other comments in your program.
- Style
- Programming languages are less forgiving than human
languages of typos and small errors, but there are still many
ways to correctly format the same program. Some are more
readable than others.
- Read the Coding Style
guidelines. Make sure to follow the link to the booksite's
style guide.
- Don't worry about the guidelines for topics we haven't
covered yet. Focus on indentation, variable
names, and spacing.
- It takes practice to develop good coding style, so we will
give style feedback on your homeworks. We will also get
progressively stricter on deducting points for poor
style.
- You will almost certainly receive deductions for
style as well as logic errors throughout the
semester. That's normal, especially since you can't test for
style errors the way you can test for logic errors.
Part VI: Write-Up
With each homework we provide a template
readme file that you must download, complete, and submit. We will
generally ask you to provide a brief write-up of decisions you made in
the homework that are not part of the standard file headers, a few
related questions, and ask for you feedback. Filling in the readme is
usually quick, but it is important and worth a substantial number of
points.
- Always edit readme files in DrJava! Do not use TextEdit,
Notepad, or Word. All three of these programs save the file
in formats that we are unable to read.
- To open a readme file in DrJava, first save it to your
computer. Click "Open" in DrJava and select "All Files" for the
file format in the Open dialog box. You will then be able to
navigate to the folder where you saved the readme file and open
it.
- Download readme_hello.txt, open
it in DrJava, and answer all the questions.
Part VII: Submit
- Click "Submission and Scores" in the course menu bar.
- Log in with your PennKey.
- Select task hw00 and click the submit button.
- Upload HelloWorld.java, HiFive.java, SumThree.java,
and readme_hello.txt using the provided form.
- Click "Submit" to submit your homework. Save the submission
receipt as your proof of submission.
- Your file names should match the required exactly,
file names including
capitalization. Java is extremely picky about
file names and capitalization; if your file name doesn't match what
we expect, your program will probably fail our automated tests.
It may also be a sign that you submitted the wrong file
(e.g. HelloWorld.class instead
of HelloWorld.java). You can always re-submit to
correct such errors.
- The confirmation page shows you the recorded submission time,
which files have just been uploaded, which were previously
uploaded, and which have not yet been submitted.
- Read the Test Output section carefully. We show you the
results of a variety of automatic tests on every homework. Each
homework will describe the tests it runs. Usually, we will show
you the output of compiling your program on our servers (if you
program compiles correctly, there will be no warning or error
messages), a few simple tests, and the results of
checkstyle.
- The tests we run on your submission are
not complete, and do not guarantee your program works
perfectly. On some homework, we only show you the result
of compiling on our servers
- checkstyle automatically checks your program for conformance to
many aspects of our coding style guidelines. It is not
exhaustive. See the "Coding Style" section of the policies for
more information.
- All homework must be submitted through the
submissions system. We cannot accept e-mailed
submissions.
Frequently Asked Questions:
- What if my assignment is late? There is normally a
three-hour grace period during which you can still submit, but
cannot get help or receive extra credit. No submissions will be
accepted past the end of the grace period.
- I'm trying to submit on Wednesday at 12:15am. I can't find the
submission link. The link goes away when you can no longer
receive credit. Normally this at the end of the grace
period. Submit what you have before the deadline and
resubmit if you are able to finish more in time.
- My submission is on time, but I still can't see the link or
submission system isn't working. In this case only,
e-mail your code to your TAs. Post a question to piazza with your
problem and a screenshot of the error if possible. If
there's a bug in our submissions system, the error you see will
likely help us find and fix it. Unless the screenshot/error
reveals your code or personal information that you don't wish to
share, make the post public. We will look into the problem as
quickly as possible and get back to you. We will usually ask you
to resubmit once the problem is resolved, and will grant you an
extension if necessary so the new submission is not counted as
late.