"The art of teaching is the art of assisting discovery." - Mark Van Doren
AP Computer Science 2007-08 / 1st Semester
Most recent update August 15, 2007 2:33 PM
Schedule
The Intersection is a room. "You stand at a crossroads." The sign is here. Instead of examining the sign: say "The sign smiles and shouts: Hello World!"
The Intersection is a room. "You stand at a crossroads." The sign is here. Instead of examining the sign: say "The sign smiles and shouts: Hello World!"
The Long Road is west of the Intersection. "The road is long, my friend." The rabbit is here. The rabbit is edible.
"Coke Machine" by Byron Philhour
The Gym Foyer is a room.
The soda machine is an open container in the Gym Foyer. "A soda machine is against one wall." The description of the soda machine is "Standard issue soda machine: it has a slot, a button for regular Coke, a button for Diet Coke, a coin release button, and a receptacle where things come out at the bottom. [if a can is in the receptacle]A can sits in the receptacle of the machine. [otherwise]It looks like a soda costs 75 cents." The soda machine is not portable.
A can is a kind of thing. A can of Coke is a can. A can of Diet Coke is a can.
The button for regular Coke, the button for Diet Coke, and the coin release button are parts of the soda machine. The receptacle is a transparent open container in the Gym Foyer. The receptacle is scenery.
A quarter is a kind of thing. The player carries 3 quarters.
Understand "slot" as the soda machine.
Understand "press [something]" as pushing.
The soda machine toll is an number that varies. When play begins, change the soda machine toll to zero.
Instead of inserting a quarter into the soda machine:
increase the soda machine toll by one;
continue the action.Instead of pushing the button for regular Coke:
if the soda machine toll is three
begin;
move a can of Coke to the receptacle;
change the soda machine toll to zero;
say "After a nervous pause and some loud clanging, a can of regular Coke makes its way to the receptacle.";
otherwise;
say "Nothing happens. Have you inserted the correct change?";
end if.
Instead of pushing the button for Diet Coke:
if the soda machine toll is three
begin;
move a can of Diet Coke to the receptacle;
change the soda machine toll to zero;
say "After a nervous pause and some loud clanging, a can of Diet Coke makes its way to the receptacle.";
otherwise;
say "Nothing happens. Have you inserted the correct change?";
end if.
Instead of pushing the coin release button:
if the soda machine toll is greater than zero
begin;
say "Clink clink!";
change the soda machine toll to zero;
now all of the things in the soda machine are in the receptacle;
try examining the receptacle.
otherwise;
say "Nothing obvious happens.";
end if.
"Elevator" by Byron Philhour
The Elevator is a room. "The elevator smells of coffee and cigarettes. Faint flickerings from the button panel and floor indicator indicate the elevator is powered, but tenuously.[if still] The elevator is at rest.[otherwise] The elevator is in motion."
The Foyer is a room.
The Second Floor Hallway is a room.
The Third Floor Hallway is a room.
A wall and a button panel and a floor indicator are scenery in the elevator. The button panel is a transparent open container. The button panel is not openable.
The first floor button is in the button panel. The second floor button is in the button panel. The third floor button is in the button panel. The button to open the door is in the button panel. The button to close the door is in the button panel.
The elevator door is a door. The elevator door is outside of the Elevator. The elevator door is scenery.
Instead of opening the elevator door: if the Elevator is moving, say "As a safety feature, the elevator door will not open when the elevator is in motion."; if the Elevator is still, continue the action.
The floor level is a number that varies. [* When play begins, change the floor level to a random number from 1 to 3. *] The floor level is 2. The destination floor is a number that varies.
Instead of examining the floor indicator, say "The number [floor level] is lit."
An Elevator is either moving or still.
Instead of pushing the first floor button:
now the destination floor is 1;
if the floor level is 1 and the Elevator is still and the elevator door is closed, try opening the elevator door;
if the floor level is 2 and the Elevator is still begin;
now the Elevator is moving;
say "With a jerk the elevator begins moving.";
the Elevator arrives in two turns from now;
end if.At the time when the Elevator arrives:
say "The elevator stops moving.";
now the floor level is 1;
now the Elevator is still.The printed name of the first floor button is "[if lit]first floor button (lit)[otherwise]first floor button". The description of the first floor button is "[if lit]The first floor button is lit.[otherwise]The first floor button is unlit."
Instead of exiting when the player is in the Elevator and the elevator door is open:
if the floor level is 1, move the player to the Foyer;
if the floor level is 2, move the player to the Second Floor Hallway;
if the floor level is 3, move the player to the Third Floor Hallway.[* Backpack *]
A backpack is in the Elevator. "A backpack lies here." The backpack is a container and wearable. The backpack has carrying capacity 10. The backpack is openable. Inside the backpack is a Calculus book, a pencil, an eraser, and a calculator.
Every turn when player is wearing the backpack and the backpack is open and the backpack contains something and a random chance of 1 in 3 succeeds: move a random thing in the backpack to the location.
import javax.swing.*;
class HelloWorld {
public static void main(String[] args) {
JFrame window;
window = new JFrame();
window.setTitle("Hello World! ");
window.setSize(150, 100);
window.setVisible(true);
}
}
class LoopTest {
public static void main (String [] args) {
for (int x = 0; x < 10; x = x + 1) {
System.out.println("x is now " + x);
}
}
}
class LoopTest2 {
public static void main (String [] args) {
for (int x = 0; x < 10; x = x + 1) {
for (int y = 0; y < 5; y = y + 1) {
System.out.println("x is now " + x);
System.out.println("y is now " + y);
}
}
}
}
import java.util.Scanner;
public class Convert {
public static void main(String [] args) {
Scanner reader = new Scanner(System.in);
double fahrenheit;
double celsius; // note the two slashes here mean comment!
System.out.print("Enter degrees Fahrenheit: ");
fahrenheit = reader.nextDouble();
celsius = (fahrenheit - 32.0) * 5.0 / 9.0;
System.out.print("The equivalent in Celsius is ");
System.out.println(celsius);
}
}
import javax.swing.*;
import java.awt.*;public class GUIWindow4 {
public static void main(String [] args) {
JFrame theGUI = new JFrame();
theGUI.setTitle("Fourth GUI Program");
theGUI.setSize(300,200);
theGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel1 = new JPanel();
panel1.setBackground(Color.white);
JPanel panel2 = new JPanel();
panel2.setBackground(Color.black);
JPanel panel3 = new JPanel();
panel3.setBackground(Color.gray);
JPanel panel4 = new JPanel();
panel4.setBackground(Color.white);
Container pane = theGUI.getContentPane();
pane.setLayout(new GridLayout(2, 2));
pane.add(panel1);
pane.add(panel2);
pane.add(panel3);
pane.add(panel4);
theGUI.setVisible(true);
}
}
System.out.println("When he came up to me he said \"Hello\" quite abruptly.");
System.out.println("Twinkle twinkly little star\nHow I wonder what you are.");
System.out.println("Store the file in the c:\\Program Files\\Howdy directory!");
Announcement: I'll be hosting another optional Computer Science review evening this Thursday, November 29th, from 7 PM to 9 PM. Meet at the Beta Lab or by the flagpole. TOPIC: GREENFOOT BASICS / HOW TO USE CLASSES AND METHODS
import java.util.Arrays;
Arrays.sort(x);
import java.util.Collections;
Collections.sort(x);
public static void selectionSort(int [] x) {
for (int i=0; i<x.length-1; i++) {
for (int j=i+1; j<x.length; j++) {
if (x[i] > x[j]) {
int temp = x[i];
x[i] = x[j];
x[j] = temp;
}
}
}
}
Announcement: I'll be hosting another optional Computer Science review evening this Thursday, November 29th, from 7 PM to 9 PM. Meet at the Beta Lab or by the flagpole. TOPIC: GREENFOOT BASICS / HOW TO USE CLASSES AND METHODS
REVIEW & WORK SESSION IN BETA LAB WEDNESDAY AFTER SCHOOL
- Unit 2: Computer Programming
- Unit 3: Java Programming Language
- Unit 4: Object-oriented Programming
- Unit 5: Algorithms and Data Structures
- Final Exam Exemptions as of Sunday Dec 9 (more coming this week as Greenfoot projects come in)
- McCarty (Units 2, 3 & 4)
- Kodros (Unit 4)
- Kwiat (Unit 2)
- Carberry (Unit 4)
- Sarmiento (Unit 4)
- Conflict exams: Abinante, Carberry, Duhn, Jose, Kwiat, Protasio -- you'll take the final during the 3rd final period on the same day (Thursday) in Room 107.
Coming up next!