|
Write several small Java programs so that you get accustomed to:
|
What preparation do I need before beginning this assignment? Read Section 2.3 of Intro to CS. You may also find it instructive to work through some of the other exercises and look at the solutions afterwards.
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 below.
For Hellos.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 Hellos.java, if the command line parameter is N, how many lines of output should I have? N.
What range of inputs should Roots.java work? You may assume that c is positive and that k is a positive integer less than 20.
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.
For Quadratic.java, what should I do with repeated roots of when a is zero? In the first case, it's fine to print out the root twice. In the second case, there will be at most one root to print out, depending on whether b and/or c are zero.
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.
* * * * * * * * * * * * * * * *
|
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:
Equal3.java Quadratic.java Hellos.java PrimeCounter.java NPerLine.java Average.java Root.java GamblerPlot.java Checkerboard.java
readme.txt. You will find the template readme file in this directory.