Name:______
COSC 420: Special Topics (Java Programming)
Programming Assignment 2
Due Feb 9, 2004
10 points
Instruction for handing in homework: Use this sheet as the cover page for your homework assignment. Write your name in the space provided above and staple your solutions to this sheet before handing in.
Task 1: Below is a copy of a Java program that displays a drawing. Write it into your JBuilder editor. Follow the steps to create a class in JBuilder environment.
/*
Displays an 'art' drawing
Get Familiar with the concatenation property of JPL (Java Programming Language)
String Data type
*/
public class Art
{
public static void main(String[] args)
{
String s1 = " * * * * * * ";
String s2 = " * * * * * ";
String s3 = "______\n";
String s4 = “______\n";
System.out.print(s4 + s1 + s3 + s2 + s3);
System.out.print(s1 + s3 + s2 + s3);
System.out.print(s1 + s3 + s2 + s3);
System.out.print(s1 + s3 + s2 + s3);
System.out.print(s4 + s4 + s4 + s4 + s4);
}
}/* End Art.java*/
Submit a screen-shot (Alt-PrtSc then paste into paint or MS-Word and print from there) or you may run the program capturing the text output and print it. Attach the output to the printout of this document.
Task 2. Detecting syntax and logic errors
There are numerous opportunities for error in any program, many times in places that seem too simple to require close attention. What do you think the following program is supposed to do?
public class Cube
{
public static void main()
{
double height = 3.0; /* inches *\
double cube_volume = height * height * height;
double surface_area = 8 * height
System.out.println("Volume = " cube_volume);
System.out.println("Surface area = " + surface_area;
}
(a)Before you compile, take a look on this program. Will it work as it is? Give reasons
(b)Try compiling the program as it is. What were the results? Submit the compiler's error messages (image-print out).
(c)Fix the syntax errors. Indicate all the errors on the code. Submit a copy of your program's output (after the corrections of all syntax errors).
(d)If the program has any run-time error, Indicate it and fix the error and submit the corrected program and output.
(e)If the program has any logic error,fix the error and submit the corrected program and final output.
(f)Submit the corrected program and result.
Task 3: Write a Java program, using one class and the main method that will produce addition, subtraction, multiplication, and division of two numbers. Document your program appropriately and follow the naming conventions as described in your textbook. Also, clearly document input, process, and output on your program. Submit the source code and result.