Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 help with board/pegs
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
tupac




PostPosted: Sat Sep 22, 2007 1:53 pm   Post subject: help with board/pegs

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
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: