A
Java Course Outline
Using the Java By Dissection
book
by Ira
Pohl and
Charlie McDowell
Homework 1 - Simple Output
We will write a program to print out and explain a scientific
formula such as pi*r^2
or "pi -r-squared for the area of a circle.
We will use System.out.println(" ---- whatever--- ")
for each line
of explanation.
So in this simple case our program would print:
Area of a circle is pi*r^2 Where pi is the universal constant 3.14159. The variable r is the radius of the circle.The point of this exercise is to get to understand how to write, compile, debug and submit a simple Java program. Follow the text in terms of style conventions. You need to properly comment the program. The output should be legible and literate.
This is the classic HelloWorld program... Using your
favorite editor (Notepad works fine) create a new file called HelloWorld.java
and the following goes in...
// This program simply uses System.out.println to print the line Hello World! //note the use of the PI number public class HelloWorld { static double PI=3.14159; //this is a comment to let you know that PI is a number //that we are not using here... public static void main(String[] args) { System.out.println("Hello World! pi = " + PI); //prints the line } //end of main } //end of class
Then, compile from the DOS prompt by typing javac
HelloWorld.java
and run the app by typing java HelloWorld
If you wish you can also see if you can get the Java program to actually perform the computation of pi.
From the SimpleInput.java example in the book, write a program that will ask a user for their name, their age, and their favorite ice cream. Then print back to the user what they have entered. For example:
What is your name: Doug Whitmore What is your age: 12 What is your favorite ice cream: Rocky Road Hello Doug Whitmore! You are 12 years old, and you like Rocky Road ice cream!
You will use a String
object for the name and
ice cream, and an int
for the age.
Optional: try and figure out how many days in the years and print that out also.
Using the Web
Using the web resources,
find out every thing you can about the String
class
Strings
.