![]() |
CS 111 - Introduction to Computer Science
Homework #2 |
NOTE: Homework that does not compile or is not submitted according to instructions may receive no credit. (See exception below.)
1. Write three versions of the Hello.java program that have different syntax errors. Call these Hello1.java, Hello2.java, and Hello3.java. (These will be the only non-compiling programs you will submit.) For each version, write a block comment that describes and explains the error message the javac compiler returns. Finally, write a version Hello4.java with a logic error and include a line comment to describe the logic error.
2. Write a program Intro.java that prints four lines with your (1) name, (2) year, (3) home town, and (4) reason for taking CS 111.
3. Write a program MyName.java that prints your name
___ ___ _ _ _ / __| / __| / | / | / | | (__ \__ \ | | | | | | \___| |___/ |_| |_| |_|The easiest way to approach this is to copy the output of the Figlet server to your program, escape the characters that need to be escaped, and surround each line with System.out.println(" ... ");
4. Exercise 2.13. There are a number of ways to indicate order of evaluation in your README file. One is evaluate the expression step-by-step as Java would, giving each intermediate result on a separate line. Another way is to list the operator (i.e. +, - *, / %) in the order they are performed when evaluating the expression. Finally, check your work by evaluating and printing the value of each expression in a program called SimpleMath.java.
For example, suppose the expression was 2 + 3 * 4. In SimpleMath.java,
you would include System.out.println(2 + 3 * 4);, and, in your README file
or SimpleMath.java comments,
include something like this:
2 + 3 * 4 = 2 + 12 = 14
or this:
* +
5. Exercise 2.28. Call your program CircleMath.java.
Note: You can calculate the square of radius by using either radius * radius or Math.pow(radius, 2).
Example Transcript (input underlined):
Radius? 10
diameter = 20.000000
circumference = 62.831853
area = 314.159265