12.07.2015 Views

COPYRIGHT 2008, PRINCETON UNIVERSITY PRESS

COPYRIGHT 2008, PRINCETON UNIVERSITY PRESS

COPYRIGHT 2008, PRINCETON UNIVERSITY PRESS

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

computational science basics 11Initialize ConstantsStore g, V0, θCalculate R, TBasic CalculationsLoop over timeY0 < t < T ?NLoop over timeCalculate x(t), y(t)Yt < 0 ?NPrint x, y“Not Yet Fired”“Grounded”EndEndFigure 1.5 A flowchart illustrating a program to compute projectile motion. On the left arethe basic components of the program, and on the right are some of its details. When writing aprogram, first map out the basic components, then decide upon the structures, and finally fillin the details. This is called top-down programming.1.4.2 Shells, Editors, and Execution1. To gain some experience with your computer system, use an editor to enterthe program Area.java that computes the area of a circle (yes, we know youcan copy it from the CD, but you may need some exercise before gettingdown to work). Then write your file to disk by saving it in your home(personal) directory (we advise having a separate subdirectory for eachweek). Note: For those who are familiar with Java, you may want to enterthe program AreaScanner.java instead (described in a later section) that usessome recent advances in Java input/output (I/O).2. Compile and execute the appropriate version of Area.java.3. Change the program so that it computes the volume 4 3 πr3 of a sphere. Thenwrite your file to disk by saving it in your home (personal) directory andgiving it the name AreaMod.java.4. Compile and execute AreaMod (remember that the file name and class namemust agree).5. Check that your changes are correct by running a number of trial cases. Agood input datum is r =1because then A = π. Then try r =10.6. Experiment with your program. For example, see what happens if you leaveout decimal points in the assignment statement for r, if you assign r equalto a blank, or if you assign a letter to r. Remember, it is unlikely that youwill “break” anything by making a mistake, and it is good to see how thecomputer responds when under stress.−101<strong>COPYRIGHT</strong> <strong>2008</strong>, PRINCET O N UNIVE R S I T Y P R E S SEVALUATION COPY ONLY. NOT FOR USE IN COURSES.ALLpup_06.04 — <strong>2008</strong>/2/15 — Page 11

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!