User Tools

Site Tools


cs175:chess_squares_-_noloop

ChessSquares class


Topics: Strings, Input, Selection (if-else)

Each square on a chess board can be described by a letter and number:

The following pseudocode describes an algorithm that determines whether a square with a given letter and number is dark or light.

If the letter is a, c, e, or g
   If the number is odd
      color = "dark"
   Else
      color = "light"
Else
   If the number is even
      color = "dark"
   Else
      color = "light"

ChessSquares

Write ChessSquares.java to input a letter and number and output whether the specified square is dark or light.

Assume that the variables letter and color are of the String type. Assume that the number variable is of int type. Use only String and int types for this program.

Sample input/output:

   Input the square's letter:
   a
   Input the square's number:
   5

   That square's color is: dark

ChessSquares2

In ChessSquares2.java, use a method called getSquareColor that returns a square color based on a square letter and square number that is passed as input to getSquareColor. The same input/output must be the same as ChessSquares.java.


Link to ChessSquares.java

Link to ChessSquares2.java


cs175/chess_squares_-_noloop.txt · Last modified: 2014/10/29 04:34 by jchung

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki