Problem Solving Assignment #2
Turnin Due Thursday 24nd, 11:59pm
Turnin for Extra Credit due Wednesday January 23rd, 11:59 pm
Interview Due Sunday January 27th, 12:00pm
Required Reading: Chapter 2, Chapter 3, and Chapter 4
Please read this whole page and be able to answer the understanding questions before starting on this assignment. Ask a tutor, TA or instructor if you have any questions before you begin.
You will work with a partner on this PSA. Before you begin you MUST have a partner. Please review the guidelines for pair programming. There is an individual interview required for this PSA which is 20% of your PSA grade.
Note: This PSA has a total of 16 points. However, all PSA assignments are weighted equally. The interview is always 20% of the total PSA grade (i.e. if you managed to obtain all 16 points but failed to complete an interview your total PSA grade would be 80%)
Please read this whole page and be able to answer the understanding questions before starting on this assignment. Ask a tutor, TA or instructor if you have any questions before you begin.
You will work with a partner on this PSA. Before you begin you MUST have a partner. Please review the guidelines for pair programming. There is an individual interview required for this PSA which is 20% of your PSA grade.
Note: This PSA has a total of 16 points. However, all PSA assignments are weighted equally. The interview is always 20% of the total PSA grade (i.e. if you managed to obtain all 16 points but failed to complete an interview your total PSA grade would be 80%)
Setup
1) Highlight the following 10 lines with the mouse, right-click to copy:
cd ../public/PSA2
make directories
make install
cd
cd PSA2
mv CreateShapes.java.empty CreateShapes.java
mv CreatePicture.java.empty CreatePicture.java
mv Picture.java.empty Picture.java
mv Turtle.java.empty Turtle.java
ls
2) Select the terminal window with the mouse and right-click to paste.
3) Verify that the 'CreateShapes.java', 'CreatePicture.java', 'Picture.java', 'Turtle.java' files is shown as the result of the last command.
Following these procedures, your file will be named correctly and be located in the correct places. For every assignment you need to follow correct naming
assignments in the correct locations to get credit for your work.
4) Proceed to start your programming assignment.
cd ../public/PSA2
make directories
make install
cd
cd PSA2
mv CreateShapes.java.empty CreateShapes.java
mv CreatePicture.java.empty CreatePicture.java
mv Picture.java.empty Picture.java
mv Turtle.java.empty Turtle.java
ls
2) Select the terminal window with the mouse and right-click to paste.
3) Verify that the 'CreateShapes.java', 'CreatePicture.java', 'Picture.java', 'Turtle.java' files is shown as the result of the last command.
Following these procedures, your file will be named correctly and be located in the correct places. For every assignment you need to follow correct naming
assignments in the correct locations to get credit for your work.
4) Proceed to start your programming assignment.
Problem
In this PSA you will be writing two separate programs one creating shapes and the other editing the backgrounds of pictures.
Shapes
This program requires you to 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., octagon, star, or some other shape, see below for restrictions) but with varying sizes so as to look something like this:
Shapes
This program requires you to 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., octagon, star, or some other shape, see below for restrictions) but with varying sizes so as to look something like this:
As in the example, you are required to have all four of the shapes be the same shape and be nested within on another. However, you cannot do square as that would be too easy. Your shape must be two dimensional (a line does not count as a shape)
When you are done coding this assignment, your program will do the following in the order listed:
1) Add an additional drawShape method AT THE BOTTOM of Turtle.java. Some code for this method is provided in the sample code section below. The rest of the method needs to be completed (2 points).
2) Use the size parameter appropriately in the drawShape method (2 points).
3) Create a file called CreateShapes.java. Some sample code is provided below.
4) Create a World for turtles (1 point).
5) Create four turtles in that world (1 point).
6) For each turtle, call the drawShape method with a different size parameter to nest the shapes (1 point).
Also properly comment your code and place both partners' names, PIDs, emails, logins, and the date in the header. You must place a history of each of your partners in the header (see PSA1 if you are unsure how). (1 pt)
When you are done coding this assignment, your program will do the following in the order listed:
1) Add an additional drawShape method AT THE BOTTOM of Turtle.java. Some code for this method is provided in the sample code section below. The rest of the method needs to be completed (2 points).
2) Use the size parameter appropriately in the drawShape method (2 points).
3) Create a file called CreateShapes.java. Some sample code is provided below.
4) Create a World for turtles (1 point).
5) Create four turtles in that world (1 point).
6) For each turtle, call the drawShape method with a different size parameter to nest the shapes (1 point).
Also properly comment your code and place both partners' names, PIDs, emails, logins, and the date in the header. You must place a history of each of your partners in the header (see PSA1 if you are unsure how). (1 pt)
Backgrounds
Once you are done coding this part of the assignment, your program will do the following in the order listed:
1) Add a method at the bottom of Picture.java called createSolid.
2) the createSolid method takes in three paramters - the desired red, green and blue component values - in that order (1 point).
3) the method sets all the pixels in the picture to the color values indicated by the parameters (1 point).
4) this method must use a for each loop of the style on page 93 (1 point).
5) Add a second method at the bottom of Picture.java called createPattern.
6) the createPattern method takes in three paramters - the desired red, green and blue component values - in that order (1 point).
7) the method sets every other pixel in the picture to "black" and the other pixels to the color passed in as parameters (1 point).
8) this method must use a while loop (1 point).
PLEASE DON'T USE JAVA TECHNIQUES FROM CHAPTER 5.
9) Create a new file called CreatePicture.java where you will test the above two methods. Some sample code is provided below for this file.
10) Fill in the statements inside the main method.
11) For each method we suggest you use FileChooser.pickAFileI() command to pick the file "640x480.jpg".
12) Next call your method.
13) Then show the result (2 points for proper execution).
14) Do this for each method you write.
15) Also properly comment your code and place both partners' names, PIDs, emails, logins, and the date in the header. You must place a history of each of your partners in the header (see PSA1 if you are unsure how) and the sample code provided has a template for you to fill in (1 point).
You should (for your personal gratification) check out the differences in the pictures you made they should look something similar to:
Once you are done coding this part of the assignment, your program will do the following in the order listed:
1) Add a method at the bottom of Picture.java called createSolid.
2) the createSolid method takes in three paramters - the desired red, green and blue component values - in that order (1 point).
3) the method sets all the pixels in the picture to the color values indicated by the parameters (1 point).
4) this method must use a for each loop of the style on page 93 (1 point).
5) Add a second method at the bottom of Picture.java called createPattern.
6) the createPattern method takes in three paramters - the desired red, green and blue component values - in that order (1 point).
7) the method sets every other pixel in the picture to "black" and the other pixels to the color passed in as parameters (1 point).
8) this method must use a while loop (1 point).
PLEASE DON'T USE JAVA TECHNIQUES FROM CHAPTER 5.
9) Create a new file called CreatePicture.java where you will test the above two methods. Some sample code is provided below for this file.
10) Fill in the statements inside the main method.
11) For each method we suggest you use FileChooser.pickAFileI() command to pick the file "640x480.jpg".
12) Next call your method.
13) Then show the result (2 points for proper execution).
14) Do this for each method you write.
15) Also properly comment your code and place both partners' names, PIDs, emails, logins, and the date in the header. You must place a history of each of your partners in the header (see PSA1 if you are unsure how) and the sample code provided has a template for you to fill in (1 point).
You should (for your personal gratification) check out the differences in the pictures you made they should look something similar to:
Sample Code
Sample Code for Shapes
/* Method : drawShape
* Created by: Partner Name1 PID1 Email1 and Partner Name2 PID2 Email2
* Partner history for Name1: PSA1 Name PID, PSA2 Name PID
* Partner history for Name2: PSA1 Name PID, PSA2 Name PID
* Date:
*/
public void drawShape(int size)
{
//Put all your commands to use the size parameter
//to make one copy of your shape. BE CREATIVE!
}
/* Filename: CreateShapes.java
* Created by: Partner Name1 PID1 Email1 and Partner Name2 PID2 Email2
* Partner history for Name1: PSA1 Name PID, PSA2 Name PID
* Partner history for Name2: PSA1 Name PID, PSA2 Name PID
* Date:
*/
public class CreateShapes
{
//The line below is magic, you don't have to understand it (yet)
public static void main (String[] args)
{
//Put all your commands to call drawShape 4 times on 4 different turtle objects
//Then REMOVE THIS COMMENT.
}
}
Sample Code for Backgrounds
/* Filename: CreatePicture.java
* Created by: Partner Name1 PID1 Email1 and Partner Name2 PID2 Email2
* Partner history for Name1: PSA1 Name PID, PSA2 Name PID
* Partner history for Name2: PSA1 Name PID, PSA2 Name PID
* Date:
*/
public class CreatePicture
{
//The line below is magic, you don't have to understand it (yet)
public static void main (String[] args)
{
//Put all your commands to open two pictures using FileChooser
//and call each method and show each result of calling the methods.
//Then REMOVE THIS COMMENT.
}
}
/* Method : drawShape
* Created by: Partner Name1 PID1 Email1 and Partner Name2 PID2 Email2
* Partner history for Name1: PSA1 Name PID, PSA2 Name PID
* Partner history for Name2: PSA1 Name PID, PSA2 Name PID
* Date:
*/
public void drawShape(int size)
{
//Put all your commands to use the size parameter
//to make one copy of your shape. BE CREATIVE!
}
/* Filename: CreateShapes.java
* Created by: Partner Name1 PID1 Email1 and Partner Name2 PID2 Email2
* Partner history for Name1: PSA1 Name PID, PSA2 Name PID
* Partner history for Name2: PSA1 Name PID, PSA2 Name PID
* Date:
*/
public class CreateShapes
{
//The line below is magic, you don't have to understand it (yet)
public static void main (String[] args)
{
//Put all your commands to call drawShape 4 times on 4 different turtle objects
//Then REMOVE THIS COMMENT.
}
}
Sample Code for Backgrounds
/* Filename: CreatePicture.java
* Created by: Partner Name1 PID1 Email1 and Partner Name2 PID2 Email2
* Partner history for Name1: PSA1 Name PID, PSA2 Name PID
* Partner history for Name2: PSA1 Name PID, PSA2 Name PID
* Date:
*/
public class CreatePicture
{
//The line below is magic, you don't have to understand it (yet)
public static void main (String[] args)
{
//Put all your commands to open two pictures using FileChooser
//and call each method and show each result of calling the methods.
//Then REMOVE THIS COMMENT.
}
}
How to Turn in Your Homework
1) Open the terminal
2) cd PSA2
3) autograder login -e yourucsdemailhere -p (wait for password prompt)
4) type in your password
5) turnin PSA2
2) cd PSA2
3) autograder login -e yourucsdemailhere -p (wait for password prompt)
4) type in your password
5) turnin PSA2
Understanding Quiz
Preferably before you begin, but certainly before you submit your assignment, make sure you can answer each of these questions correctly. The answers are provided here.
1. In which file do you put the method drawShape?
a. CreateShapes.java
b. Turtle.java
2. What is the correct method header for the method createPattern in Picture.java?
a. public void createPattern()
b. public int createPattern(int red, int blue, int green)
c. public void createPattern(int red, int blue, int green)
d. public Picture createPattern()
1. In which file do you put the method drawShape?
a. CreateShapes.java
b. Turtle.java
2. What is the correct method header for the method createPattern in Picture.java?
a. public void createPattern()
b. public int createPattern(int red, int blue, int green)
c. public void createPattern(int red, int blue, int green)
d. public Picture createPattern()