Aquarium Lab Series Developed by Alyce BradyAlyce Brady of Kalamazoo CollegeKalamazoo College.

Slides:



Advertisements
Similar presentations
Introduction to Macromedia Director 8.5 – Lingo
Advertisements

Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
CATHERINE AND ANNIE Python: Part 3. Intro to Loops Do you remember in Alice when you could use a loop to make a character perform an action multiple times?
Pages and boxes Building quick user interfaces. learning objectives o Build a quick UI with pages and boxes o understand how pages and boxes work o click.
Animation Mrs. C. Furman. Animation  We can animate our crab by switching the image between two pictures.  crab.png and crab2.png.
Georgia Institute of Technology DrJava Appendix A Barb Ericson Georgia Institute of Technology May 2006.
Wombats Creating Games with Greenfoot The Walker School – Games and Simulations
© The McGraw-Hill Companies, 2006 Chapter 18 Advanced graphics programming.
Alice Variables Pepper. Set to Java look Edit / preferences restart.
SUNY Morrisville-Norwich Campus-Week 12 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith.
Creating Functions Deborah Nelson Duke University Professor Susan Rodger July 22, 2008.
Games and Simulations O-O Programming in Java The Walker School
Chapter 5 - Making Music: An On-Screen Piano
What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.
Scratch the Cat. Object Oriented Programing Writing computer programs Based on Objects Instead of Actions Based on Data Instead of Logic.
04-Intro-Object-Oriented-In-Java1 Barb Ericson Georgia Institute of Technology Sept 2009 Introduction to Object-Oriented Programming in Java.
AP ® Marine Biology Simulation Case Study Alyce Brady Kalamazoo College.
AP ® Marine Biology Simulation Case Study Alyce Brady Kalamazoo College.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
XP New Perspectives on Microsoft Office Access 2003 Tutorial 11 1 Microsoft Office Access 2003 Tutorial 11 – Using and Writing Visual Basic for Applications.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
Karel J Robot An introduction to BlueJ and Object- Oriented Programming.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Learn about the types of Graphics that are available Develop a basic Graphics applet Develop a basic Graphics application Review the Java API and use.
ACM/JETT Workshop - August 4-5, Guidelines For Using BlueJ.
Introduction to Arrays. definitions and things to consider… This presentation is designed to give a simple demonstration of array and object visualizations.
Nonvisual Arrays and Recursion by Chris Brown under Prof. Susan Rodger Duke University June 2012.
Continuous February 16, Test Review What expression represents the zip car eligibility rules of at least 18 years old and no incidents?
CPSC1301 Computer Science 1 Overview of Dr. Java.
Graphics Concepts CS 2302, Fall /3/20142 Drawing Paths.
AP ® Marine Biology Simulation Case Study Alyce Brady Kalamazoo College.
By Melissa Dalis Professor Susan Rodger Duke University June 2011 Multiplication Table.
Marine Biology Simulation Part II: Assignment, Milestone 1 Dung “Zung” Nguyen Mathias Ricken Stephen Wong TeachJava 2004! June 25, 2004.
1 ball, 2 ball, red ball, blue ball By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Session 16 Pinball Game Construction Kit:. Pinball Version 1 Replaced the fire button with a mouse event. Multiple balls can be in the air at once. –Uses.
CSD 340 (Blum)1 Starting JavaScript Homage to the Homage to the Square.
Algorithms Writing instructions in the order they should execute.
Georgia Institute of Technology Simulations Barb Ericson Jan 2005.
02/14/2005 Introduction to Programming with Java, for Beginners Midterm 1 Review.
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
Lec 21 More Fun with Arrays: For Loops. Agenda Some backfill for Lab 20: – Using an array in an applet or class – array instance variables – using Math.random()
CSD 340 (Blum)1 Starting JavaScript Homage to the Homage to the Square.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
Ready, SET, go! By Melissa Dalis Professor Susan Rodger Duke University July 2011.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Getting started with the turtle Find the latest version of this document at
Continuous. Flow of Control Programs can broadly be classified as being –Procedural Programs are executed once in the order specified by the code varied.
CompSci 4 Chap 6 Sec 2 Sep 30, 2010 Prof. Susan Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were not a Flutterbudget.
1 Project 7: Looping. Project 7 For this project you will produce two Java programs. The requirements for each program will be described separately on.
IST 210: PHP LOGIC IST 210: Organization of Data IST210 1.
Microsoft® Small Basic Conditions and Loops Estimated time to complete this lesson: 2 hours.
CS320n –Visual Programming Execution Control with If / Else and Boolean Functions (Slides 6-2-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for.
Learning Javascript From Mr Saem
Click to edit Master text styles Stacks Data Structure.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Georgia Institute of Technology Dr Usman Saeed Assistant Professor Faculty of Computing and Information Technology North Jeddah Branch King Abdulaziz University.
Georgia Institute of Technology More on Creating Classes Barb Ericson Georgia Institute of Technology June 2006.
Appendix A Barb Ericson Georgia Institute of Technology May 2006
Appendix A Barb Ericson Georgia Institute of Technology May 2006
Creating and Modifying Text part 2
Manipulating Pictures, Arrays, and Loops part 2
Conditions and Ifs BIS1523 – Lecture 8.
CSE 8A Lecture 6 Reading for next class:
Alice Variables Pepper.
T. Jumana Abu Shmais – AOU - Riyadh
More on Creating Classes
Intro to Programming (in JavaScript)
Workshop for Programming And Systems Management Teachers
Presentation transcript:

Aquarium Lab Series Developed by Alyce BradyAlyce Brady of Kalamazoo CollegeKalamazoo College

Why Use This? Review of concepts –Declaring object variables, creating objects using constructors, invoking methods –Conditional Execution (ifs) –Iteration (for loops) –One-dimensional Arrays –Encapulating behavior (classes) Intro to Marine Biology Case Study

Getting Started Instructions are at: – ariumLabSeries/ ariumLabSeries/ Download the zip file and unzip it –AquariumLabSeries.zipAquariumLabSeries.zip Add full path to jpt.jar to the classpath –This holds the user interface classes Compile all source –Don’t forget the files in the BlackBoxClasses directory

First View of the Aquarium nLabs/AquariumLabSeries/ObjConstLabs. shtml#starthttp://max.cs.kzoo.edu/patterns/JavaPatter nLabs/AquariumLabSeries/ObjConstLabs. shtml#start Run the main in AquaSimApplication –Click on the Start button –You will see the initial empty aquarium –Click the top right X to close the window

First View of the Aquarium

Add 3 Fish nLabs/AquariumLabSeries/ObjConstLabs. shtml#constructhttp://max.cs.kzoo.edu/patterns/JavaPatter nLabs/AquariumLabSeries/ObjConstLabs. shtml#construct Edit the main in AquaSimApplication.java –Create 3 AquaFish objects After the start button is pushed Before the user interface is asked to show the aquarium –Still no fish!

Add 3 Fish

Show the 3 Fish nLabs/AquariumLabSeries/ObjConstLabs. shtml#invokehttp://max.cs.kzoo.edu/patterns/JavaPatter nLabs/AquariumLabSeries/ObjConstLabs. shtml#invoke Edit the main in AquaSimApplication.java –Check the documentation on AquaSimGUI for how to draw fish (cause them to show up)AquaSimGUI –Add calls to this method for each of the 3 fish in the main After you create the fish and draw the aquarium Before you repaint to show the result

Show The 3 Fish

Make the Fish Move s/AquariumLabSeries/ObjConstLabs.shtml#invo kehttp://max.cs.kzoo.edu/patterns/JavaPatternLab s/AquariumLabSeries/ObjConstLabs.shtml#invo ke Check the AquaFish documentation to find the method to move the fishAquaFish –Add calls to this method for each of the 3 fish in the main after you have displayed them After the last code you added to the main to draw the fish –Add the code to draw the aquarium and fish again and repaint to show the changes

Possible Problems If you forget to redraw the aquarium – you will see both locations of the fish If you don’t show the fish again –You won’t see them move If you don’t repaint after showing the fish again –You won’t see them move They display and move so fast –You won’t see them move

Pause Between Movements nLabs/AquariumLabSeries/ObjConstLabs. shtml#invokehttp://max.cs.kzoo.edu/patterns/JavaPatter nLabs/AquariumLabSeries/ObjConstLabs. shtml#invoke Check the documentation for the AquaSimGUI class –To see how to pause Add a call to this method –Before you move the fish

Reverse at Wall s/AquariumLabSeries/ConditionalLabs.shtml#ifhttp://max.cs.kzoo.edu/patterns/JavaPatternLab s/AquariumLabSeries/ConditionalLabs.shtml#if Fish get stuck when they hit the wall –Find a method in AquaFish that returns true when the fish is at the wall –Find the method that reverses the fish Add code in the main to test if the fish is at the wall and if so reverse it –After you ask the fish to move

Reverse at Wall

Red or Blue Fish umLabSeries/ConditionalLabs.shtml#elsehttp://max.cs.kzoo.edu/patterns/JavaPatternLabs/Aquari umLabSeries/ConditionalLabs.shtml#else Check the documentation for RandNumGenerator for how to get an object of the class Random –Put this before you create the fish in the main Declare a variable to hold the fish color –Color fishColor; Find how to get 0 or 1 from Random –If 0 set the fish color to Color.RED –Else set the fish color to Color.BLUE Specify the color when you create the fish

Red or Blue Fish

Rainbow of Colors s/AquariumLabSeries/ConditionalLabs.shtml#els eifhttp://max.cs.kzoo.edu/patterns/JavaPatternLab s/AquariumLabSeries/ConditionalLabs.shtml#els eif Change random.nextInt(int maxVal) to 6 to give you a number from 0 to 5 Use if, and else if to assign the color –0 = Color.RED –1 = Color.ORANGE –2 = Color.YELLOW –3 = Color.GREEN –4 = Color.BLUE –5 = Color.MAGENTA

A Better Way Fish color shouldn’t be assigned in the main –They should be assigned in the constructor that doesn’t take a color –But, this means changing the first line which currently calls the other constructor –Instead pull out the code in the other constructor and put it in an initialize

Rainbow of Colors

Loop 10 Times s/AquariumLabSeries/RepetitionLabs.shtml#forhttp://max.cs.kzoo.edu/patterns/JavaPatternLab s/AquariumLabSeries/RepetitionLabs.shtml#for Instead of moving forward just once move forward 10 times –Pause to see the previous position –Move the fish –Draw the aquarium and fish –Be sure to repaint the user interface to see the changes Either start at 0 and loop while < 10 or start at 1 and loop while <= 10

User Specified Number of Steps nLabs/AquariumLabSeries/RepetitionLabs.shtml#inputhttp://max.cs.kzoo.edu/patterns/JavaPatter nLabs/AquariumLabSeries/RepetitionLabs.shtml#input You can use the userInterface to ask the user for how many steps to use –Change the constructor parameters –Find the method that return the number of steps –Change your loop to use this number

User Specified Number of Steps

Add ¼ Chance of Reversing nLabs/AquariumLabSeries/RepetitionLabs.shtml#orhttp://max.cs.kzoo.edu/patterns/JavaPatter nLabs/AquariumLabSeries/RepetitionLabs.shtml#or When a fish moves –Still reverse if at the wall –But also reverse if a random value from 0 to 3 is 0 (1/4 chance of reversing) –Do this in one if statement boolean expression (using ‘or’)

Add ¼ Chance of Reversing

Add an Array of Fish nLabs/AquariumLabSeries/MoreFish.shtml #LIDShttp://max.cs.kzoo.edu/patterns/JavaPatter nLabs/AquariumLabSeries/MoreFish.shtml #LIDS Change the constructor call for AquaSimGUI to ask the user how many fish to use Ask the user interface how many to use Create an array of AquaFish of that size

Add an Array of Fish

Create First and Last Fish nLabs/AquariumLabSeries/MoreFish.shtml #AccessFishhttp://max.cs.kzoo.edu/patterns/JavaPatter nLabs/AquariumLabSeries/MoreFish.shtml #AccessFish Create a fish at the first position in the array and at the last and show both as well as the aquarium

Create First and Last Fish

Looping Through an Array nLabs/AquariumLabSeries/MoreFish.shtml #ProcessAllhttp://max.cs.kzoo.edu/patterns/JavaPatter nLabs/AquariumLabSeries/MoreFish.shtml #ProcessAll Use a for loop to create all the fish in the array Use another for loop to show them all

Looping Through an Array

Moving the Fish Again nLabs/AquariumLabSeries/MoreFish.shtml #School%20in%20Motionhttp://max.cs.kzoo.edu/patterns/JavaPatter nLabs/AquariumLabSeries/MoreFish.shtml #School%20in%20Motion Add another loop to move each of the fish –You will need a nested loop Be sure to use a different index variable –Don’t forget to show the fish again

Moving the Fish Again

Up and Down Fish umLabSeries/ImplementingClasses.shtmlhttp://max.cs.kzoo.edu/patterns/JavaPatternLabs/Aquari umLabSeries/ImplementingClasses.shtml Add ascend and descend methods to AquaFish (by height) In the main before the fish moves do: –A fish at the surface has a 2/3 chance of descending and a 1/3 chance of staying at the surface. –A fish at the bottom has a 1/3 chance of ascending and a 2/3 chance of staying at the bottom. –A fish that is neither at the surface nor at the bottom has a 1/3 chance of ascending, a 1/3 chance of descending, and a 1/3 chance of staying at the same depth.

Up and Down Fish

AquaFish Move Method s/AquariumLabSeries/ImplementingClasses.sht mlhttp://max.cs.kzoo.edu/patterns/JavaPatternLab s/AquariumLabSeries/ImplementingClasses.sht ml The main should only create objects and start them doing something – it shouldn’t have behavior in it! –Create a new move method in AquaFish and move all code related to moving the fish there –Change the main to call the new move method –Test to make sure you get the same behavior

AquaFish Move Method

Adding a Simulation Object s/AquariumLabSeries/ImplementingClasses.sht mlhttp://max.cs.kzoo.edu/patterns/JavaPatternLab s/AquariumLabSeries/ImplementingClasses.sht ml Finish the Simulation class –Finish the constructor –Finish the run method –Finish the step method In the main method –Create a simulation object Tell it to run the user specified number of steps Test to see if you get the same results