Lab must be completed and
reviewed by Peer Instructor on Tuesday, Jan 14 during lab class and no later
than the first 10 minutes of lab class on Thurs, Jan 16.
Description
In this lab you'll create
a new Java program using PFE that will generate the output specified below.
Task 1 - Prepare to create
your own 1st Java program.
- You may want to look
at the Java programs from Lab 2 to remind you of the structure required. In
fact, you can even copy a program, rename it, and use it to write this program.
Task 2 - Create the class
and method headers
- The class name should
be lab3 (so it will have to be saved in a file named what?)
- Since there will be only
one method, what should the name be?
- Make sure there's a comment
above the method describing what it does.
Task 3 - Build the comment
(banner) at the top of the program.
- Remember to include your
name, the section and course number, the assignment (lab3), and a description
of what the program will do.
- Use the // or /* symbols
to denote your comment.
Task 4 - Create some
variable declarations.
In your program, declare
7 variables:
- two int
variables (int1 & int2)
- initial values should be set to 4 & 7,
- one double
variable (num)) - initial value
should be set to 12.0,
- one char
variable (letter) - initial
value should be set to 'K',
- one boolean
variable (flag) - initial value
should be set to true,
- one double
variable (sum) - no initial
value should be specified, and
- one double
variable (product) - no initial
value should be specified.
Task 5 - Create the print
and assignment statements necessary to complete the lab.
- First, print some header
lines. They should look like this:
(include the " in your output, and use tabs in front of your name)
"My first program"
Your name
--------------- ---------
- Use the println method
from the System.out object to output a string concatenated with the value
of each variable.
Example: System.out.println("int1's
value is" + int1);
- Use assignment statements
to calculate the sum and the product of the three variables int1, int2, and
number.
- Store the results in
sum and product
respectively.
- Output a blank line.
- Output sum
on one line by itself, but over to the right one tab with the string, "sum's
value is "
- Output product
in the same way on the next line down.
- Output another blank
line.
- Output the concatenation
of all the variable's values on one line. No spaces necessary.
Example (these are not the correct values): 3423.0Hfalse21.0132.0
Task 6 - Compile and
execute the program.
Completion Requirements
Once you've completed the
lab, you should show the Peer Instructor that you have completed:
-- Run the lab3 program,
-- the PI will compare the specified output to your output.
-- then use PFE to show the lab3.java file to the PI, your comments and code
structure will be checked.