Description
What this Lab Is About:
- This program is for practicing the use of primitive data types, expressions. – Chapter 2
Use the following Coding Guidelines:
- When declaring a variable, you usually want to initialize it.
- Remember you cannot initialize a number with a string.
- Remember variable names are case sensitive.
- Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes classes, methods, and code associated with ifs, switches and loops. Be consistent with the number of spaces or tabs that you use to indent.
- Use white space to make your program more readable.
- Use comments after the ending brace of classes, methods, and blocks to identify to which block it belongs.
At the beginning of each programming assignment you must have a comment block with the following information. The number in the left column indicates the line number. Go to the View menu à Line Numbers in TextPad, then you will see the line numbers, which is very helpful in fixing the errors.
1. Getting Started
Create a class called Lab2. Use the same setup for setting up your class and main method as you did for the previous assignments. Be sure to name your file Lab2.java.
Hints: See the sample output below in the lab for an idea of what your program should output.
2. Programming exercises
The following is a template of Lab2.java. It has three parts. Finish the part1, 2 and 3 one by one. Once you finish all parts and run the program correctly in your PC, submit the Lab2.java to the online site. The template Java code has each instruction as a comment block, but you don’t have to type them in your code.
Part 2: Assign Values to Variables
After part 1, write a segment of code which will assign values to the variables and print out the following:
********************************************************/
/******************************************************
Part 3: Using Mathematical Operators
After part 2, we will be finding the average of all the 4 numbers n1,n2,n3,n4 and will be initializing the variable avg with this result.
********************************************************/







