Question: Please help with these two java methods ???? Modify the Row class to allow rows to be created at different locations. To do this you
Please help with these two java methods ????
Modify the Row class to allow rows to be created at different locations. To do this you will need to complete the constructor that takes a row number as a parameter, and the moveVertically method. Row number 0 indicates the first row, and each additional row number should move the row down 50 pixels. The moveVertically method should move each square in the row by the given amount. (The squares created by this constructor should have size 48. DO NOT put any delays in this new constructor for the Row class.)
Here is my current row class....
import java.util.ArrayList;
public class Row { private ArrayList
public Row() { sqList = new ArrayList
} /* * @param rowNumber * row number 0 is the first row, after that * each row will move down 50 pixels. * */ public Row(int rowNumber) { int x = 0; for (int i = 1; i <= rowNumber; i++) { }
}
public void addSquaresToList() { int count = 0; while ( count < 8) { sqList.add(new Square(0 + count * 50 , 0 , 50, "red")); count ++; }
}
public void moveVertically(int amountToMove) { // new Square(x, y, size, "blue"); //new Square(100, 100, 40, "blue"); int x = 0; for ( int i = 0; i < 10; i++) { new Square(x+48*i,amountToMove,48) } }
public void changeSquareSize(int size) { int i = 0; for ( Square sq: sqList) { sq.setSize(size); }
} /** * changes even squares to black and is in the no-arg construtor. */
public void changeEvenToBlack() { int i; for(i = 0; i < sqList.size(); i =+ 2) { sqList.get(i).setColor("black"); }
} /** * this is a method to change all odd sqaures to black. */
public void changeOddToBlack() { for ( int i =1; i < sqList.size(); i =+ 2) { sqList.get(i).setColor("black"); } } /** * @param waitAmountMillis */
public void delay(long waitAmountMillis) /** * delays a number of mS. */ { System.currentTimeMillis(); long systemTime = System.currentTimeMillis(); while(systemTime + waitAmountMillis >= System.currentTimeMillis()) { // do nothing in this block } }
public ArrayList
public void setSqList(ArrayList
} }
I dont really under stand how to make the constuctor create each square and then make the moveVerticaly method move them once they have been created?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
