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 programs, javac for compiling them, java for executing them, and Moodle for submitting them.
Hello, World. In this step, you will setup an environment for developing Java programs.
Programming. In this part, your job is to write four short programs. We'll assume that you've already created, compiled, and executed HelloWorld.java by following the instructions in the previous part of the assignment. Before completing this part, you should read Sections 1.1 and 1.2 in the textbook.
% java HiTwo Alice Bob Hi, Alice! Have you met my friend Bob?
% java HiTwo Mickey Minnie Hi, Mickey! Have you met my friend Minnie?
% java Ordered 10 17 49 true % java Ordered 49 17 10 true % java Ordered 10 49 17 false
sin 2x + cos 2x = 1.Write a program SinCos.java that reads in a double value x from the command line, computes
sin 2x + cos 2xand prints out the result. Note that Math.sin(x) returns the sine of x and Math.cos(x) returns the cosine of x, where x is an angle measured in radians.
% java SinCos 0.534 1.0
% java SinCos 1.0 1.0
Write a program RGBtoCMYK.java that converts RGB to CMYK. Take 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
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.
Browsing the course website. The next part of the assignment is to browse the COS 126 Web pages. The address is:
Cruise around the COS 126 Web site; it is essential that you understand what's where and how to get to it. Be sure to fill out the online questionnaire. Also make sure you find the Assignment 0 checklist page, and also be sure to read the COS 126 Collaboration Policy and answer the related questions in your readme file.http://www.princeton.edu/~cos126
Submitting the assignment. The final part of the assignment is to submit HiTwo.java, Ordered.java, SinCos.java, RGBtoCMYK.java, and readme.txt via the Web submission system. To do this, go to the course webpage and select the HelloWorld assignment under Social Activities. Be sure to hit the Run Script button to check your program against our Java compiler. It should compile without errors or warnings; if not, fix the problem and resubmit it. To submit a file, you must be officially registered for the course.