COS 126 Assignment 0 |
Programming Assignment |
The purpose of this assignment is to introduce you to programming in Java and familiarize you with the mechanics of preparing and submitting assignment solutions. Your goal this week is to learn to use DrJava for editing, compiling, and executing programs.
Hello, World. The purpose of this step is to set up your computer for developing Java programs.
Programming. Your job is to write four short programs on your own. We'll assume that you have already created, compiled, and executed HelloWorld.java by following the instructions in the previous part of the assignment.
outputs% java HiFour Alice Bob Carol Dave
Hi Dave, Carol, Bob, and Alice.
% java Ordered 10 17 49 true % java Ordered 49 17 10 true % java Ordered 10 49 17 false
This formula uses degrees, whereas Java's trigonometric functions use radians. Use Math.toRadians() and Math.toDegrees() to convert between the two.
% java GreatCircle 40.35 74.65 48.87 -2.33 // Princeton to Paris 3185.1779271158425 nautical miles
Write a program RGBtoCMYK.java that converts RGB to CMYK. Input three integers, red, green, and blue (not all zero), from the command line, and print the equivalent CMYK values using these formulas:
Hint. Math.max(x, y) returns the maximum of x and y.
% java RGBtoCMYK 75 0 130 // indigo cyan = 0.423076923076923 magenta = 1.0 yellow = 0.0 black = 0.4901960784313726
Program style and format. Now that your program is working, go back and look at the program itself. Did you include a header that will tell the reader who wrote the program, and what it does? (Also, if you are planning on doing any professional programming, you should get into the habit of also including instructions for compiling and running the program.) For full marks, your program should not only work correctly, but should conform to the recommended style and format so that it is easy to follow. Read Booksite Appendix B: Writing Clear Code. Follow the guidelines in the Reviewing your Programs section of the Checklist.
Writeup. With each assignment you must submit a text file named readme.txt that is a narrative description of your work. We provide a readme.txt that you should use as a template. Download this file and answer all questions in the space provided. You will need to read the COS 126 Collaboration Policy in order to answer the related questions in your readme file.
Questionnaire. Part of this assignment is to fill out the following brief questionnaire.
Browsing the course website. The next part of the assignment is to browse the COS 126 website. The address is:
It is essential that you understand what's where and how to get to it. Please follow the Treasure Hunt worksheet on the Precepts page. (You may complete this part with a classmate.)http://www.princeton.edu/~cos126
Submitting the assignment. The final part of the assignment is to submit HelloWorld.java, HiFour.java, Ordered.java, GreatCircle.java, RGBtoCMYK.java, and readme.txt via the Web submission system called Dropbox. To do this, click the Assignments link from the course website; click the Submit link for that assignment; and (if you aren't already logged in) login using your OIT NetID and email password. Upload the required files, and click the Check All Submitted Files button. Your programs should compile without errors or warnings; if not, fix the problem and resubmit the appropriate files. Remember that every file you submit needs to have your name, netID, and precept number.
Getting help. If anything is unclear, don't hesitate to drop by office hours, post a question on Piazza or email us. We also recommend reading the checklist, which provides some clarifications and answers to frequently asked questions.
Challenge for the bored (not extra credit). Try to solve Ordered without using any of the four ordered-comparison operators (< <= > >=). Try to solve RGBtoCMYK without using Math.max(). You don't need to use if for either one. Even if you solve these, we recommend submitting your original simpler solutions, which are less likely to have bugs and are more transparent to read.