This week the text introduces the concept of a simple array. This structure will allow us to create a variable that can hold a collection of items from the same data type. It also teaches us about another looping structure, the foreach loop, which is intended to be used to go through and read each element in an array. Once again we'll be looking at your code to be sure you are using the correct looping type, while, for, foreach, do/while.
For this exercise, we will simulate an interesting scenario where there is a system board with a row of unlit lights, along with their corresponding switches. The problem is such that we will have one person for each light on the board. One at a time, the people will come up to the board and switch the lights in a specific manner, as described. People and lights will be numbered using a 1based system. The first person (#1) will simply start with the light #1 and toggle every light (so that after their 'turn', all the lights will be on). The second person (#2) will then start at light #2 and toggle every second light. The third person (#3) will then start at light #3 and toggle every third light. And so on until each person has taken their turn. At the end, we'll want to see a count of the lights that are turned on, as well as a listing that describes the status of each light in the board.
You will need to develop a class named Light, which will keep track of the information about a light. Please know that the Light can either be on or it can be off.
This class should define methods:
This class will keep track of a collection of Light objects. In order to create a LightBoard, the number of Light objects must be specified.
This class will need to define the following methods:
Be sure to read through all items before you begin.
1. Create a new Java project named YourLastNameLab07
2. Add a new package named edu.westga.cs6311.lights.controller with two classes to be used for your informal tests:
3. Create a second package named edu.westga.cs6311.lights.model that contains the Light and LightBoard classes described in the Problem Statement.
As you are working, be sure to practice incremental development by writing informal test code in your LightDemo class to confirm correct functionality of each method. If you've forgotten how to write informal test code.
4. After you are certain that your code passes the informal tests, it's time to turn our attention to the actual application that we'll be creating. Add a package named edu.westga.cs6311.lights.view. Inside, create a LightBoardTUI class. This class should have exactly two instance variables: a Scanner and a LightBoard.
This class must define at least:
5. Finally, return to the controller package and add a new class named InteractiveDriver that will have a main method that creates a LightBoardTUI object and use it to call run.
Run 1:
Welcome to the Light Board Simulator
Enter the number of lights present: 3
After running the simulation, the board status is:
Light 0 is On
Light 1 is Off
Light 2 is Off
There are a total of 1 light(s) on.
Run 2:
Welcome to the Light Board Simulator
Enter the number of lights present: 6
After running the simulation, the board status is:
Light 0 is On
Light 1 is Off
Light 2 is Off
Light 3 is On
Light 4 is Off
Light 5 is Off
There are a total of 2 light(s) on.