|
|
||||||
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
Due date and time: September 21, 2005 at 11:59:59pm
Points: 8
This homework is very light and is intended to make you familiar with writing Executable class files, using data types, compiling, and running. You can use any material from the lectures.
(4 points)
Place the code for this part of the homework in a file by the name of HW1Part1.java. Be sure to follow the exact capitalization.
Write an executable (runnable) class, in which you simply print out the following information about yourself (nothing too personal), one line at a time:
For each line that you print, place 2 spaces in the beginning, and indent your values so that the output appears tabulated. Use System.out.println() to write text to the screen.
Here's an example output:
(4 points)
Place the code for this part of the homework in a file by the name of HW1Part2.java . Be sure to follow the exact capitalization.
Write an executable (runnable) class, in which you experiment with primitive data types. Perform the following operations, and make data type casts only when necessary. Points will be deducted for unnecessary casts. The point of the exercise is to understand type casting for primitive data types. For each of the sub-problems, you will either declare variables or re-use previous ones. In addition, you are required to print out the complete operation, making use of the actual variables, noting their data types and possible casts, and using String concatenation. For example, given declared values long l1 = 1234567889, and double d1 = 1.987654321, you are asked to declare a third variable, a long (l2), which will hold the sum of the two, i.e. l2 = l1 + d1. This operation will throw some errors during compilation, and casting is necessary for the double d1 in order to obtain a valid long as a result. The final statement would be: l2 = l1 + (long)d1. Your output to the screen should be as follows:
Instead of actually writing out the numbers, you should use the variables in String concatenation, e.g.:
Use the submit script to submit your assignment (instructions on class web site).
|
||||||||||||||||||||||||||