Lab 06

PLEASE NOTE: All lab exercises are due by Monday June 16th at 10:00am.
  1. Download Files
  2. Nested For Loops
  3. Hide and Seek
  4. Stock Market
  5. Request Lab Solutions

Download Files

Download the L06.zip file and extract the files to your cs125 folder in your home directory. You will use these files to complete this week's lab exercises.

1. Nested For Loops

Write a program (called NestedForLoops.java) that will read in two integers that correspond to the number of rows and columns of a board. Use nested for loops to place green pegs in every column of every second row of the board. An example is given below.

Submit the completed code for NestedForLoops.java below.


2. Hide and Seek

Open the java file named HideAndSeek.java in your Lab 06 folder. Add a loop to this program that will allow the user to play hide and seek. The location of the hidden peg is given by the integers secretRow and secretColumn. If the user clicks on the cell corresponding to secretRow and secretColumn the hidden peg is found. Show this by placing a red peg on the secret square. Otherwise, place a green peg on the square. Allow the user no more than 10 guesses and stop playing immediately if the secret peg is found. An example of a game is given below.

You will find the Board documentation and Coordinate documentation helpful. Both are also found under Resources --> Java.

NOTE: Use only the variables that are already declared.

Submit the completed code for HideAndSeek.java below.


3. Stock Market

This exercise requires two classes, Company.java and StockMarket.java, both of which are provided to you. These files are saved in the same directory. Read, but do not modify, Company.java. Then perform the four tasks indicated by the comments in StockMarket.java.

The market value of a company is simply the share price multiplied by the number of shares in the company. The data for this problem was taken from here.

Note: In Java, large double values are sometimes written using Exponent 'E'. That is, a number such as 1023.2356 may be outputted (displayed) as 1.0232356E3 (where E3 stands for 10 raised to the power of 3).

Submit the completed code for StockMarket.java below.


Request Lab Solutions

If you request solutions for this lab you will be sent an email that contains your answers as well as the expected answers. The email will be sent out to all interested students once the deadline for completing the exercises has passed for all students.