Create Code

DMST 102 – Week 2 – Homework
• Create code that follows the instructions below.
• Use comments to label your code snippets with the matching exercise numbers. E.G.:
/* #1 */
Some code here
/* #2 */
Some more code here
• If you need to repeat code, but doing so will generate an error, comment out the earlier
completed code.
• The exercises between dashes are related and build on each other.
• Each numbered exercise is worth 1 point. 10 total.
• When completed, copy your code into a text document (any format) and submit it on
Blackboard. Name the file as follows: HW02-your last name-your first name

LOOPS
1. Create a list variable of your favorite foods with at least five foods in it.
a. Use one of the two types of for-loops to loop through the array and print out
each element in the list.
2. Use the second for-loop that you didn’t use in #1.
a. Loop through the list of favorite foods again.
b. This time, print the number of characters in the name of each food. (Review the
reference material for Strings, if you’re not sure how to do this.)
3. Create a while-loop that iterates through the numbers 1 – 10.
a. During each iteration, add the current number to the previous number and print
the result. Use only variables in the loop. Do not use hard-coded numbers.

VARIABLE SCOPE
4. Create a global variable and function. (They don’t need to be complicated.)
5. Create an example of scope that will generate an error.

OBJECTS
6. Create a class named Employee with no properties or methods.
7. Duplicate the code from #6 and add the following three properties:
a. name
b. title
c. age
8. Add a method (function) to the Employee class called ‘describe’.
a. In the method, use the class properties in #7 to print a description of the
Employee.
9. In main(), instantiate (create) an object based on your Employee class.
a. Assign it values for name, title, and age
b. Call the describe method.
10. Add a 2nd method to Employee class called ‘work’.
a. Add a named parameter to the ‘work’ method named ‘job’.
b. In the work method, print out the job parameter value.
c. Back in main(), call the work method and pass in a job that describes what your
employee does.

Don't use plagiarized sources. Get Your Custom Essay on
Create Code
Just from $13/Page
Order Essay