Aqua Phoenix
     >>  Lectures >>  Java 1  


1.19 Homework Assignment 1

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.

1.19.1 Part 1

(4 points)

Place the code for this part of the homework in a file by the name of 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:

  • First Name, Middle Initial, Last Name
  • CunixID
  • Preferred e-mail address
  • School you're in (College, SEAS, etc.)
  • University level (Graduate/Undergraduate)
  • Semester
  • OS Platform you use for development (Windows [XP, 2000, etc.], Mac, Linux, etc.)
  • Programming languages you are familiar with, e.g. C, C++, Perl, etc.
  • Level of programming familiarity (none, novice, advanced, expert)

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:

$ javac
$ java HW1Part1
  Name:        Alexander Haubold
  CunixID:    ah297
  School:      GSAS
  Level:      Graduate
  Semester:    5
  Platform:    Solaris
  Languages:  Java, C, Perl
  Familiarity: Advanced

1.19.2 Part 2

(4 points)

Place the code for this part of the homework in a file by the name of . 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:

long 1234567890 = long 1234567889 + (long) double 1.987654321
Instead of actually writing out the numbers, you should use the variables in String concatenation, e.g.:

System.out.println("long " + l2 + " = " + ......)
  1. Declare integer i1: value 3000, declare integer i2: value 101, and declare integer i3: sum of i1 and i2.
  2. Declare double d1: value 101.3, use previous integer i1, and assign to integer i3: sum of d1 and i1.
  3. Use previous double d1, use previous integer i1, and declare double d2: sum of d1 and i1.
  4. Declare long l1: value 100200300400, declare float f1: value 3.1415, and declare long l2: product of l1 and f1.
  5. Use previous double d1, use previous float f1, and declare float f2: d1 divided by f1.

1.19.3 Submission instructions

Use the submit script to submit your assignment (instructions on class web site).