Assignment 02

Task

Write a program that prints a giant X of user-specified size.

Text: Java Tutorial -> Learning the Java Language -> Language Basics and/or Appendix A in the textbook
Concepts: variables, conditionals, loops, exceptions, user input.

Steps

Your program should be text-based (no GUIs). Ask the user to enter a size. This should be an odd integer between 1 and 79. If the user enters a String or an invalid integer, your program should give an error message and then keep asking the user until they enter something valid. (If you want to, you may also accept 0 as a valid input, which means print nothing and quit.)

Then print an X on the screen. There should be an 'X' character in the center, with the left-to-right diagonal formed by '\' characters and the right-to-left diagonal formed by '/' characters. The X should have a width and height equal to the number entered by the user. The only other characters that may be printed in the square formed by the X are spaces and newlines.

Sample Output

The following is taken from the command line and shows me running the program 5 separate times. The grey line is my prompt, and is not part of the program output. User input is shown in green.

C:\Files\webwork\UH\teaching\ics211\grading\A02>java ZtomaszeA02
This program draws a large X.
Please enter a size as an odd integer (1 - 79): 3
\ /
 X
/ \

C:\Files\webwork\UH\teaching\ics211\grading\A02>java ZtomaszeA02
This program draws a large X.
Please enter a size as an odd integer (1 - 79): 9
\       /
 \     /
  \   /
   \ /
    X
   / \
  /   \
 /     \
/       \

C:\Files\webwork\UH\teaching\ics211\grading\A02>java ZtomaszeA02
This program draws a large X.
Please enter a size as an odd integer (1 - 79): 1
X

C:\Files\webwork\UH\teaching\ics211\grading\A02>java ZtomaszeA02
This program draws a large X.
Please enter a size as an odd integer (1 - 79): 17
\               /
 \             /
  \           /
   \         /
    \       /
     \     /
      \   /
       \ /
        X
       / \
      /   \
     /     \
    /       \
   /         \
  /           \
 /             \
/               \

C:\Files\webwork\UH\teaching\ics211\grading\A02>java ZtomaszeA02
This program draws a large X.
Please enter a size as an odd integer (1 - 79): big
Sorry, but that is not an integer.  Try again.
Please enter a size as an odd integer (1 - 79): 6
The size must be an ODD integer.  Try again.
Please enter a size as an odd integer (1 - 79): 81
The size must be between 1 and 79, inclusive.  Try again.
Please enter a size as an odd integer (1 - 79): -3
The size must be between 1 and 79, inclusive.  Try again.
Please enter a size as an odd integer (1 - 79): 7
\     /
 \   /
  \ /
   X
  / \
 /   \
/     \

What to Submit

Name your class UsernameA02 in a file named UsernameA02.java. Your class and its main method must both be public. Do not use any packages. Upload your UsernameA02.java file to Tamarin.

Remember to follow the course coding standards on all assignments.

Grading [40 points]

5 - Compiles
15 - User input
Continues to prompt the user until she enters an odd integer, providing an appropriate error message on any bad input.
20 - Prints the X correctly
Correct size and shape and formed only of the requested X, \, /, and space characters. Use one or more loops to draw the shape.