In this homework, you will utilize the Scanner class in order to read input from the command prompt. You will also create a business card in order to gain some experience with graphics and applets.
On the first assignment, we did not discuss any code comments just for simplicity. Comments are very important, however, for software maintenance and understanding of your code. There is an old adage in development that says, "Comment your code so that someone who has no idea what the code does can understand it, because in six months that someone will be you!"
In this assignment we will begin requiring you to comment your code and we will gradually build this level up over the term. For HW2 we will begin to "javadoc" our code. Javadoc is an application that is part of the JDK that you downloaded. You can run it on the command line by typing "javadoc *.java" which will create documentation for all the classes in your current directory. If you are using JGrasp, you can invoke javadoc by using Project->Generate Documentation from the pull-down menu. Javadoc creates the nice web-page based documentation that we have been using in class (the API).
Remember from class we said that javadoc comments were a special form of comment. Javadoc recognizes a comment that starts with /** as a javadoc comment. For each new program assignment we will introduce new javadoc features. For HW2 we will create the following javadoc comments:
The class header:/** * This is HW2, problem 1. * This class rids the Earth of bad guys. */
You should also place good comments into your code when the algorithm you are using is not obvious. For the statement
int perimeter = a + b + c;a good comment might be:
// calculate the perimeter by summing the lengths of the sidesA bad comment would be:
//add a b and c together
A frequent syntax problem developers have is mismatched braces. One commenting technique that can really help you is to comment the close brace with a short description of what it is enclosing. For example:
} // end switch(x)
} // end main method
} // end class def Demo
We'll be looking at more javadoc and commenting issues in future HWs. For now, if you have more questions, check out the javadoc info page under the Java Resources page on the class website, or talk to your TA.
Write a java application that reads in a value that represents a number of seconds. Your program should then determine and output the equivalent time as a combination of hours, minutes and seconds. For example, 11,000 seconds is 3 hours, 3 minutes and 20 seconds. Your program should prompt the end-user to enter an integer value that represents the number of seconds. Your program should then calculate and print out the corresponding hours, minutes, and seconds. Call the class that you create TimeCalc.
Write a java applet that displays a business card of your own design. The card should include both graphics and text. At a minimum, your text should include your name and the graphics should include at least 3 or 4 different shapes from the Graphics class. You should also use a least 3 different colors on your card. Make the business card (applet) 400 pixels wide by 200 pixels tall, an aspect ratio similar to a real card. Make sure to include an HTML file that displays your applet in a web page. We will put some of the "coolest" cards off our class web page.
In order to view your applet, you can use appletviewer or run it as an applet from inside JGrasp, but you should also embed it in a web page for WWW viewing. You can do this in a web page editor or even a simple text editor. Since you may not know how to code html, the only line of code needed is given below:
<applet code="BusinessCardApplet.class" height=200 width=400></applet>assuming that your applet file is called BusinessCardApplet.java.
After you have finished the above assignments, turn them via Webwork You will be submitting three files: