CSC 120 Programming Assignment 1

Note: You should not work on this assignment during lecture or lab class-time unless:
  1. You have completed all of the in-class assigned work for the day, and
  2. You have permission from the instructor.

Overview:

Develop a Java Application program that draws a visual scene in the graphical output window.  Your application must declare, instantiate and draw at least TWO (2) objects from each of TWO (2) different classes that represent visual objects (in other words, the classes must have a draw method that can be called from the MUPanel class).  One of the classes will use the drawing methods of the Graphics class to display a Logo that you develop, and the other class will draw your initials made up of the shapes that can be drawn using the Graphics class methods.  Each Logo object and each Initials object must be drawn in a different screen location.  Details of this assignment and links to several example output screens appear below.

In effect, this assignment is quite similar to the Boat lab that we've worked on recently; with the requirement that two different-looking classes are written by the student, and at least two objects from each of the classes is drawn in different locations on the screen.

Instructions and Requirements:

  1. Create an application called PA1 (no spaces in the name, so PA1, not PA 1).  It should have the classes MUPanel, Initials and Logo in the files MUPanel.java, Initials.java and Logo.java, respectively.  To get started, you can use the MUPanel.java file from previous labs you've worked on in Java (Lab1, for example), and you can right-click on the following links and save the file in the src folder of your PA1 project:

    Then you can copy the Logo.java file and rename the copy as Initials.java, so you have three .java files in the src folder for your project.  You can change the class names Initials and Logo to names that are more meaningful for your project if you wish.

  2. In the MUPanel class, there should be two private data members (aka properties) of type Initials and two private data members of type Logo.  They should be instantiated inside of the MUPanel constructor, and in the paintComponentmethod each of these objects should be "asked" to draw themselves, by calling their draw method.

  3. The Initials class and the Logo class each should have data members of type Integer called anchorX and anchorY.  They may have other data members, too, as seen in the sample Logo.java file you copied earlier.  If you aren't going to use some of the data members in the given code, you should delete them from the file to keep your program as simple as possible.

  4. The Initials class and the Logo class each need a constructor method to initialize all data members.

  5. The Initials class and the Logo class each need a draw method that accepts a parameter of type Graphics.

  6. All drawing done by the draw method of the Initials class should be relative to one fixed point referenced by the anchorX and anchorY data members. For instance you might use something like

    g.drawRect(anchorX + 25, anchorY + 50, width, height);

    rather than something like

    g.drawRect(125, 250, width, height);

    Similarly, the draw method of the Logo class should also draw everything relative to one fixed point referenced by the anchorX and anchorY data members.

  7. The draw method of the Initials class must use various drawing methods of the Graphics class to draw the three initials of your name in some decorative style without using drawString.  You may use your initials or your first name.  (If you use your first name, the class should be called FirstName instead of Initials.)

  8. The draw method of the Logo class draws some kind of personal logo or some kind of scene relating to a favorite hobby, sport or interest of yours.

  9. You must use at least four different drawing colors, and at least four different drawing methods of the Graphics class (not counting setColor).  For example drawRect, fillRect, drawOval, fillOval, drawArc, and/or fillArc.

    Note:  You CANNOT use g.drawString to cause your intitals to be printed on the screen in the Initials class — you must create the initials from basic shapes like rectangles, ovals and arcs.  However, you can use g.drawString to draw some text in the Logo class.  See the last example below (the BOE example), where g.drawString was used to print the name of the soft drink on each of the bottles.

  10. DO NOT use any of the shape-drawing or shape-filling methods of the Graphics class in the paintComponent method of the MUPanel class.  All drawing must be done in the draw methods of the Logo class and the Initials class.

Hints:

Look here for some helpful hints.

Enhancements:

This assignment includes the requirement to add at least two extra visual features over and above the base requirements that make the output of the program more fun, interesting, or surprising.  Use your creativity and have fun with your drawings!  Here are some suggestions for things you could do as enhancements:
  1. One possible enhancement would be to define your own colors (in addition to the standard ones that are part of the Color class). To do this, you can use the following method call:
    g.setColor( new Color( red, green, blue) );
    where the three parameters shown above represent the intensities of the red, green, and blue components of your chosen color, respectively. Each parameter must be an integer number between 0 and 255.  How do you know the three primary color components of some shade you want to use (such as turquoise)? Visit the VisiBone Color Code Page to choose a color (the numbers shown diagaonally in each box give the red, green and blue values you should use when creating a new Color, in order from top-left to bottom-right).  As an example, to draw using a light shade of yellow, use the following Java method call: g.setColor( new Color( 255, 255, 153 ) );

  2. You could define an additional class or two to be other logo(s) that are displayed on screen along with your Logo and Initials objects as an enhancement.

  3. Another possible enhancement could be using an irregular polygon (see the Polygon Demo page).
You must document your enhancements by adding comment lines at the top of your program in MUPanel.java after your CSC 120, name, etc, comments.  Your comments should explain what you did for your enhancements.

Programming Style, Indenting, and Comments:

Every Java program written in the Department of Computer Science and Information Systems must follow the Department's documentation and style guidelines in order to obtain full credit.  Click on THIS LINK to see a list of requirements for programming style in CSC 120.

Turning in your Program for Grading:

When you have completed your NetBeans project for PA1 (including the comment header at the top of the MUPanel.java file with your name, etc.), use File Explorer to make a .zip file of the PA1 folder in your H:\CSC120\Java folder so that the file is named PA1.zip.  Then upload that file to the PA1 dropbox in D2L.

Note:  It is expected that each student will complete this assignment INDIVIDUALLY.

Examples:

Grading Rubric:

PA1 Grading Rubric