if anyone here is in UW CS133 please give me some pointers as to how to go by this program:
In this section, write a program that accepts an input number N (using the Scanner class), where N is between 1 and 5 inclusive. If the number is outside of that range, print an error message and exit. Otherwise, draw an instance of the Board class that has dimensions (2N + 1) by (2N + 1) and draw a series of squares on it using black pegs so it appears like the figure below.
*|*|*|*|*|*|*|
*| | | | | |*|
*| |*|*|*| |*|
*| |*| |*| |*|
*| |*|*|*| |*|
*| | | | | |*|
*|*|*|*|*|*|*|
^Something like that should be the output.
so far i have:
Quote:
import java.util.*;
import javax.swing.*;
public class squarePins
{
public static void main(String[] args)
{
Scanner inpScanner = new Scanner(System.in);
System.out.print("Enter the width of board: ");
String pegX = inpScanner.nextLine();
System.out.print("Enter the height of board: ");
String pegY = inpScanner.nextLine();
try
{
int intPegX = Integer.parseInt(pegX);
int intPegY = Integer.parseInt(pegY);
Board mainBoard = new Board(2*intPegX + 1, 2*intPegY + 1);
for (int i = 0; i <= 2*intPegX; i++)
for (int j = 0; j <= 2*intPegY; j++)
{
{
if (i%2 == 0 && j%2 == 0)
{
mainBoard.putPeg(Board.BLACK,i,j);
}
if (i%2 == 0 && j%2 != 0)
{
mainBoard.putPeg(Board.BLACK,i,j);
}
}
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"Error! Prgam is now terminating");
}
}
}
and the output looks something like this:
|*|*|*|*|*|
| | | | | |
|*|*|*|*|*|
| | | | | |
|*|*|*|*|*|
please help
thank you
- Dave