0

Ok I will post what I have for Java code at the end but here is what I need it to do. In the main method a boolean array called Lights is declared which runs through how_many (declared int).

Then I have to call a method called initialize which I am to pass in the lights array along with the size of the lights array as the first and second arguments (respectively).

This is followed by a for loop that calls the method do_pass over and over until I reach the end of how_many and toggles each array position either true or false. This will then start at the second position and if true will toggle false or if false will toggle true. It will do this until it starts at how_many and ends at how_many.

It will then print out how many are toggled true (on) by calling the method how_many_are_on

Here is my code so far:

import java.util.Scanner;

public class Lab7
{

   public static void main(String args[])
   {
      Scanner stdin = new Scanner(System.in);
      int how_many = stdin.nextInt();
      boolean [] lights = new boolean [how_many];

      initialize (lights[0].how_many);
      for (int a = 0; a < how_many; a++)
      do_pass(lights.length);
   }     

   public static void initialize (boolean [] resets, int size)
   {
      for (int i = size; i < size; i++)
         if (lights[how_many] == true)
            lights[how_many] = false;
   }  

   public static void do_pass(boolean lights[], int start, int end, int skip)
   {
      for (int index = start; index < end; index += skip)
         lights[index] = !(lights[index]);
   }

   public static int how_many_are_on(boolean lights[], int size)
   {
      int sum = 0;
      for (int count = 0; count < size ; count++)
      {
         if (lights[count] == true)
         {
            return true;
            sum ++;
         }
      }
      return false;
   }
}
PoByBolek
  • 3,775
  • 3
  • 21
  • 22
  • 6
    What is the question? – MadConan Nov 05 '13 at 12:59
  • it is not calling the initialize method at this point. – Daniel Gosz Nov 05 '13 at 13:18
  • 1
    This code does not compile. Please fix the compilation errors first. – Ingo Nov 05 '13 at 13:20
  • You should call the methode like this: initialize (lights , how_many); But you don´t need to do this in java since all the array values will be initialized to false anyway. – HectorLector Nov 05 '13 at 13:20
  • Hector, I understand that part but as each loop of do_pass goes through the array it will toggle to either true or false (the opposite of whichever one it was, ie if true it toggles to false) and that is where the method calls for initialize are to come in. – Daniel Gosz Nov 05 '13 at 13:28
  • It’s a bit surprising that the method `do_pass` can be compiled without errors. So it doesn’t seem to belong to the other methods… – Holger Nov 05 '13 at 14:55
  • so far the only part that does not compile is the calling of the method initialize in the main method. I tried what hector suggested and it asked for a class. – Daniel Gosz Nov 05 '13 at 15:02

1 Answers1

0

Your issue is you aren't passing in the right amount of arguments into your methods. Here is your initialize method's signature:

public static void initialize (boolean [] resets, int size)

This means it takes in an Array of booleans, and an int. In your main method you call it like this:

initialize (lights[0].how_many);

As you can see, you gave it one value, instead of the two that you needed to pass in.

Fix this, as well as some other methods wherein you don't pass in the required number of arguments.

Marcel Puyat
  • 325
  • 3
  • 8