|
|
Write several small Java programs so that you get accustomed to:
|
|
What preparation do I need before beginning this assignment? Read Section 2.3 and the first three subsections of Section 2.4 of Intro to CS. You may also find it instructive to work through some of the other exercises and look at the solutions afterwards.
Where to I find the standard input methods? Download StdIn.java. Be sure to save it to the same directory you are using for your programs for this assignment.
Do I need to do javac StdIn.java? No. As long as StdIn.java is in the same directory as your program, the appropriate class file will be created when you javac your program.
How should I format my Java code? Follow the style from lecture and the booksite. Use JEdit to auto-indent your code. To re-indent after inserting/deleting code, select the code you want to indent and click Edit -> Indent -> Indent Selected Lines.
What names should I use for my programs? See the Submission section below.
When using standard input, should I output a message to the user indicating what needs to be input? For this assignment, that is OK. Be careful in future assignments. Many of our outputs in future assignments are being used as inputs to programs that will crash if they encounter a message to the user.
I've been reading ahead. May I use an array for Zodiac.java? No arrays this week, please, but hold that thought. We definitely want you to use arrays for next week's assignment.
For Zodiac.java, do we need to check for valid input? You should check for a valid month (1 through 12) and a valid date (1 through 31), but you do not need to check for a valid combination. If the user enters "java Zodiac 2 31" (as in February 31st), the program can output "Pisces." If the program does detect an invalid input, then output an error message and stop. The input is via the command line input, so there are no second chances.
For NHellos.java, what are the rules that dictate when to use "st", "nd", "rd", or "th" for printing the ith Hello? Any integer that ends in 0, 4, 5, 6, 7, 8, or 9 should always be followed by "th". Any integer that ends in 1, 2, or 3 should be followed by "st", "nd", or "rd", respectively, unless it ends in 11, 12, or 13 in which case it should be followed by "th".
For NHellos.java, if the input is N, how many lines of output should I have? N.
How long should PrimeCounter.java take when N = 1 or 10 million? Ours takes about 10 seconds for 1 million and 5 minutes for 10 million. Of course it will depend on the speed of your computer. If it takes substantially more, consult a preceptor.
What exactly is a 4-by-4 checkerboard? It has a total of 16 asterisks, 4 per row. Note that each row has 8 characters, alternating between asterisks and spaces.
* * * * * * * * * * * * * * * *
|
|
Test Data for Statistics. We have generated some input files for the Statistics program. Simply download the statdataN.txt files from the loops directory. Then use redirected standard input.
% java Statistics < statdata100.txt Average = 48.45403999999999 Std Dev = 29.434692414536972
Reference solutions. To help you check your work, we have provided reference solutions (the .class files, not the .java source code) to the exercises. Simply download the relevant .class file from the solutions directory and execute as normal. For example to run the program contained in PrimeCounter.class, type
Note that when you compile PrimeCounter.java, it will overwrite any other version of PrimeCounter.class in the current directory. Thus, to save our reference solutions, you should store them in a different directory, say solutions.% java PrimeCounter 1000 The number of primes < 1000 is 168
|
|
Submission. Use the following names for your programs:
Distinct.java Zodiac.java NHellos.java Statistics.java PrimeCounter.java Checkerboard.java BohrRadius.java
readme.txt. You will find the template readme file in this directory.