<p>rahful - I don’t get your code.
You were supposed to return the index of the lowest leveled fuel tank under the threshold if any.</p>
<p>EDIT:
zrath - That’s exactly what I did but I didn’t think of using a while loop.
I just had an int increment if the value was 0, and if it wasn’t 0 then I just used break. But same thing. On GridWorld, you forgot the constructor. You actually could have left it empty since it required no parameters so it would just make a call to the default super().</p>
<p>supercuber - lol, that’s number 3. this is the one where you adjust the values of an array so there are none greater than the threshold and none less than the negative threshold. looking at my code right now, i dont know why i did the && array* > 0… i thought i had a good reason when i added it at the last second when reviewing my code. hmph.</p>
<p>@SuperCuber, I think I’m mixing up the question that involved absolute value with this one. I actually probably meant if(whateverItWasCalled[x]<threshold). Ahhhhjdsklfjklasdfjoidsajrioewamklfcmkdsaljklf. I didn’t realize we had to return the lowest value. I misread. THAT’S NOT EVEN HARD! Ugh…going to cry now.</p>
<p>@rahful, Was confused at first. That’s 3. Got it. & That looks right, I had something pretty similar.</p>
<p>You know what, at this point I have no idea. I think you’re right. I’m confusing myself in so many ways. But I do know which one you’re talking about, and I did do something similar :P</p>
<p>I thought 4.b was pretty simple, but all my classmates thought it was the hardest one. Is it just storing a string in a variable called temp, calling the method that puts message into the array, using a for loop to add every element back into temp, and then calling the other method which encrypts it and returning that, correct?</p>
<p>@supercuber, i dont think you need a constructor. critter class has no constructor, it inherits the one from the actor superclass (makes a blue critter facing north). i don’t think chameleoncritter has a constructor, does it? </p>
<p>either way, i think no constructor is the way to go.</p>
<p>edit: sorry, it does NOT inherit one, constructors are NEVER inherited. but when no constructor is supplied, the compiler makes it use the superclass default constructor.</p>
<p>Was this the one where you defined “encryptString()”? I did something like this:</p>
<p>
int numCells = numRows * numCols;
String encrypted = new String();
for (int i = 0; i < message.length(); i += numCells) {
if (i + numCells > message.length)
fillBlock(message.substring(i));
else
fillBlock(message.substring(i, i + numCells));
encrypted += encryptBlock();
}
return encrypted;
</p>
<p>Basically I looped through the string in chunks of size numCells, and stored each chunk in the matrix, encrypted the matrix, and appended the result to a string.</p>
<p>And I think Rahful’s right, you didn’t need a constructor because the problem didn’t require adding any fields to the class (which would need to be initialized in a constructor)–just methods.</p>
<p>Sorry… I actually didn’t know that.
AndrewT that’s what I did as well for 4b.
Argh your implementation was so wonderfully simple though.
Mine was a lot more complicated than it needed to be haha.</p>
<p>@andrewT, why did you say the for loop like that? Dosen’t fillBlock take a string as a parameter so you can just call fillBlock(message) which converts it to the Array and then use a for loop to traverse the array and add every element to String, and then encrypt the String and return that?</p>
int numCells = numRows * numCols;
//Finds total number of characters to feed to fillBlock
String encrypted = new String();</p>
<p>//Every turn through the for loop will send forward
//a String of numCells length. Note the increment factor.
for (int i = 0; i < message.length(); i += numCells) {
if (i + numCells > message.length)
//If there aren't enough characters left, sends forward the rest of the String
//to fillBlock to encrypt
fillBlock(message.substring(i));
// note: he forget to update to String here
else
//If there are enough characters left, it sends the next numCells characters into
//fillBlock to encrypt.
fillBlock(message.substring(i, i + numCells));
encrypted += encryptBlock();
}
return encrypted;