
|
Current Assignments
Textbook Chapters & Case Study (Grid World) Exercises:
1st Semester
(1st Quarter)
(2nd Quarter)
2nd Semester
(3rd Quarter)
(4th Quarter)
|AP Course Main Menu|
Lesson 1 - Background~ Assignments
Lesson 1 (i.e., chapter 1) in the textbook has no programming projects
of its own. So while you are learning the academic material of Lesson
1, your teacher will provide time to key in projects that are actually
examples used in Lesson 2. This will provide you with time to become
familiar with JCreator and how to setup a workspace and its projects.
If you do not understand what all the code does, do not worry. It
will be explained later. Beginning in Lesson 2, instead of just
copying code, you will be writing original code of your own.
Login to your personal folder in 'Computer Science\AP Comp\' and create
a folder in your main directory named "java".
In JCreator, projects are grouped together in workspaces. We will
create a new workspace for each chapter. All projects for a given
chapter will be grouped under the same workspace.
Workspace:
Lesson01
- We will organize each workspace in a separate folder.
- Version 3.5 of JCreator DOES NOT create these separate workspace
folders automatically.
- We must create them first manually using Windows BEFORE WE START
USING JCREATOR.
- Using Windows, create a folder named "java" on folder
in 'Computer Science\AP Comp'. Then create a folder named
"Lesson01" (no spaces, please) inside the "java" folder.
- Using JCreator, create a workspace named "Lesson01"
(no spaces, please) and save it in the "java" folder on folder
in 'Computer Science\AP Comp'.
- This will create three files inside the "Lesson01" folder.
- Lesson01.jcd
- Lesson01.jcu
- Lesson01.jcw (the actual workspace file that keeps
track of all projects added to the workspace using a special
markup language called XML)
- The full pathname to your workspace file will be: "Lesson01\Lesson01.jcw".
- We will create one workspace for each chapter in our textbook.
You will only have to create a folder using Windows once for each
of these workspaces.
- BEFORE you start your first project, open folder
in 'Computer Science\AP Comp' using Windows and check to see that all
of your folders and files are in the right place.
Project:
Lesson01\HelloWorld
- Add a new project (Terminal IO Application) to your workspace named
"HelloWorld" (no spaces, please).
- When you add a new project to an existing workspace, JCreator automatically
creates a folder by the same name.
- Adding a project named "HelloWorld" will create a folder named
"HelloWorld" in your Lesson01 workspace folder.
- Inside this folder will be one file and two subfolders:
- The file named Lesson01.jcp, which keeps track of all files
added to the project, also using XML.
- The folder named classes will contain your compiled byte-code
files. For this project, the file will be named "HelloWorld.class".
Notice that the file is always named after the class it contains,
followed by ".class". This is a requirement of Java.
- The folder named src contains your source code, which in
this case is one file named "Lesson01.java".
- Remove the java code inside the main function (except for the first
and last lines) and key in the program on page 31 of your text.
- Compile and run the project.
Project:
Lesson01\Convert
- Add a new project (Teriminal IO Application) to your workspace named
"Convert" (no spaces, please).
- Remove the java code and key in the program on pages 42-43 of your
text.
- Compile and run the project.
Project:
Lesson01\GUIWindow
- Add a new project (GUI w Flow Layout) to your workspace named "GUIWindow"
(no spaces, please).
- Remove the java code and key in the program on page 47 of your text.
- Compile and run the project.
Project:
Lesson01\GUIWindow2
- Add a new project (GUI w Flow Layout) to your workspace named "GUIWindow2"
(no spaces, please).
- Remove the java code and key in the program on page 49 of your text,
except:
- Be sure to type a "2" at the end of "GUIWindow"
on the line that reads "public class GUIWindow{", like
this:
public class GUIWindow2{
- You must do this because the name of your project, the
name of the class, and the name of the source file
(the .java file in the src folder) must match each
other exactly, including capitalization. It's a Java rule.
- Compile and run the project.
Project:
Lesson01\GUIWindow3
- Add a new project (GUI w Flow Layout) to your workspace named "GUIWindow3"
(no spaces, please).
- Remove the java code and key in the program on page 50 of your text,
except:
- Be sure to type a "3" at the end of "GUIWindow" on the
line that reads "public class GUIWindow{", like this:
public class GUIWindow3{
- You must do this because the name of your project, the
name of the class, and the name of the source file
(the .java file in the src folder) must match each
other exactly, including capitalization. It's a Java rule.
- Compile and run the project.
Project:
Lesson01\GUIWindow4
- Add a new project (GUI w Flow Layout) to your workspace named "GUIWindow4"
(no spaces, please).
- Remove the java code and key in the program on page 51 of your text,
except:
- Be sure to type a "4" at the end of "GUIWindow" on the
line that reads "public class GUIWindow{", like this:
public class GUIWindow4{
- You must do this because the name of your project, the
name of the class, and the name of the source file
(the .java file in the src folder) must match each
other exactly, including capitalization. It's a Java rule.
- Compile and run the project.
Lesson 2 - First Java Programs ~ Assignments
Workspace:
Lesson02
- FIRST THING, create a folder named "Lesson02" (no spaces, please)
using Windows BEFORE you use JCreator to actually create the workspace.
- Create a workspace named "Lesson02" (no spaces, please)
- Save it in the "Lesson02" which is under your "java" folder on
drive K.
- This will create a file named "Lesson02.jcw" and two
other files we don't need to worry about--just don't delete them or
change them.
- The full pathname will be: "Lesson02\Lesson02.jcw".
Project:
Lesson02\PersonalInfo
- Textbook project, page 54, project 2-1.
- Add a new project (Terminal IO Application) to your workspace named
"PersonalInfo" (no spaces, please).
- Remove the java code inside the main function (except for the first
and last lines) and write a program that displays your name, address,
and telephone number.
- Compile and run the project.
Project:
Lesson02\YieldSign
- Textbook project, page 54, project 2-2.
- Add a new project (Terminal IO Application) to your workspace named
"YieldSign" (no spaces, please).
- Follow the textbook directions.
- Compile and run the project.
Project:
Lesson02\KlicksToNauts
- Textbook project, page 55, project 2-3.
- Add a new project to your workspace named "KlicksToNauts"
(no spaces, please).
- Follow the textbook directions.
- Compile and run the project.
Project:
Lesson02\MinutesToYear
- Textbook project, page 55, project 2-4.
- Add a new project to your workspace named "MinutesToYear"
(no spaces, please).
- Follow the textbook directions.
- Compile and run the project.
Project:
Lesson02\Momentum
- Textbook project, page 55, project 2-5.
- Add a new project to your workspace named "Momentum"
(no spaces, please).
- Follow the textbook directions.
- Use the Convert class source code on pages 42 and 43 as an example
of how to get user input, calculate, and display your results.
- Compile and run the project.
GRAPHICS
PROGRAMS:
For each of these projects, use a Terminal IO Application template and
make the appropriate changes (such as changing the import commands, as
done in the text examples).
Project: Lesson02\FranceFlag
Project: Lesson02\MauritiusFlag
Project: Lesson02\BulgariaFlag
- Textbook project, page 55, project 2-6.
- One at a time, add three projects to your workspace named:
- "FranceFlag"
- "MauritiusFlag"
- "BulgariaFlag"
- Follow the textbook directions.
- To help you, here are the the flags of the three required countries.
Flag of France
Flag of Bulgaria
Flag of Mauritius
- Compile and run each of the three projects.
Project:
Lesson02\Grid3x3
- Textbook project, page 55, project 2-7.
- Add a new project to your workspace named "Grid3x3" (no spaces, please).
- Follow the textbook directions.
- Compile and run the project.
Lesson 3 - Syntax Errors, and Debugging
~ Assignments
Workspace:
Lesson03
- Create a workspace named "Lesson03" (no spaces, please)
and save it in the "java" folder on drive K.
- This will create a file named "Lesson03.jcw".
- The full pathname will be: "Lesson03\Lesson03.jcw".
Assigned Projects
| Project Name |
Project Number |
Page in Text |
Lesson03\CubeSurface
The surface area of a cube can be know f we know the length of an
edge. Write a program that takes the length of an edge (an
integer) as input and printed the cube's surface area as output. |
3-1 |
103 |
Lesson03\SphereAreaAndVolume
Write a program that takes the radius of a sphere (a double) as
input and outputs the sphere's diameter, circumference, surface
area, and volume. |
3-2 |
103 |
Lesson03\MomentumAndKineticEnergy
Start this project, then copy/paste the code from Chapter 2 Momentum
into it. Then...
The kinetic energy of a moving object is given by the formula KE=(1/2)mv2,
where m is the object's mass and v is its velocity. Modify
the program of Chapter 2, Momentum, so that it prints the object's
kinetic energy as well as its momentum. |
3-3 |
103 |
Lesson03\EmployeePay
An employee's total weekly pay equals the hourly wage multiplied
by the total number of regular hours plus any overtime pay.
Overtime pay equals the total overtime hours multiplied by 1.5 times
the hourly wage. Write a program that takes as inputs the
hourly wage, total regular hours, and total overtime hours, and
displays an employee's total weekly pay. |
3-4 |
103 |
Lesson03\EmployeePay2
Copy the code from EmployeePay into this project's code window.
Then make the modifications described in the text:
Modify the program of Project 3-4 (EmployeePay) so that it prompts
the user for the regular and overtime hours of each of five working
days. |
3-5 |
103 |
|
Graphics
|
Lesson03\MullerLyer
The Muller-Lyer illusion is caused by an image that consists of
two parallel line segments. One line segment looks like an
arrow with two heads, and the other line segment looks like an arrow
with two tails. Although the line segments are of exactly
the same length, they appear to be unequal--like this:
Write a graphics program that illustrates this illusion. |
3-6 |
103 |
Lesson03\CenterPoint
Write a graphics program that displays the coordinates of the center
point of a panel in the form (x,y). This information should
be displayed at the panel's center point and be automatically updated
when the panel is resized. |
3-7 |
104 |
Graphics Practicum
Lesson03\HouseAndAppleTree
The following scene is drawn on an extended JPanel using rectangles,
rounded rectangles, and ellipses, except the triangle, which uses
the Graphic class's drawPolygon method. To draw a 3-sided
polygon (a triangle) you need to specify the three vertex points
using two separate arrays. Suppose your triangle's vertex
points were at (10,15), (20, 25), and (40, 55) and your Graphic
object is g. Here's your code:
int[] xCoords = {10, 20, 40}; // the x coordinates
int[] yCoords = {15, 25, 55}; // the y coordinates
g.setColor(Color.green);
g.fillPolygon(xCoords,yCoords,3); // fill the triangle with
green first
g.setColor(Color.blue);
g.drawPolygon(xCoords,yCoords,3); // draw the blue triangle
border second
Of course, the coordinates and colors you use for the roof of your
house will be different.
Write a Java program that draws the scene. |
|
|
Lesson 4 - Control Statements
Workspace:
Lesson04
- FIRST THING, create a folder named "Lesson04" (no spaces, please)
using Windows BEFORE you use JCreator to actually create the workspace.
- Create a workspace named "Lesson04" (no spaces, please)
- Save it in the "Lesson04" which is under your "java" folder on
drive K.
- This will create a file named "Lesson04.jcw" and two
other files we don't need to worry about--just don't delete them or
change them.
The full pathname will be: "java\Lesson04\Lesson04.jcw".
Assigned Projects
| Project Name |
Project Number |
Page in Text |
java\Lesson04\Division
Input must be done using two input dialog boxes. Since
dialog boxes return String objects, you will need to use
the Integer wrapper class's static parseInt method
to parse the resulting String objects and store their values
in int variables before dividing. |
4-1 |
146 |
| java\Lesson04\RightTriangle |
4-2 |
146 |
| java\Lesson04\PhoneCall |
4-3 |
146 |
java\Lesson04\Factorial
Modify the program provided on page 119 of your text so that
input is done using an input dialog box. Convert the input
from String to int using Integer.parseInt.
Test for valid numerical input using try/catch--like this:
boolean valid = false;
while (!valid)
{
try
{
String st = JOptionPane.showInputDialog
("Enter an integer greater than zero.");
n = Integer.parseInt(st);
valid = true;
// test for negative
values here
// if negative,
set valid back to false
}
catch(NumberFormatException e) { }
}
Input should repeat until the user enters a valid integer greater
than zero. |
4-4 |
147 |
java\Lesson04\PI
Input must be done using an input dialog box. Reject negative
and invalid values. |
4-5 |
147 |
java\Lesson04\Population
If pop is the starting population, gr is the growth rate,
tt is the total time, and gp is the growth period, then
total population = pop * gr(tt/gp) |
4-6 |
147 |
| java\Lesson04\Powers |
4-7 and 4-8 |
147 |
java\Lesson04\PowersFromTextFile
Copy the code from Power into this project's code window.
Then make the modifications described in the text. Use this text file. |
4-9 |
147 |
java\Lesson04\MakeWebpage
Write a Java program that will prompt the user to input (1) a title
for a web page and (2) two colors, one to be used as the background
color of the web page, and the other to be used as the font color.
Your program should generate a web page named "mywebpage.htm"
with the required title and colors. The title should appear
twice, once as the title of the webpage and again as a heading centered
at the top of the page. No additional text on the webpage
is required.
As a sample, if the user entered a title of "My Web Page" and two
colors as "yellow" and "green", then
this might be the webpage that would be generated. |
n/a |
n/a |
| java\Lesson04\Salary |
4-10 |
148 |
java\Lesson04\RadixMadness
Write a Java console application that converts a number of one
base (radix) to another base (radix).
Your program should prompt for a base, then have the user input
a valid positive number in that base. It should then ask for
the base to which to convert.
If the user enters anything invalid, or zero, the program should
halt. Otherwise it should repeat. (hint: use the Integer wrapper
class methods parseInt and toString that use radix) |
n/a |
n/a |
| GUI: |
|
|
java\Lesson04\CheckerBoard
You MUST use at least one loop to generate the checkerboard. |
4-11 and 4-12 |
148 |
| java\Lesson04\InducedContrast |
4-13 |
148 |
Lesson 5 - Defining Classes Intro
~ Assignments
Workspace:
Lesson05
- FIRST THING, create a folder named "Lesson05" (no spaces, please)
using Windows BEFORE you use JCreator to actually create the workspace.
- Create a workspace named "Lesson05" (no spaces, please)
- Save it in the "Lesson05" which is under your "java" folder on
drive K.
- This will create a file named "Lesson05.jcw" and two
other files we don't need to worry about--just don't delete them or
change them.
- The full pathname will be: "\java\Lesson05\Lesson05.jcw".
Assigned Projects
| Project Name |
Project Number |
Page in Text |
\java\Lesson05\StudentTester
- The code for Student.java, as
printed on pages 164-165 of your text without the additional
constructors, is provided for you. (You may copy/paste
its contents.)
- Add the extra constructors as specified. You will find
them printed in your text on page 166.
- Your StudentTester class should:
- Instantiate and display a student object using the first
additional (assignment) constructor.
- Instantiate another student object that is a copy of the
first student object using the second additional (copy)
constructor.
- Change the name of the first student object.
- Display the contents of both objects (using their toString
methods), which shows that the second student's name still
retains the original name even though the first student's
name was changed.
- Continuing to follow the directions in text project 5-2, write
a public method named validateData() and place in Student.java.
A student object's data is considered valid unless
- its name variable is empty
- one of its test scores is less than 0 (zero) or more than
100.
- If one of these invalid conditions is found to be true, an
appropriate string literal is returned displaying one of the
two messages "SORRY: name required" or "SORRY: must have 0 <=
test score <= 100". Otherwise, null is returned (see
page 160).
|
5-1
5-2 |
196 |
|
|
|
| \java\Lesson05\TestFraction |
5-3 |
196-197 |
\java\Lesson05\LuckySevens
- To save time in typing, you may copy/paste this starter code.
|
5-4 |
197 |
\java\Lesson05\TestBankAccount
- After initially creating this project, you will ADD a new
file that you name "BankAccount.java" into which you will type
the code for your new BankAccount class.
|
5-5 |
197 |
| GRAPHICS PROJECTS |
|
|
\java\Lesson05\ShowImages
- Here are four images to use:
|
5-7 |
198 |
| \java\Lesson05\ShowRectangles |
5-8 |
198 |
| \java\Lesson05\ClickaGrid |
5-9 |
198 |
|
Turtle Graphics
NOTE: Before you can compile and run any Turtle Graphics
project in this unit, you will need to point JCreator to the
Turtle Graphics library provided with the textbook.
If working at home, this file can be downloaded at http://home.wlu.edu/~lambertk/hsjava/.
If working in Classroom / Lab the files can be accessed here.
See Section 10.2 Turtle Graphics and Appendix I for documentation
on Turtle Graphics.
|
\java\Lesson05\DrawThreeHorizontalLines
- Write a Java program that uses Turtle Graphics to draw
three horizontal line segments, each having the same length,
and one of them is equidistant from the other two.
|
n/a |
n/a |
\java\Lesson05\MyRectangleDemo
- Write a Java class named MyRect that has
- four instance variables of type int that store
the coordinates of the rectangle's upper left corner, the
rectangles width, and the rectangle's height.
- three constructors
- a default constructor that sets the upper left corner
to (-75,50), the width to 150, and the height to 100.
- an assignment constructor that allows the client to
instantiate a MyRect object while specifying
the upper left corner, the width, and the height.
- a copy constructor.
- a mutator method named setLocation that allows
the client to change the two integer values of the coordinates
of the upper left corner.
- a method named draw of type void that draws
the rectangle using the instance variables and Turtle
Graphics using one parameter of type Pen: public
void draw(Pen p)
- Write a Java program named MyRectangleDemo that declares
and instantiates three MyRect objects.
- The first object uses the default constructor.
- The second object uses the assignment constructor.
- The third object uses the copy constructor to instantiate
a copy of the second MyRect object. It then
uses the setLocation mutator method to change its
location.
- Finally, the draw method of all three objects draws
the objects on the Turtle Graphics window (make the
window 500 by 500).
- None of the rectangles drawn may touch each other and
all should fit completely on the turtle's drawing panel.
|
n/a |
n/a |
AP®
Computer Science in Java ~ GridWorld Case Study ~ Part 1
|
Part
1, Observing and Experimenting with GridWorld
- You will find a GridWorld workspace on your AP folder
named GridWorld, setup to run using JCreator 3.5.
- Running the Demo
- Read pages 1 to 4.
- Do what it says and complete the questions "Do You Know?
Set 1" (provided as a handout by your teacher).
- Be prepared for a class discussion over these questions
and answers.
- Exploring Actor State and Behavior
- Read pages 5 to 7
- Do what it says and complete the Exercises on page 6 (provided
as a modified handout by your teacher).
- Be prepared for a class discussion over these exercises
and their results.
- Familiarize yourself with the "GUI Summary" on page
7.
- Which shortcut keys do you anticipate using the most
|
|
Lesson
6, Control Statements Continued ~ Assignments
Workspace: \java\Lesson06
- FIRST THING, create a folder named "Lesson06" (no spaces, please)
using Windows BEFORE you use JCreator to actually create the workspace.
- Create a workspace named "Lesson06" (no spaces, please)
and save it in the "java" folder on drive K.
- This will create a file named "Lesson06.jcw" and two other
files we don't need to worry about--just don't delete them or change
them.
- The full pathname will be: "\java\Lesson06\Lesson06.jcw".
Assigned Projects
| Project Name |
Project Number |
Page in Text |
\java\Lesson06\GuessNumber
- Reminder: the Random class is defined in java.util.Random.
See sample on pg 109 of text.
|
6-1 |
244 |
| \java\Lesson06\ComputerGuess |
6-2 |
245 |
\java\Lesson06\ConvertGrade
- INSTEAD of using the scale provided in the text, use the Newport
News grading scale.
- A (92-100), B(83-91), C(74-82), D(65-73), F(0-64)
- The top 2 numeric grades of a range get a plus. The
bottom 2 numeric grades of a range get a minus. No plus
or minus for Fs.
|
6-4 |
245 |
\java\Lesson06\GCD
Sample run #1:
Enter the first number: 64
Enter the second number: 40
Finding the GCD of 40 and 64:
Replacing 64 with 40 and 40 with remainder 24
Replacing 40 with 24 and 24 with remainder 16
Replacing 24 with 16 and 16 with remainder 8
Replacing 16 with 8 and 8 with remainder 0
The GCD is 8
Sample run #2:
Enter the first number: 7
Enter the second number: 11
Finding the GCD of 7 and 11:
Replacing 11 with 7 and 7 with remainder 4
Replacing 7 with 4 and 4 with remainder 3
Replacing 4 with 3 and 3 with remainder 1
Replacing 3 with 1 and 1 with remainder 0
The GCD is 1
Sample run #3:
Enter the first number: 50
Enter the second number: 25
Finding the GCD of 25 and 50:
Replacing 50 with 25 and 25 with remainder 0
The GCD is 25 |
6-5 |
245 |
\java\Lesson06\LuckySevensAgain
- Start with your code from Project 5-4 on page 197. Copy/paste
it into this project and get it running. Then make the
required modifications.
|
6-6 |
246 |
\java\Lesson06\PrimeTime
- Write a Java program that generates 10000 random integers
between 1 and 100 and outputs the following:
- The number of primes.
- The number of composites.
- The probability that a number was prime.
- You must write and use a static function named IsPrime
that returns a boolean True if its integer parameter is prime,
otherwise False.
|
n/a |
n/a |
| \java\Lesson06\PerimetersAndAreas |
6-7 |
246 |
\java\Lesson06\BaseConverter
- Write a Java program that accepts as input two positive integers
representing two bases--one to convert from and the other to
convert to--and then accepts another integer to be converted
from the first base into the second base.
- Negative input should be rejected. If either base is
zero, the program should quit without converting.
- Major hint: Use the Integer wrapper class and its overloaded
parseInt(string,radix) and valueOf(string,radix) methods.
See the handout entitled Wrapper Classes from Chapter 4.
- Sample runs:
Enter base to convert from: 5
Enter base to convert to: 3
Enter value to be converted: 1234
1234 base 5 equals 21012 base 3
Enter base to convert from: 16
Enter base to convert to: 2
Enter value to be converted: fe
fe base 16 equals 11111110 base 2
|
n/a |
n/a |
|
Graphics
|
| \java\Lesson06\BouncingCircles |
6-8
6-9
6-10 |
246 |
|
|
|
Lesson
7, Improving the User Interface ~ Console Assignments
Workspace: \java\Lesson07
- FIRST THING, create a folder named "Lesson07" (no spaces, please)
using Windows BEFORE you use JCreator to actually create the workspace.
- Create a workspace named "Chapter07" (no spaces,
please) and save it in the "java" folder on drive K.
- This will create a file named "Chapter07.jcw".
- The full pathname will be: "k:\java\Chapter07\Chapter07.jcw
Assigned Projects
| Project Name |
Project Number |
Page in Text |
k:\java\Chapter07\NewtonSQRT_Console
Create a console application as directed in the text.
Display the result accurate to 8 decimal places. (use System.out.printf) |
7-1 |
266 |
k:\java\Chapter07\NewtonSQRT_View_Console
Create a console application as directed in the text.
In this application, prompt the user for the number of decimal
places (2 to 10) and display the result accurate to that many decimal
places. (use System.out.printf) |
7-2 |
266 |
k:\java\Chapter07\CompoundInterest_Console
Create a console application as directed in the text.
If the user types an invalid integer, your program should re-ask
for that value. (use try/catch)
See below for a sample run. |
7-3 |
266 |
|
|
|
Sample run for CompoundInterest_Console:
Enter interest rate: x
Enter interest rate: 10
Enter initial investment: $1000
Enter initial investment: 1000
Enter number of years: five
Enter number of years: 5
Interest Table:
Year $ at Year Start Interest Earned $ at Year End
-----------------------------------------------------
1
1000.00 103.81
1103.81
2
1103.81 114.59
1218.40
3
1218.40 126.49
1344.89
4
1344.89 139.62
1484.51
5
1484.51 154.11
1638.62
6
1638.62 170.11
1808.73
7
1808.73 187.77
1996.50
8
1996.50 207.26
2203.76
9
2203.76 228.78
2432.54
10 2432.54
252.53 2685.06
AP®
Computer Science in Java ~ GridWorld Case Study ~ Part 2
|
Part
2, Bug Variations
Exercise 4 on page 6:
We have waited until after mastering Chapter 9, Arrays Intro,
to tackle exercise 4 because it involves arrays. We are
now ready to give it a try.
- JCreator 3.5 instructions:
- Add a new project named DancingBugRunner
to your GridWorld workspace.
- Then add a new class named DancingBug
to the DancingBugRunner project.
- Then follow the instructions in Exercise 4.
- There are two ways to interpret the instructions.
Both require that we rewrite the DancingBug's
act() method.
- One interpretation is that the DancingBug
will replace one turn with multiple turns during one call
of the act() method, after which super.act()
will be called. This means that all other actors in
GridWorld will wait while our bug spins
around and all turns have been completed. The trouble
with this interpretation is that the repeated turns of the
bug are so fast that we can't see them. Instead, the
bug appears to merely choose a random direction in which
to face before taking off again.
- The other interpretation is that the bug still only turns
once during each call to the act() method.
This method overrides the act() method,
and might not call super.act() at all.
Counters keep track of which element of the turn limit array
is being used as well as how many turns have currently been
made on the current turn limit element. This causes
our DancingBug to turn only once before
other actors on the grid perform their act()
methods once each. As a result, we get to see our
DancingBug spin around several times (as
determined by the array of turn limits) before it takes
off again.
- The student is allowed to code either interpretation,
but should be able to discuss both interpretations intelligently--including
any ways that might make the movement of the DancingBug
more interesting.
|
|
Lesson 9
Workspace: \java\Lesson09
- FIRST THING, create a folder named "Lesson09" (no spaces, please)
using Windows BEFORE you use JCreator to actually create the workspace.
- Create a workspace named "Chapter09" (no spaces,
please) and save it in the "java" folder on drive
K.
- This will create a file named "Chapter09.jcw".
- The full pathname will be: "k:\java\Chapter09\Chapter09.jcw
Assigned Projects
| Project Name |
Project Number |
Page in Text |
| Console Applications |
k:\java\Chapter09\IntLists
- Input up to 10 integers. Place even ints in an array called
EvenList, odd ints in an array called oddList,
and negative ints in an array called negativeList.
After entry, display contents of all three lists.
- Files:
IntLists.class
IntLists01.java
|
9-1 |
347 |
k:\java\Chapter09\AverageDoubles
- Input up to 10 floating-point numbers. Display average
followed by a list of all numbers greater than the average.
- Average must be calculated using a method that has an array
at its parameter (if non-full, a second parameter for size will
also be needed).
- Files:
AverageDoubles.class
AverageDoubles01.java
|
9-2 |
347 |
| WE WILL OMIT THIS PROJECT FOR THE
2008-2009 SCHOOL YEAR, BUT STUDENTS WISHING TO GET SOME EXTRA CREDIT
MAY DO THE PROJECT BUT ONLY AFTER COMPETING ALL REQUIRED PROJECTS.
k:\java\Chapter09\Statistics
- Input up to 10 integers. Only 1 through 10 inclusive
are valid values. Others must be rejected.
- find the required information in any order
- but display them in this order:
- the original list
- the ordered list
- the table of frequencies first
- followed by the ordered list
- the mode* and the median
- the stardard
deviation
- You MAY NOT sort any array. You may, however,
create a new array which is ordered as it is created, and as
many other new arrays as needed to complete the project.
* if more than one mode, find and display only the smallest.
|
9-3, 9-4, 9-5
add stardard
deviation |
347 |
| omit |
9-6 |
347 |
k:\java\Chapter09\MagicSquare
- Input 16 integers into a two-dimensional 4x4 array.
- Ignore the requirement to display the results in a text area.
This is a console application. Simply report whether or
not the square is a magic square.
- Files:
MagicSquare.class
MagicSquare01.java
|
9-7 |
348 |
k:\java\Chapter09\PascalsTriangle
- Pay close attention to the math of this project, as it was
used in the 2003 Great Computer Challenge!
- Although it is possible to solve this problem using either
a one or two-dimensional array, YOU MUST USE A TWO-DIMENSIONAL
ARRAY WITH VARIABLE LENGTH ROWS (see page 320 in your text).
- To best determine the relationship between the numbers of
each row, view them arranged in left-justified fashion instead
of a triangle:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
etc.
- Notice each row starts with one and ends with 1. Each
number in between is the sum of the pair of numbers just above
it and to the left.
Sample runs:
---------------------------------------------------------
This project is named "Pascals Triangle..."
by Mr. C. Monroe
How many rows? (1-10): 5
1
1
1
1 2
1
1 3
3 1
1 4 6
4 1
Press Enter to continue . . .
-------------------------------------------
This project is named "Pascals Triangle..."
by Mr. C. Monroe
How many rows? (1-10): 6
1
1 1
1
2 1
1
3 3 1
1 4
6 4 1
1 5 10
10 5 1
Press Enter to continue . . .
|
9-8 |
348 |
|
omit
|
9-9 |
348 |
| Swing GUI Application |
| WE WILL OMIT THIS PROJECT
FOR THE 2008-2009 SCHOOL YEAR, BUT STUDENTS WISHING TO GET SOME
EXTRA CREDIT MAY DO THE PROJECT BUT ONLY AFTER COMPETING ALL REQUIRED
PROJECTS ABOVE.
k:\java\Chapter09\PennyPitch
- Display the two-dimensional board of numbers using buttons.
My I suggest a gridbag layout.
- A "Toss" button, which, when clicked executes the toss, as
directed in the text, and replaces the appropriate number with
the letter P.
- A label to display a running total of the numbers hit by
coin tosses.
- Your Square class should store:
- a boolean indicating whether or not it has been "hit" by
a coin toss
- an integer storing its value--1, 2, or 3--or 0 if the letter
P is to be displayed
- alternatively, instead of an integer, you could store a
pointer to a component (a button)
- Your PennyPitch class should declare and instantiate a 5x5
array of Square objects.
- If your Square class stores a pointer to a button component,
the PennyPitch class should declare and instantiate each button
and pass its pointer to the Square. Otherwise, the PennyPitch
class will need to use a 5x5 array of buttons in parallel
with the array of Square objects.
- At the very least, your program should display the running
total of the numbers hit by coin tosses.
- Additionally add:
- The number of tosses
- The number of misses
- Logic to end the game when the number of misses reaches
10 or all 25 numbers have been hit.
- Optionally, reset all values and restart the game after
each game ends.
- Still not sure what to do? This applet
version demonstrates how the game should work.
|
9-10 |
349 |
Lesson 10
Workspace: \java\Lesson10
- A workspace named "Chapter10" has already placed in your "java"
folder on drive K. This workspace already has a project named "DemoShapes"
in it which is to be used for the last project in this chapter.
- For the other projects, you must create them yourself and add them
to this workspace.
| Project Name |
Project Number |
Page in Text |
k:\java\Chapter10\MartianCounter
- A console project to demonstrate using class data (static
data) to count instances of a class.
- Martians are appearing in orbit around the earth and some
of them have landed!
- Design a project that will
- prompt the user for how many Martians to initially be in
orbit around the earth (at least one, please).
- ask the user to enter 1 to add another orbiting Martian,
-1 to land a Martian, and 0 to end the program.
- a loop should continue this process until 0 is entered.
- After each input, the program should display the number of
Martians still orbiting and the number of Martians that have
landed.
- REQUIRED: Write a class named Martian with the following
- Private class (static) integers to keep track of how many
Martians are orbiting and how many have landed.
- When the default constructor creates a new Martian, it
is placed in orbit (the orbit counter increases by one).
- A public method named Land()
lands one Martian (the orbit counter decreases by one,
the landed counter increases by one)--unless of course there
are no Martians in orbit.
- The public toString() method
displays the number of Martians in orbit and the number of
Martians that have landed.
Sample run:
Project "MartianCounter" by Mr. C. Monroe.
How many Martians to begin? (at least one, please) 2
2 martians are in orbit.
0 martians have landed.
1=Another Martian, -1=Martian lands, 0=quit -1
1 martian is in orbit.
1 martian has landed.
1=Another Martian, -1=Martian lands, 0=quit -1
0 martians are in orbit.
2 martians have landed.
1=Another Martian, -1=Martian lands, 0=quit -1
Can't land a martian if none are in orbit.
0 martians are in orbit.
2 martians have landed.
1=Another Martian, -1=Martian lands, 0=quit 1
1 martian is in orbit.
2 martians have landed.
1=Another Martian, -1=Martian lands, 0=quit 2
1 martian is in orbit.
2 martians have landed.
1=Another Martian, -1=Martian lands, 0=quit 0
1 martian is in orbit.
2 martians have landed.
Press Enter to continue . . .
|
n/a |
n/a |
|
|
|
Turtle Graphics
NOTE: Before you can compile and run any Turtle Graphics
project in this unit, you will need to point JCreator to the Turtle
Graphics library provided with the textbook. If working
at home, this file can be downloaded here.
If working in Lab 101, your teacher has installed the file on
your computer and will show you how to set up JCreator.
See Section 10.2 Turtle Graphics and Appendix
I for documentation on Turtle Graphics.
|
k:\java\Chapter10\DrawSquare
- Implement the project provided in your text on pages 357-358.
- Write a Java program that uses Turtle Graphics to draw a
50 x 50 pixel square centered in a turtle graphics window.
|
n/a |
357.358 |
k:\java\Chapter10\DrawDiagonals
- Write a Java program that uses Turtle Graphics to draw a
75 x 75 pixel square centered in a turtle graphics window.
This time you should also draw the square's diagonals.
|
n/a |
n/a |
k:\java\Chapter10\DemoShapes
- Your teacher has placed a project named "DemoShapes" in your
"Chapter10" folder that contains your "Chapter10" workspace.
- Add the project named "DemoShapes" to your "Chapter10" workspace
and open it.
- Files provided are:
- DemoShapes.java (contains public static void main), AbstractShape.java,
Shape.java, Circle.java, Wheel,java, and Rect.java.
- Study these classes carefully.
- Students writes this code:
- Triangle (follow the guidelines provided in 10-4)
- Square
- Trapezoid
|
10-3, 10-4 |
403-404 |
|
|
|
AP®
Computer Science in Java ~ GridWorld Case Study ~ Part 3
Part 3, GridWorld Classes and Interfaces
- JCreator 3.5 instructions:
- Add a new project named DancingBugRunner
to your GridWorld workspace.
- Then add a new class named DancingBug
to the DancingBugRunner project.
- Then follow the instructions in Do You Know? Set 3 and Set
4
-
Due Wednesday 3/18/09, by the end of the day: Do You Know?
Set 5 and 6
Looking Ahead
In-class lab activity Thursday 3/19/09 will be Jumper, in
groups of 4, with specification and design due by end of class.
|
|
Workspace: k:\java\Lesson11
- Create a workspace named "Lesson11" (no spaces, please)
and save it in the "java" folder on drive K.
Assigned Projects
| Project Name |
Project Number |
Page in Text |
k:\java\Lesson11\SortMarathon
See directions below. |
not in text |
not in text |
k:\java\Lesson11\Election
See directions below. |
not in text |
not in text |
|
SortMarathon
k:\java\Lesson11\SortMarathon
- In this project we will write a GUI program that examines
the relative speeds--in milliseconds--and others behaviors of
various sort routines.
- It reads from a text file named "unsorted.txt"
that contains 2,639 five-letter words--one on each line, all
in upper case. Based on user-input, it reads one or more
of the words and stores them in an array. For each sort
routine, a copy of the original is sorted. The sort routines
sort pointers, not actual data, which allows Java to perform
sorting tasks on arrays much faster than other languages such
as C++.
- The sort routines examined will include but not be limited
to:
- Bubble Sort (with stop flag)
- Selection Sort*
- Insertion Sort*
- Shell Sort
- Quick Sort
- Merge Sort*
* these sorts are on the APCS A exam
- Starting code is provided.
- Complete the selection sort code.
- Add insertion, shell, quick and merge sorts.
- You may also add heap sort, if you can find the algorithm.
- The GUI includes
- an integer field to input the number of words (0 to 2700)
to be sorted. (This will read that many words from the
file and quit. If end of file is reached, the total
words read will not be 2700.)
- a checkbox labeled "Show Words" which, when checked allows
the words read to be displayed in the text area labeled "Words"--unsorted
prior to sorting, sorted after sorting, and unsorted again
in their original order.
- a text area labeled "Report" in which a neat chart is displayed
when the user clicks the button labeled "Start the Marathon"
as follows:
- The title of the program and the actual number of words
read and sorted.
- Columns with appropriate column headings to display:
- The name of the sort.
- The time the sort started (hours, minutes, seconds,
milliseconds).
- The time the sort ended (hours, minutes, seconds, milliseconds).
- How long the sort lasted (duration in hours, minutes,
seconds, and thousandths of seconds).
- The number of movements. This is a count of the
number of data movements (actually pointer movements)
performed by the sort. A swap is three movements.
Most other assignments are one movement each.
- By examining the starting code, you will also find out how
to:
- read one line at a time from a text file.
- create a Date object and use it to store the date and time
accurate to the nearest one thousandth of a second
- compute elapsed time
- display a time (either a Date object or a number of milliseconds)
in the format "hh:mm:ss:ccc" ("ccc" = milliseconds).
- Sample run:
Sort Marathon. Number of words sorted: 2345
Sort Start End Duration Comparisons Movements
Bubble 11:21:50:254 11:21:50:634 00:00:03:080 2747164 4105890
Selection 11:21:50:644 11:21:50:905 00:00:02:061 2748340 7008
Insertion 11:21:50:905 11:21:51:085 00:00:01:080 1370966 1373318
Shell 11:21:51:085 11:21:51:105 00:00:00:020 48361 49569
Merge 11:21:51:105 11:21:51:115 00:00:00:010 23350 50254
Quick 11:21:51:115 11:21:51:125 00:00:00:010 33999 20244
Heap 11:21:51:125 11:21:51:135 00:00:00:010 45384 72708
|
|
Election
k:\java\Lesson11\Election
- Write a Java console application that calculates and displays
simple election results based on simple data entered by the
user.
- Data for each candidate is stored in a simple class that
you design. It should include at least
- private instance variables to store the candidate's last
name and number of votes received
- an assignment constructor
- public access methods so the client can retrieve the candidate's
data.
- Your program must use an ArrayList of
candidate objects, not a simple Java array.
- You may have the user enter the number of candidates or you
may terminate input using a sentinel value--your choice.
- Then, for each candidate, the user enters
- the last name
- the number of votes received
- once entered, into temporary variables, use the temporary
variables to instantiate a candidate object and add the object
to your ArrayList.
- The program will then display a chart
- the first line has headings for the columns
- The columns display
- the candidate name (left-justified)
- the number of votes received (right-justified)
- the percent of total votes (right-justified, rounded
to 2 decimal places)
- Two more lines display
- The total number of votes (also left and right justified)
- Who won.
Sample OUTPUT might be:
Candidate Votes Received
% of Total Votes
Simpson
5000
25.91
Mergatroid 4000
20.72
Magillicuddy 6000
31.09
Haagendaas 2500
12.95
Van Helsing 1800
9.33
Total
19300
The Winner of the Election is Magillicuddy.
|
Workspace: k:\java\Lesson12
- Create a workspace named "Lesson12" (no spaces, please)
and save it in the "java" folder on drive K.
Assigned Projects
| Project Name |
Project Number |
Page in Text |
k:\java\Lesson12\TowersOfHanoi
(Demo) |
n/a |
462 |
| k:\java\Lesson12\TestGCD |
12-1 |
499 |
| k:\java\Lesson12\TestReverse |
12-2 |
499 |
| k:\java\Lesson12\TestCommas |
12-3 |
499 |
|
GUI
|
k:\java\Lesson12\Mondrian
The header for your code should use Mondrian instead of
the ever present GUIWindow.
Include the modification of 12-8 to fill each rectangle with a randomly
generated color. |
Text
12-8 |
493-494,
500 |
k:\java\Lesson12\Ccurve
This program uses the same client code as the Mondrian (page 493)
program, but with a different ColorPanel class (page 496). |
n/a |
493,496 |
AP®
Computer Science in Java ~ GridWorld Case Study ~ Part 4
Part 1, Observing and Experimenting with GridWorld
- When working on the GridWorld Case Study, open JCreator,
open the APlus
GridWorld Intro (PPT), and follow along in Trey Carroll's
Flash Screen-capture Lectures below:
| A+ Slides and Java Code: a.gridworldintro |
|
Videos
|
Activities
|
Worksheets
|
| |
|
|
- Running the Demo & Exploring Actor State and Behavior
- View Videos 1 to 4.
- Do the Activities listed above.
- Complete worksheets Actor One and Actor Two
(listed above).
|
|
AP® Computer
Science - Review / Diagnostic Exam
The purpose of this "Exam" is to help you determine your
strengths and weaknesses vis-à-vis the AP Computer Science curriculum.
The questions cover material in the AP curriculum, but do not mimic
the style or fomat of a real AP Exam. This
is NOT a practice Exam.
|AP Course Main Menu|
|