Homework 0: Hello, World

GOALS OF THE ASSIGNMENT

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:

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.

This part of the homework will walk you through setting up the necessary software on your computer, and making sure that it works. The software you need is all freely available, and the booksite provides a handy installer to set it up for you. Even if you have already installed Java on your computer, you need to complete this step to set up the course-specific software properly. The necessary tools are also installed on the Moore lab computers, but you will need a SEAS account to log in. If you are an engineering student, you should already have a SEAS account.

Non-SEAS Students: Request your SEAS account here - . It usually takes at least 30 minutes for your account to be activate. Even if you do not plan on using the lab computers, you should request an account now. If your own laptop stops working for any reason, you will be relieved to have immediate access to the lab machines. (Per SEAS policy, SEAS accounts are available only to registered students (including P/F), but not to auditors.)

Click on the accordion panel below that corresponds to your system.
Mac
Follow these instructions to set up Java, Dr. Java, and several additional tools that you will need throughout the semester. You must run this installer even if you already have a Java environment on your computer.
  • Log in to the user account in which you will be programming. Your account must have Administrator privileges (with a non-blank password) and you must be connected to the Internet.
  • You will need a Java runtime, which is installed by default on all versions of Mac OS X prior to 10.7 Lion. If you are running any version of Mac OS X prior to 10.7 Lion, run Software Update; if are running 10.7 Lion or newer but don't have a Java runtime, install the Java runtime.
  • To install:
    • Download introcs.zip
    • If you have Mac OS X 10.8 (Mountain Lion) or 10.9 (Mavericks), temporarily allow applications downloaded from anywhere by selecting System Preferences -> Security & Privacy -> General -> Allow applications downloaded from: Anywhere.
    • Double-click it to unzip it.
    • Double-click the introcs.app to perform the installation. If you receive a warning that introcs.app was downloaded from the Internet, click Open.
    • Enter your password when prompted.
  • If the installation succeeds, you will see the following:
    • A terminal window containing approximately this execution log.
    • A Standard Draw window containing the red bullseye and a textbook graphic.
  • Delete introcs.zip and introcs.app from your Downloads folder.
  • If you have Mac OS X 10.8 (Mountain Lion) or 10.9 (Mavericks), select System Preferences -> Security & Privacy -> General -> Allow applications downloaded from: Mac App Store and identified developers.
Windows
Follow these instructions to set up Java, Dr. Java, and several additional tools that you will need throughout the semester. You must run this installer even if you already have a Java environment on your computer.
  • Log in to the user account in which you will be programming. Your account must have Administrator privileges and you must be connected to the Internet.
  • Download introcs.exe and double-click it to perform the installation. If you receive a User Account Control alert before the installation, click Yes or Allow; if you receive a Program Compatibility Assistant alert after the installation, click This program installed correctly.
  • If the installation succeeds, you will see the following:
    • A Command Prompt window containing approximately this execution log.
    • A Standard Drawing window containing a red bullseye and textbook graphic.
  • Delete introcs.exe from your Downloads folder.
Linux
If you run Linux, follow Part 0 of these instructions to install DrJava and stdlib.jar. You will need to configure them manually. Make sure to run the config.sh to set up your CLASSPATH. You are welcome to install checkstyle and findbugs, but you do not need them for this course. (Moreover, the version of checkstyle that you install this way applies different rules than the version we run when you submit your assignment. It's safer to submit your code to see our checkstyle output.)
Using Lab Computers
The Java compiler and DrJava editor are installed in the Moore computer labs (Moore 100 and Moore 207).
  • 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".

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."

"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.
The introcs installer sets up tools to help you draw graphics and play sound (StdDraw and StdAudio) that are very simple to use.

For CIS110, we will be using a drawing library that we have called PennDraw (PennDraw is StdDraw that the textbook refers to with some additional functionality)
To do this part of your HW:

  1. Download PennDraw.java and put it in your hw folder.
  2. Open this up in DrJava.
  3. Click Compile in the DrJava toolbar.
  4. Click Run in the DrJava toolbar.
  5. You should see a drawing appear in a new window. If so, close the window and continue with the assignment. If not, we'll be happy to help you.

Here is some example code to make sure that drawing is working on your machine. It also gives you some examples of what can be drawn using PennDraw.
PennDraw is documented extensively on the PennDraw wiki

Make sure to update the header section so that it is your name, PennKey, and recitation (or ??? if you don't have a recitation yet). Make sure this code runs on your machine and pay attention to the comments in the code. Those should help you understand how the program works. Save this file as MyHouse.java .

 /**
 * Name : Arvind Bhusnurmath
 * PennKey : bhusnur4
 * Recitation : 110
 * 
 * Execution: java MyHouse
 *
 * An example drawing using the PennDraw library
 * This draws a house in the middle of a green field with a blue sky.
 */
	  
public class MyHouse {
    public static void main(String[] args) {
        PennDraw.setCanvasSize(500, 500);
        // draw a blue background
        PennDraw.clear(PennDraw.BLUE); 
        
        //draw a green field
        PennDraw.setPenColor(0, 170, 0);
        PennDraw.filledRectangle(0.5, 0.25, 0.6, 0.3);
        
        //change the pen color to a shade of yellow
        PennDraw.setPenColor(200, 170, 0);
       
        //draw a filled triangle (roof)
        PennDraw.filledPolygon(0.255, 0.70, 0.745, 0.70, 0.49, 0.90);
        
        //draw the house
        PennDraw.filledRectangle(250 / 500.0, 260 / 500.0, 120 / 500.0, 
                                 90 / 500.0);
        
        PennDraw.setPenRadius(0.005); // thicken the pen for outline drawing
        
        PennDraw.setPenColor(PennDraw.BLACK); // make the pen black
        
        // draw the roof outline        
        PennDraw.polygon(0.255, 0.70, 0.745, 0.70, 0.49, 0.90); 
        
        // draw the house outline
        PennDraw.rectangle(250 / 500.0, 260 / 500.0, 120 / 500.0, 90 / 500.0);
        
        // draw the door outline
        PennDraw.rectangle(298 / 500.0, 220 / 500.0, 40 / 500.0, 50 / 500.0);
        
        PennDraw.point(270 / 500.0, 220 / 500.0); // draw a doorknob
    }
}

In addition to HelloWorld and MyHouse, you must write your own program. Call the program MySketch and put it in a file called MySketch.java.

Design and create your own piece of digital art using Java and the PennDraw library. Think of yourself as a creative designer when choosing the topic of your design. This is your very first program, so here are some guidelines:

Here are some ideas to get you started:

Every assignment will have an accompanying "readme" file that you will fill out and submit. This is a required part of the assignment, although it usually takes only a few minutes. Among other things, the readme is where you will cite anyone you worked with or got help from, and where you can give any comments or feedback you have on the homework.
If you used images in any of your programs, you'll need to submit those images files as well in order for your program to run correctly. To do that, follow these steps:
"What if my assignment is late?"
You have four late days that you can use over the course of the semester. You do not need to ask before you use them, just use them. You can use only two late days per assignment. See the policies page for more details.
"I'm trying to submit, but I can't find the submission link."
The link goes away when you can no longer receive credit (when you're more than two days past the due date or when you're out of late days). You can submit as many times as you like, so be absolutely certain to Submit what you have before the deadline and resubmit if you are able to finish more in time. See the policies page for more details.
"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 since other students may well have the same problem. 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.