Computer science homework
Page 1 of 2 2014-09-30
CPS 150/Fall 2014 Assignment 2 Drawing a Better Looking Chessboard
Assigned: September 30, 2014 Due: Oct 3, 11 pm Cut-off: Oct 5, 11 pm
Tamisra H. Sanyal
Objectives: Organizing a modular program using void functions (methods), simple loop, named constants.
References: This assignment is based on ideas from lab 5. See also the exercise P2.15 (page 73) in your textbook.
In Lab 5 you worked on a program that was broken down into a number of functions (or methods). In this assignment
you will use similar ideas to write a program that will display a chessboard where the black and white squares are
surrounded by borders. Following the idea of defining string variables holding a pattern (P2.15, page 73), define the
following:
final static String Border = "+---+---+---+---+---+---+---+---+"; // 3 –'s between +'s final static String BWL = "|###| |###| |###| |###| |"; // black white line final static String WBL = "| |###| |###| |###| |###|"; // white black line
Put these 3 declarations between the line public class classname {
and the line public static void main(String [] args) {
created by Netbeans in your program. This will ensure that all methods in your program will be able to access these 3
identifiers.
These are the requirements:
• Write two methods. These should be static void methods, similar to main. See what was done in Lab 5. It is not necessary to make these methods public, but you could do so. Name these appropriately.
• One method should send the string Border to the output. Then it should send the string BWL twice to the output.
• The other method should send Border once to output, followed by WBL twice.
• The code for these two methods should appear after the code for the main method, but before the final } that ends the class.
• The main method will: o Display the output identification line (with your name) first. o Then it will use a loop to call the two methods four times (similar to Lab 5). o It may need to do something after that loop to make the picture look correct. o Finally, it will display the sign-off message.
Note: The System.out.println's (the ones that display any of the patterns making up the chessboard) should not use the
patterns as literal constants; it should use the given names instead.
A sample output screen shot is given below. Your output should be the same (except for output identification line).
Submit a single Word document containing your Source program and output screen shot. Set your Word document to
Narrow margins, single line spacing and 0 pt paragraph spacing both before and after a paragraph. Also set the font to
Consolas (fixed pitch font). Submit both a printed copy and electronic copy on Isidore.
Page 2 of 2 2014-09-30