Hi There!

I'm Dan Schlegel, an Associate Professor in the Computer Science Department at SUNY Oswego

Programming Challenge 4.5: Nonrepresentational Artistic Extra Credit

Overview

Your task is to write several separate Java programs for this assignment, all but one in the context of the Nonrepresentational Painting World (NPW). These programs, with the one exception, will make use of both the painter functionality and the shapes functionality of the world. You will be asked to place each of these programs, including the one exception, in the npw package of your CS1 project.

Why do it?

By composing Java solutions to these non-representational artistic expression problems you will:

  1. Gain considerable practice in creating and using objects.
  2. Gain considerable practice in program modification.
  3. Practice using selection and repetition constructs.

The Entrance

You should review the Nonrepresentational Painting World functionality, and the mechanisms for selection and repetition previously presented in lecture and in lab.

Problem 1: Text Rectangles

Write a program called TextRectangles in your npw package that will (1) accept, from the standard input stream, data corresponding to the number of rows and number of columns in a rectangle made up of stars, and (2) print, to the standard output stream, the rectangle of stars. Your program should be consistent with the following set of three demos:

Moreover, your program should be consistent with the following Java program text. What I did was to write the program, and then delete the instructions within the main method, and the entire drawOneRow method. Your job is to add the instructions back. Or at least, instructions which will do the job. Other than adding instructions pertaining to these two methods, all of the executable code should remain exactly as in the accompanying program text. You should be able to use your program to generate the rectangles that appear in my demo, and many others, as well.

Problem 2: Rectangles of Randomly Colored, Black Framed Squares

Write a program called Number1 in your npw package to paint a rectangle of randomly colored, black framed squares centered in the canvas. The number of rows and columns, as well as the side length of the square, should be read from dialog boxes. Actually, I have written this one for you. What I would like for you to do is enter it carefully (don’t copy/paste!), run it several times, and study it! It’s important that you understand how it works for later parts of this assignment.

Problem 3: Hirst Squares

This one requires a stroke of insight! Write a variant of the Number1 program in your npw package which paints images like the one shown. Call this program Number2. You should do this task as follows:

  1. Copy the code from the Number1 class into a new class, called Number2.
  2. Edit the Number2 class, replacing all occurrences of “Number1” with “Number2” and also modifying the leading comment.
  3. Add exactly two instructions to the paintOneSquare method.. Important: Do not remove any instructions. Do not modify any other instructions. Just add exactly two instructions, as specified.

Of course you will want to run your program a number of times to be sure it’s doing what it’s supposed to.

Problem 4: Hirst Dots

Write a simple variant of your Number2 class in your npw package which paints images like the one shown. Call this program Number3. Moreover, do this task by:

  1. Copying and pasting the code from the Number2 class to a newly established Number3 class.
  2. Edit the Number3 file by replacing all occurrences of “Number2” by “Number3” and also modifying the leading comment.
  3. In doing the following item, please take special care to replace all references to squares (including sides) by references to circles/dots (including diameters).
  4. Do what needs to be done to your program to replace the randomly colored, black framed squares with randomly colored, unframed dots!

Run your program a number of times to see that it is doing what it is supposed to do.

Problem 5: Simple Dots

Write a simple variant of your Numnber3 class in your npw package which paints images like the ones shown. Call this program Number4. Moreover, do this task by:

  1. Copying and pasting the code from the Number3 class to a newly established Number4 class.
  2. Edit the Number4 file by replacing all occurrences of “Number3” by “Number4” and also modifying the leading comment.
  3. Arrange to accept one more item of information from a dialog box, a color name, either red or blue or green. You might like to consider doing this by securing the color input just after securing the other needed inputs, by calling an appropriately specific method analogous to the getNumber method, and then passing along the color to where it is needed in a cascading manner.
  4. Do what needs to be done to replace the randomly colored dots with the dots of the named color, or black dots should the user type in something other than the three specified color names.

Run your program a number of times to see that it is doing what it is supposed to do.

The Exit

  1. Due date: Thursday April 15, 2021
  2. Once you are ready, you must demo your programs for one of the TAs.
  3. You must post your work, a source program and an appropriate demo for each problem (Standard Output Stream for the first problem, images for the remainder of the problems), to your Web Work Site to receive any credit.