Write correct, successfully-compiling, correctly-running programs to accomplish the following tasks:
- UsingVariables.java -- In the main method of your first program, do the following:
- Declare the following variables, each in a separate, one-line statement (4 statements, total):
Name: |
Type: |
byteVar | byte |
boolVar | boolean |
fVar1 | float |
fVar2 | float |
- For each of the four variables, initialize each in a separate, one-line statement. For the float variables, you will need to put an "f" after the number. For example: 2.2f (4 statements, total)
- Write println statements (4 statements, total) to announce the current values of each (use your variables in String concatenation):
The current value of byteVar is 5
The current value of boolVar is true
The current value of fVar1 is 3.7
The current value of fVar2 is 5.5
- Change the values of each variable, and repeat the previous step by announcing the new values of those variables (8 statements, total).
- Swap the values of the float variables (fVar1 and fVar2) without using literals. (Number of statements may vary)
- Write println statements to announce their new values after the swap. (2 statements, total)
- VariablePractice.java -- In the main method of your second program, do the following:
- Declare a short variable in one statement on one line and initialize it on the next line in another statement. (2 statements)
- Declare a long variable and initialize it in a single, one-line statement. (1 statement)
- Declare two boolean variables in a single statement. Initialize each on separate lines, in separate statements. (3 statements)
- Declare two char variables and initialize both, all in a single one-line statement. (1 statement)
- Declare two double variables and initialize them to 5.5 and 9.7. (Number of statements may vary)
- Declare two int variables and initialize them to 22 and 85. (Number of statements may vary)
- Declare two String variables and initialize them to "carpe" and "diem". (Number of statements may vary)
- Write println statements with string concatenation expressions to produce the following output. This should only require the variables you declared in the previous three steps, with the exception of the last line of output, where you will need to concatenate some elements not contained within the variables. (4 statements):
diem229.7carpe
15.2carpe
90.5carpe2285
carpe, diem_8522
In at least 150 words, please address the following questions: - How did the process of creating these programs go for you?
- What were your main challenges and how did you overcome them?
- What did you learn that may be of use as you move along in this class?