Part 1:

Read the following code skeleton and add your own code according to the comments. Your TA is available if you have and questions and you may collaborate with your classmates if you need help.

Note: //--> Indicates a place where you should add code.

// class name matches the file name
public class Lab2
{ // we must have a main method to run the program
public static void main(String[] args)
{
// declare some variables of different types:
// an int called age
//-->
// a double called num
//-->
// a String called firstName
//-->
// a String called lastName
//-->

Part 2:

After Part 1, write a segment of code that will assign values to the variables you just declared. In addition, this code will print out the values of some of these variables.

// Assign a value to the "age" integer
//-->
// Assign a value to the "firstName" String
//-->
// Assign a value to the "num" double.
//-->
// Print the values of firstName and age in the following string:
// "< firstName > is < age > years old."
//-->
// Print the values of firstName and num in the following string:
// "< firstName >'s favorite number is < num >."
//-->

Part 3:

After Part 2, write a segment of code that will assign a value to the lastName variable after asking the user for the appropriate input.

// Use the Scanner class to ask the user for their last name and store the
// input in the 'lastName' variable.
//-->
// Print values of firstName and lastName in the following string:
// "< firstName >'s last name is < lastName >."
//-->

Part 4:

After Part three write a segment of code that will calculate the sum of products of four numbers and the product of sums of those same numbers.

// Declare and define the variables.
int x = 3, x2 = 4
int y = 5, y2 = 6
//Write one line of code that adds the values of the 'x' variables and 'y' //variables then multiplies these resultant values. Assign the result to a
//new integer 'pos' that you declare.
//-->
// Write one line of code that multiplies the values of the 'x' variables and
// 'y' variables then adds the resultant values. Assign the result to a new
// integer 'sop' that you declare.
//-->
// Print the value of 'sop' in the string: "The sum of products is: < sop >."
//-->
// Print the value of 'pos' in the string: "The product of sums is: < pos >."
//-->
} // End main()
} // end class Lab2

Sample Output:

Below is an example of what your output should look like when this lab is completed.

Sample Run:
John is 22 years old John's favorite number is 3.1415
John's last name is Doe
The sum of products is: 42
The product of sums is: 77
Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.