CIS 174                                                        LAB ASSIGNMENT  #4
Assigned date: Tuesday 2/19
Due date: Tuesday 2/26
30 points

Objectives

Lab 4.1 - [4 points]

Write a program that displays the numbers 5 through 15 and their squares. Require to use a Counter-Controlled while loop.

Sample run

Number    Number Squared
----------------------------
5                       25
6                       36
7                       49
8                       64
9                       81
10                   100
11                   121
12                  144
13                  169
14                  196
15                  225

A copy of your source code and run time output.

Lab 4.2 - [4 points]

Write a program that read positive integer numbers and accumulate only odd integer numbers.  Suppose that the number -999 marks the end of the data. Require to use a Sentinel-Controlled while loop.

A copy of your source code and run time output. Demonstrate the result to the instructor in the lab.

Lab 4.3 - [4 points]

Write a program that read positive integer numbers and accumulate only even integer numbers.  When the accumulated value is greater than 130, the program displays the accumulated value and then exits. Require to use flag-controlled while loop.

A copy of your source code and run time output. Demonstrate the result to the instructor in the lab.

Lab 4.4 [4 points]

Rewrite lab 4.1 using a for loop. Demonstrate the result to the instructor in the lab

Lab 4.5 - [8 points] 

Write a complete Java program that inputs, processes and outputs a one-dimensional array with the following operations:

  1. read 6 integer numbers input from the keyboard and store them into a one-dimensional array.   
  2. find and display the index of the largest element in the array
  3. display the largest element in the array
  4. find and display the index of the smallest element in the array
  5. display the smallest element in the array
  6. display all the array elements
  7. display the total of all array elements.

A copy of your source code and run time output. Demonstrate the result to the instructor in the lab.

Lab 4.6 [6 points]

In the class Picture, write a method called keepRed to keep just the red color. This means to set all the green and blue values to zero.
Write a main method to test the method keepRed.

A copy of your source code and run time output. Demonstrate the result to the instructor in the lab.