Problem Solving Assignment 3


Due: Tuesday, Jan 20, midnight (11:59pm)


You will be solving this homework as a pair-programming team. For more details on pair programming please go here. You need to visit 2 websites before you get started. DO THIS NOW

This homework requires skills from Chapter 2, Chapter 3, and Chapter 4 up to page 98.

Note, besides writing the code there is an interview process required for this PSA.
Details at bottom after turn-in instructions.


SetUp Problems
  1. Shapes - This program requires you create a program called CreateShapes.java and modify the existing Turtle.java file in order to draw four copies of the same shape (e.g., octogon, star, or some wierd shape you create, see below for restrictions) but with varying sizes so as to look something like this example (but you can't do squares, too easy :). As in the example, you are required to have all four of the shapes be the same shape and be nested within one another.

    To create this program you will need to do the following:

    • Turtle.java already exists in your PSA3/bookClasses directory. Open it in Dr. Java (File, Open, surf to your bookClasses folder in your PSA directory).
    • Modify Turtle.java by going to the bottom of the file (but above the last "}" bracket). You will add one method to Turtle.java named drawShape which takes in one integer parameter: size.
      • To be specific, you should add the following method AT THE BOTTOM of the Turtle.java file that looks like this (copy this into the bottom of the Turtle.java class, but BEFORE the last "}" in Turtle.java). Then fill in lines of code where indicated to make your drawShape method do something.
    • Create a program CreateShapes.java that will call drawShape 4 times on 4 turtle objects (this is your "application" program).

      In Dr. Java, open a new file, and copy this code into it. Save it in the PSA3/bookClasses directory. Add the lines inside the main method necessary to do the following:

      • Create a simple World.
      • Create four turtles in that world.
      • For each turtle you will call the method drawShape with a different size parameter (to get the nesting effect).
    • Hint: In order to get the shapes to be nested, you may need to have each turtle be created at different (x,y) locations in the world.

    Note: Please use the term "Shape" not the shape you use. We will be looking specifically for the method drawShape and for the file CreateShapes.java.

    You are required to use four turtles and have each sized shape a different color. However, feel free to be creative. The only shapes that are "not allowed" are squares (too easy :). You can use any shape you want (e.g. not all the "sides" of your shape have to be the same size... (ask on webboard if you don't get the idea...).

  2. Backgrounds - Write a program that will call two methods in Picture.java (Picture.java is in bookClasses folder). The first will set a picture to a single specified background color. The second will alternate between a specified color and black for each pixel in a Picture. You may not use techniques from Chapter 5 to solve this problem.

    Method 1: createSolid

    • Add a method (to Picture.java) called createSolid. You will add a method to Picture.java (be sure to use PSA3/bookClasses/Picture.java) that creates a "solid canvas" of a particular color. This method takes three parameters -- which are the desired red, green, and blue component values -- IN THAT order.
    • The method should set ALL the pixels in the picture to the color values indicated by the parameters.
    • SPECIFICALLY, this method must be submitted using a for each loop of the style on page 93 (although we encourage you to consider and try out for yourself how you would implement this method with other types of loops -- for example with a while loop -- it is not required).

    Method 2: createPattern

    • Add a method (to Picture.java) called createPattern. This method should set every other pixel in the picture to "black" (that is pixels at indices 0,2,4,6,8, etc.) and the other pixels to the color passed in as parameters (in the same red, green, blue format as in createSolid). That is, pixels in the picture's pixelArray with odd indices (1,3,5,7, etc.) should be set to the color values passed into the method as parameters.
    • SPECIFICALLY, this method must be submitted using a while loop (in fact, 2 while loops).
    • HINT Think about how you might want to update the index variable.
    • PLEASE DON'T USE JAVA TECHNIQUES FROM CHAPTER 5.

    Testing your methods (in an application):

    • Create a new file called PSA3B.java where you will write an application to test your methods. Start by copying in this code. Save the file in PSA3/bookClasses.
    • Fill in the statements (inside the main method) you need to test and show the results of your methods.
      • For each method we suggest you use the FileChooser.pickAFile() command to pick (inside mediasources) the file "640x480.jpg". (this is in your mediasources directory).
      • Next call your method.
      • Then show the result.
      Do this for each method you wrote (createSolid then createPattern). You should (for your personal gratification) check out the differences in the pictures you made -- so you can build up your understanding of how color setting works and so you can answer the tutor interview questions :).

How to turnin your homework electronically

When you are ready to turn in your homework, first open a terminal window by right clicking on the empty area of your computer's desktop (have to use lab computers or remotely connect from your home computer using SSH or Putty) and select "Open a New Terminal". Then, run bundlePSA3 from your PSA3/bookClasses directory. 4 files are required to be submitted for PSA3:

If you don't have one of these files present or have misspelled the name of one of these files, the bundle script will complain! Here you can see how you can run these commands:

-bash-2.05b$  cd ~/PSA3/bookClasses 
-bash-2.05b$  bundlePSA3 
Good; all required files are present:

        Turtle.java
        CreateShapes.java
        Picture.java
        PSA3B.java

Do you want to go ahead and turnin these files? [y/n] y
OK.  Proceeding.


Performing turnin of approx. XXXX bytes 
Copying to /home/linux/ieng6/cs8f/turnin.dest/cs8wxx.PSA3
.
Done.
Total bytes written: XXXX 
Please check to be sure that's reasonable.
Turnin successful.

Make sure the Turnin is successful, otherwise we won't receive your submission! . If you want to make changes after you've turned in your homework, make the changes and run bundlePSA2 again. The program will warn you that a "previously turned-in file exists" and ask if "you wish to over-write this existing file". Respond in the affirmative by typing y and pressing the Enter key.

Getting your interview done INDIVIDUALLY

10% of your grade on this assignment will come from an interview you will have with one of the tutors during Open Lab Hours. You have 48 weekday hours after the electronic turnin deadline to get your interview done. The deadline for the interview for PSA3 is Thurs Jan 22 (theoretically at midnight, but actually by the end of the last tutor hour scheduled). Remember, the tutors may be busy after 4pm helping CSE8B students

You get an interview by going into B260 during a scheduled tutor hour. Find the tutor, ask them if you can interview for the 8A PSA. If they have others who are waiting for interviews, your name will go on the end of the list of people waiting. Interviews take about 5 minutes each. It is your responsibility to go in early enough that you can get your interview completed. If everyone waits until the last hour on Thurs, this will not work.

For the interview you will need to have a copy of your team's assignment in your account. If you are using your partner's account to submit the files, make sure you email them to yourself and save them under your account so that you have them available for the interview. The tutor will ask you to log in, change to the directory where your work is and then to follow their directions. They will ask you to run your program to show that it works, open files in Dr. Java (or your favorite editor), and ask you questions about HOW your code works. Additionally, they may question you as to how you would (theoretically) make small changes to the program to have it do something slightly different. You will not actually be required to change your code.

Learning to be able to explain your problem solving process and discuss code with another human being is a very important professional skill. We hope that this process will help you develop this skill.