Faculty of Sciences and Social Sciences HOPE Object Oriented Programming Pie Eater Revisited Stewart Blakeway FML 213

Slides:



Advertisements
Similar presentations
I Spy! Shapes in our world.
Advertisements

Faculty of Sciences and Social Sciences HOPE Structured Problem Solving An Introduction Stewart Blakeway
Types of Graphs By: Kelsey Period 6. Type of Graph Graphing can be really hard… Graphing can be really hard… Remember…circles have the same number for.
Nested If Statements While Loops
Picture It Very Basic Game Picture Pepper. Original Game import java.util.Scanner; public class Game { public static void main() { Scanner scan=new Scanner(System.in);
Programming in Jessica By Joaquin Vila Prepared by Shirley White Illinois State University Applied Computer Science Department.
Faculty of Sciences and Social Sciences HOPE Structured Problem Solving Week 5: Steps in Problem Solving Stewart Blakeway FML 213
Faculty of Sciences and Social Sciences HOPE Variables and Trace Tables Stewart Blakeway FML 213
Faculty of Sciences and Social Sciences HOPE Structured Problem Solving Week 8: Java: Selection and Repetition Stewart Blakeway.
Faculty of Sciences and Social Sciences HOPE Structured Problem Solving Week 6: Problem Solving Exercises Stewart Blakeway FML.
Faculty of Sciences and Social Sciences HOPE Structured Problem Solving Object Oriented Concepts 3 Stewart Blakeway FML 213
Faculty of Sciences and Social Sciences HOPE Structured Problem Solving Object Oriented Concepts 2 Stewart Blakeway FML 213
Faculty of Sciences and Social Sciences HOPE PHP Flow Control Website Development Stewart Blakeway FML
Faculty of Sciences and Social Sciences HOPE Structured Problem Solving Week 12: Data Structures 1 Stewart Blakeway FML 213
Faculty of Sciences and Social Sciences HOPE PHP & MySQL Stewart Blakeway FML 213
Faculty of Sciences and Social Sciences HOPE Functions in PHP Stewart Blakeway FML
Faculty of Sciences and Social Sciences HOPE PHP – Working with Input Stewart Blakeway FML 213
Faculty of Sciences and Social Sciences HOPE Structured Problem Solving Data Structures 3 Stewart Blakeway FML
Faculty of Sciences and Social Sciences HOPE Structured Problem Solving Examination Revision Stewart Blakeway FML 213
Faculty of Sciences and Social Sciences HOPE Object Oriented Programming Pie Eater Stewart Blakeway FML
Faculty of Sciences and Social Sciences HOPE Data Structures 2 Stewart Blakeway
Faculty of Sciences and Social Sciences HOPE Java: Loops within loops Stewart Blakeway FML 213
Karel The Robot Nested If Statements While Loops Copyright © 2008 by Helene G. Kershner.
Faculty of Sciences and Social Sciences HOPE Structured Problem Solving An Introduction Stewart Blakeway
CIS 101: Computer Programming and Problem Solving Lecture10 Usman Roshan Department of Computer Science NJIT.
Shapes Preschool. Circles and Ovals Let’s trace the shapes and see which object they match!
Faculty of Sciences and Social Sciences HOPE JavaScript Validation Regular Expression Stewart Blakeway FML
Introduction to Programming with Java. Overview What are the tools we are using – What is Java? This is the language that you use to write your program.
Welcome to CS1102 sem1 08/09 Notes: All of my PowerPoint slides will be uploaded to my website after my last tutorial class every week.
Module 10: Simple Inheritance #1 2000/01Scientific Computing in OOCourse code 3C59 Module 10: Simple Inheritance In this module we will cover Inheritance.
Faculty of Sciences and Social Sciences HOPE JavaScript Advanced Stewart Blakeway FML
OBJECTS AND CLASSES CITS1001. Concepts for this lecture class; object; instance method; parameter; signature data type multiple instances; state method.
Vectors and Projectile Motion Chapter 3. Adding Vectors When adding vectors that fall on the same line, using pluses and minuses is sufficient. When dealing.
Dr.C Needs time for reflection. Away From The Rut.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA ‏ Visibility Control.
Greenfoot Game Programming Club.
 The scientific method comes in many different forms but always has these basic steps: 1. Ask a question 2. Develop a hypothesis (An if/then statement.
Lesson 1: Writing a program. Java Java is a programming language Computer cannot understand it, though it can be translated ( compiled ) so a computer.
Vectors and Projectile Motion Chapter 3. Adding Vectors When adding vectors that fall on the same line, using pluses and minuses is sufficient. When dealing.
Shapes, Shapes Everywhere Teddy and his friends love shapes. Teddy wants you to help him find the shapes in each picture. Would you like to help? Graphics.
Faculty of Sciences and Social Sciences HOPE Structured Problem Solving Week 3: Algorithms Stewart Blakeway FML 213
[1.1] Line Symmetry. Use two pattern blocks to make:  Triangle  Rectangle  Square  Parallelogram  Rhombus  Trapezoid  Hexagon  Can you find more.
3-7 6 th grade math Make a Graph. Objective To make graphs to illustrate data and solve problems Why? To know how to appropriately display mathematical.
Repeating patterns Can you work out the next shape in the pattern?
Negative Space and Forming Shapes. Negative Space In art, generally, negative space is the space around and between the subjects of an image.art.
There are many kinds of shapes. Look around you, There are shapes in everything you see.
MATHEMATICS Line Symmetry. Lesson Objectives The aim of this powerpoint is to help you… Review what we mean by ‘symmetry’ Draw reflections and find mirror.
By Mackenzie.  Defining Attributes:  6 flat faces  8 vertices  12 edges  Stacks and slides  Shape of faces is a square.
How many …?. What shape can you see? I can see some _____. Q1 Q1 stars.
Dividing Fractions Part 1: Dividing a Whole Number by a Unit Fractions.
Perimeter The distance around the outside of a shape.
Week91 APCS-A: Java Problem Solving November 2, 2005.
Section 4.4 Counting Blobs
Fractions Learning objective: To find ½ , ¼ and ¾ of a shape.
Loops We have already seen instances where a robot needs to repeat instructions to perform a task turnRight(); moveMile(); Harvesting beepers in a field.
What properties can a 3D shape have?
Elements of Design.
Fraction Fun.
Geometry in my life By: Darrin.
Shapes.
Aim: How do we use quadratic formula to solve equation?
Algorithms.
Objective;To use four figure grid references
Nested If Statements While Loops
Greenfoot November 8, 2009.
By 2-D shapes.
Implementation Review the mathematical concept.
Can you work out the next shape in the pattern?
2D Shapes Rectangle Circle Triangle Rectangle. What shape is the door? Rectangle.
Can you work out the next shape in the pattern?
Presentation transcript:

Faculty of Sciences and Social Sciences HOPE Object Oriented Programming Pie Eater Revisited Stewart Blakeway FML

Faculty of Sciences and Social Sciences HOPE Aims of the Presentation To create our friend from last year – Pie Eater To create Pie Eaters world To give Pie Eater some mobility – walk – turn left – turn right

Faculty of Sciences and Social Sciences HOPE What we know so far public class Picture { private Circle pieEater; } public class Picture { private Circle pieEater; } public void walk() { } public void walk() { }

Faculty of Sciences and Social Sciences HOPE Pie Eater Pie Eater is very complex – He can walk – He can turn left – He can turn right – He can eat pies His world is complex – There are boundaries – It can contain pies What do we do with any complex problem that requires solving?

Faculty of Sciences and Social Sciences HOPE Let’s Create Pie Eater How can we achieve this? – We will do this in a method (message) – Remember we have use of the other classes Triangle Square Circle Rectangle

Faculty of Sciences and Social Sciences HOPE Pie Eater public class Picture { private Circle pieEater; } public class Picture { private Circle pieEater; } public void createPieEater() { pieEater = new Circle(); pieEater.changeColor("blue"); pieEater.moveHorizontal(87); pieEater.moveVertical(-29); pieEater.changeSize(30); pieEater.makeVisible(); } public void createPieEater() { pieEater = new Circle(); pieEater.changeColor("blue"); pieEater.moveHorizontal(87); pieEater.moveVertical(-29); pieEater.changeSize(30); pieEater.makeVisible(); } We do something similar for the tail

Faculty of Sciences and Social Sciences HOPE Let’s Create Pie Eater’s World How can we achieve this? – We will do this in a method (message) – Remember we have use of the other classes Triangle Square Circle Rectangle – Think about the grid – it is a repetition of lines Horizontal lines Vertical lines

Faculty of Sciences and Social Sciences HOPE Pie Eater’s World public class Picture { private Circle pieEater; private Rectangle xLine; } public class Picture { private Circle pieEater; private Rectangle xLine; } public void drawGrid() { for (int y=10; y<400; y=y+40) { xLine = new Rectangle(); xLine.changeColor("black"); xLine.moveVertical(y); xLine.moveHorizontal(50); xLine.changeSize(3,320); xLine.makeVisible(); } public void drawGrid() { for (int y=10; y<400; y=y+40) { xLine = new Rectangle(); xLine.changeColor("black"); xLine.moveVertical(y); xLine.moveHorizontal(50); xLine.changeSize(3,320); xLine.makeVisible(); } We do something similar for the vertical line

Faculty of Sciences and Social Sciences HOPE Let’s Make Pie Eater Walk How can we achieve this? – We will do this in a method (message) – Remember we have use of the other classes Triangle Square Circle Rectangle – There are a couple of ways to do this We can make him jump for one square to the next Or, we can create more complex code that allows for smooth transition

Faculty of Sciences and Social Sciences HOPE Pie Eater walking public class Picture { private Circle pieEater; private Rectangle xLine; private Rectangle yLine; private Rectangle tail; } public class Picture { private Circle pieEater; private Rectangle xLine; private Rectangle yLine; private Rectangle tail; } public void walk() { } public void walk() { } Class exercise Complete the code for the method. Assume we have objects called: pieEater and tail. The squares in the grid are 40x40px Class exercise Complete the code for the method. Assume we have objects called: pieEater and tail. The squares in the grid are 40x40px

Faculty of Sciences and Social Sciences HOPE Pie Eater walking public class Picture { private Circle pieEater; private Rectangle xLine; private Rectangle yLine; private Rectangle tail; } public class Picture { private Circle pieEater; private Rectangle xLine; private Rectangle yLine; private Rectangle tail; } public void walk() { pieEater.moveHorizontal(40); tail.moveHorizontal(40); } public void walk() { pieEater.moveHorizontal(40); tail.moveHorizontal(40); } My solution

Faculty of Sciences and Social Sciences HOPE Let’s Make Pie Turn Left How can we achieve this? – Your suggestions???

Faculty of Sciences and Social Sciences HOPE Pie Eater Turn Left public class Picture { private Circle pieEater; private Rectangle xLine; private Rectangle yLine; private Rectangle tail; } public class Picture { private Circle pieEater; private Rectangle xLine; private Rectangle yLine; private Rectangle tail; } public void turnLeft() { tail.moveHorizontal(18); tail.changeSize(10,5); tail.moveVertical(16); } public void turnLeft() { tail.moveHorizontal(18); tail.changeSize(10,5); tail.moveVertical(16); } My solution

Faculty of Sciences and Social Sciences HOPE Considerations? Walking pieEater.moveHorizontal(40); tail.moveHorizontal(40); What if we are facing Left, Up or Down ?

Faculty of Sciences and Social Sciences HOPE Considerations? Turning tail.moveHorizontal(18); tail.changeSize(10,5); tail.moveVertical(16); What if we are facing Left, Up or Down ?

Faculty of Sciences and Social Sciences HOPE Solution We need to know which direction Pie Eater is facing – If we walk, we need to know which direction to walk – If we turn right we need to know which direction we are facing When do we record the direction? When do we check the direction?

Faculty of Sciences and Social Sciences HOPE Recording the Direction Pie Eater starts by default facing East – Each time Pie Eater turns right we must update his direction (after checking his direction) – Pie Eater needs and attribute called direction

Faculty of Sciences and Social Sciences HOPE Recording the Direction Pie Eater starts by default facing East – Each time Pie Eater turns right we must update his direction (after checking his direction) – Pie Eater needs and attribute called direction public class Picture { private Circle pieEater; private Rectangle xLine; private Rectangle yLine; private Rectangle tail; String direction = “E”; } public class Picture { private Circle pieEater; private Rectangle xLine; private Rectangle yLine; private Rectangle tail; String direction = “E”; } public void setDirection(String turn) { if (direction == "E") { if (turn == "L") { direction = "N"; } else { direction = "S"; } } public void setDirection(String turn) { if (direction == "E") { if (turn == "L") { direction = "N"; } else { direction = "S"; } } My solution

Faculty of Sciences and Social Sciences HOPE Recording the Direction When do we update the direction? I.e. when do we call the setDirection(String turn) method (message)?

Faculty of Sciences and Social Sciences HOPE Pie Eater Turn Left public class Picture { private Circle pieEater; private Rectangle xLine; private Rectangle yLine; private Rectangle tail; } public class Picture { private Circle pieEater; private Rectangle xLine; private Rectangle yLine; private Rectangle tail; } public void turnLeft() { tail.moveHorizontal(18); tail.changeSize(10,5); tail.moveVertical(16); setDirection (“L”); } public void turnLeft() { tail.moveHorizontal(18); tail.changeSize(10,5); tail.moveVertical(16); setDirection (“L”); } My solution

Faculty of Sciences and Social Sciences HOPE So far Created Pie Eater (with a tail) Walked Turned Left Turned Right Checked Direction Updated Direction

Faculty of Sciences and Social Sciences HOPE Next Not all directions have been accounted for yet – When walking – Turning We have not discussed boundaries – How do we stop Pie Eater leaving his world? Where are the pies? – How do we place them on the grid? – Where do we place them? – How many do we place? Pie Eater encounters a pie – How does pie eater know there is a pie? – How does pie eater eat the pie? Should Pie Eater have friends in his world?

Faculty of Sciences and Social Sciences HOPE Conclusion Pie Eater is a complicated application Many real world factors have to be accounted for Object Orient Programming is an excellent approach for this type of problem You are to create your own PieEater Application – Your project will be compiled – You will demonstrate your project next week (5 min per person) – Your project will be placed on the website so that you can impress your friends and your tutors (better work hard)

Faculty of Sciences and Social Sciences HOPE Any Questions?