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. You will learn to use IntelliJ editor for writing, compiling, and executing Java programs, and TigerFile for submitting your work electronically.
Setting up a Java programming environment. In this step, you will set up a Java programming environment, either on your computer or on an OIT public cluster machine.
Programming. In the previous step, you created, compiled, and executed HelloWorld.java. Next, you will write two four short programs on your own.
You will need to make one minor edit: change the header to match the format prescribed in the Assignment FAQ.% java HelloWorld Hello, World
% java HiFour Alice Bob Carol Dave Hi Dave, Carol, Bob, and Alice.
% java HiFour Alejandro Bahati Chandra Deshi Hi Deshi, Chandra, Bahati, and Alejandro.
% java SumThree 2 5 8 2 + 5 + 8 = 15 % java SumThree -2 5 -8 -2 + 5 + -8 = -5
% java Ordered 10 17 49 true % java Ordered 49 17 10 true % java Ordered 10 49 17 false
Restriction: You may not use if statements on this assignment.
\( \textrm{distance} = 60 \arccos(\sin x_1 \sin x_2 + \cos x_1 \cos x_2 \cos(y_1 - y_2)) \)This formula uses degrees, whereas Java's trigonometric functions use radians. Use Math.toRadians() and Math.toDegrees() to convert between the two. For reference, a nautical mile is 1/60 of a degree of an arc along a meridian of the Earth (which is approximately 1.151 miles).
% java GreatCircle 40.35 74.65 48.87 -2.33 // Princeton to Paris 3185.1779271158425 nautical miles % java GreatCircle 48.87 -2.33 40.35 74.65 // Paris to Princeton 3185.1779271158425 nautical miles
Write a program RGBtoCMYK.java that converts from RGB format to CMYK format. Your program must take three integer command-line arguments red, green, and blue; print the RGB values; then print the equivalent CMYK values using these mathematical formulas:
\( \begin{align*} white \;&=\; \max \left \{ \, \frac{red}{255}, \, \frac{green}{255}, \, \frac{blue}{255} \, \right \} \\ cyan \;&=\; \Bigl(white - \frac{red}{255} \Bigr) \; \div \; white \\ magenta \;&=\; \Bigl(white-\frac{green}{255}\Bigr) \; \div \; white \\ yellow \;&=\; \Bigl(white-\frac{blue}{255}\Bigr) \; \div \; white \\ black \;&=\; 1 - white \end{align*} \)
% java RGBtoCMYK 75 0 130 // indigo red = 75 green = 0 blue = 130 cyan = 0.423076923076923 magenta = 1.0 yellow = 0.0 black = 0.4901960784313726 |
% java RGBtoCMYK 255 143 0 // Princeton orange red = 255 green = 143 blue = 0 cyan = 0.0 magenta = 0.4392156862745098 yellow = 1.0 black = 0.0 |
Hint. Recall that Math.max(x, y) returns the maximum of x and y.
Restriction: You may not use if statements on this assignment, but you may assume that the command-line arguments are not all simultaneously zero.
More things to do.
This will compile and execute your programs, alerting you to potential problems before we grade your work. Fix any problems and resubmit.
Getting help. If anything is unclear, don't hesitate to drop by office hours or post a question on Piazza. We also recommend reading the checklist, which provides some clarifications and answers to frequently asked questions.
Challenge for the bored (not extra credit). Redo Ordered.java without using the comparison operators (<, <=, >, and >=). Redo RGBtoCMYK.java without using Math.max(). Do not use if statements for either one. Even if you solve these, please submit your original solutions, which are likely to be simpler and easier to read.