Assignment 0: Set Up and First Java Programs

Objectives:

Due: Before the next class on Wednesday, Sep 10.

Setting Up Your Account

Create a directory for cs209 and a subdirectory for assign0 within the cs209 directory.

Part 1: Your First Program

In jEdit, create a Java class called Intro in a file named Intro.java. The Intro class's main method should print out, on separate lines, your name, your favorite color, and your favorite summer Olympic sport. For example:

Sara Sprenkle
Favorite Color: Purple
Favorite Summer Olympic Sport: Swimming

All the top-down design principles from CS111 and CS112 apply in any computer science course. Do not try to write the entire program in one go. Break the problem into manageable pieces.

You should write only a little code at a time, then compile and execute it so that you find bugs quickly. You're just getting used to the new Java syntax, so I'm sure you'll run into problems. If you run into problems, compare your code to the examples from class.

Make sure your program is well-documented, as discussed in class.

Compiling the Program

In a terminal, from the directory that contains Intro.java, compile your program using javac Intro.java

If there are errors, fix those errors and re-compile until it works.

Executing the Program

In a terminal, from the directory that contains Intro.java, execute your program using the command java Intro

If the output is not what you expect, edit your program, recompile and execute.

When you're sure your program is working correctly, execute your program using the command java Intro > output, which writes the output from java Intro into the file output.

Part 2: Fixing A Program

Objective: The goal of this part of the assignment is to get you familiar with the required Java syntax, the compiler's error messages, and how to fix the errors so that the program compiles.

Save Assign0.java into your assign0 directory.

This program contains at least 5 errors. Some are compiler errors that the compiler will catch. Others are logic errors that the compiler won't catch.

Comment out the original code and note the cause of the error. Then, correct the code.

Saving the Final Output

After you're sure the program behaves correctly, save the output in a file called debugged.out as you did in the last problem.

Part 3: Computing Molecular Weights

Write a Java class whose main method determines the total molecular weight of a molecule based on the number of hydrogen, carbon, and oxygen atoms it contains. You should use the following weights:

AtomWeight (g/mol)
H1.0079
C12.011
O15.9994

Note: The above weights should be class constants.

Since we haven't discussed input, you will need to hardcode the number of atoms in the program.

You should have an appropriately named Java class, in the appropriately named file. Your code will mostly be in the main method.

A sample run is shown below:

The number of Hydrogen atoms: 3
The number of Carbon atoms: 2
The number of Oxygen atoms: 1

Weight of molecule is 43.0451 g/mol

Saving the Final Output

After you're sure the program behaves correctly, run it a few times and save the output to files named like weight1.out

Turning in Your Assignment

Copy your assign0 directory into your turnin directory, i.e., /home/courses/cs209/turnin/yourusername.

For example: cp -r assign0 /home/courses/cs209/turnin/sprenkles/

There is no printed part of this assignment.

Grading (100 pts)

You will be evaluated based on

Part 1 (20 pts)

Part 2 (40 pts)

Part 3 (20 pts)

Style/Indentation (10 pts)

Turnin (10 pts)