Programming Assignment Checklist: Conditionals and Loops


Frequently Asked Questions

What are the goals of this assignment? To write several small Java programs so that you get accustomed to: declaring and initializing variables, using expressions, using conditionals and loops, arrays, and debugging your code.

What preparation do I need before beginning this assignment? Read Sections 1.2 and 1.3 of the textbook. Read Sections 1.3 and 1.4 of the textbook. You may also find it instructive to work through some of the other exercises and look at the solutions on the booksite afterwards.

How should I format my Java code? How much do I need to comment my code? Follow the style guidelines. Don't forget to put your name, login and precept in the header of every file, as well as a brief description (and/or example run) of each program.

I have the constants 6, 10, 51, 60, and 61 sprinkled through my TenDice program. Is there a better way? Yes, give your constants meaningful symbolic names, such as SIDES or NUMBER_OF_DICE. This will make your code easier to read, maintain, and debug. Beginning on this assignment, you will lose points for not doing so.

What does this error mean?
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at TenDice.main(TenDice.java:6)

This means that you are trying to access an element in the array that doesn't exist. The number at the end of the first line is the index into the array.
When the number is 0, it is possible the error refers to args[0]. Since that doesn't have a value, you probably aren't passing in any command line arguments to your program even though your program expects it.
Use the index number and the line number, in this case, 6, to determine what is wrong with your code.

Do I have to use command-line arguments to read the inputs? Yes, or you will lose a substantial number of points.

My output from RGBtoCMYK is almost the same as the sample on the assignment page. Only the last digit or two is different. Why is there this tiny discrepancy, and is my answer wrong? Computers work with limited precision, and so different algebraically equivalent solutions can give slightly different answers. In grading we ignore such tiny discrepancies (except for certain assignments later where we explicitly tell you otherwise).

Submission

Submission. When you submit, be sure to click the Check All Submitted Files button. Make sure that you submitted the right files and that they compile cleanly. You may resubmit a file after making corrections. The newly submitted file will overwrite the old one.

Testing and Debugging

Here are our results for sample runs of Time.

% java Time 725 
Start time: 12:00pm
End time: 12:05am

% java Time 1420
Start time: 12:00pm
End time: 11:40am
Possible Progress Steps

These are purely suggestions for how you might make progress. You do not have to follow these steps. The key to writing correct programs is to develop them incrementally, testing after each step.

Time.java program.

A drunkard's walk. This is similar in many ways to the gambler's ruin example from lecture and the textbook. The key to building a larger program is developing it incrementally.

Dice and the Gaussian distribution.

Reviewing your Programs

Needless to say, you should continue to follow the guidelines from earlier in the course. Here are some new conventions to keep in mind.

  • Efficient and clear code: This will be more important as we write more complicated programs. This week it includes ideas like:

    Enrichment

    Here are some famous and not-so-famous quotations about learning to program.