For Friday Finish reading chapter 2 Complete WebCT quiz.

Slides:



Advertisements
Similar presentations
2/18/2008ITK 1681 Feb. 20, Wed. 8:00 – 9:30 pm STV Closed book, notes, and no computer is allowed. 2.Everyone is allowed to bring a self- prepared.
Advertisements

Chapter 3 Extending the Robot Programming Language.
© 2007 Lawrenceville Press Slide 1 Chapter 3 Classes and Objects.
Chapter 1: Introduction
Lab 1 City, Robot, Thing, Wall. Documentation of Classes and Methods.
Extending the Robot Programming Language In the Robot world 1 mile = 8 blocks Suppose we want a robot to run a marathon (26+ miles)? Does our program have.
Lecture 10 Instructor: Craig Duckett. Assignment 2 Revision TONIGHT DUE TONIGHT Wednesday, August 5 th Assignment 3 NEXT DUE NEXT Monday, August 10 th.
Java for Robots How to program an NXT robot with a Java Brain Bert G. Wachsmuth Seton Hall University.
3.1 Documentation & Java Language Elements Purpose of documentation Assist the programmer with developing the program Assist other programers who.
Lecture 6a Instructor: Craig Duckett. Upcoming Assignments & Mid-Term Assignment 1 Revision Assignment 1 Revision is due NEXT Wednesday, July 29 th, by.
9/12/2015IT 2751 IDE ( Integrated Development Environment ) 1.A customized plain text editor 2.Compiler 3.Loader 4.Debugging tool JDK (Java Development.
Introduction to Programming Writing Java Beginning Java Programs.
Karel J Robot An introduction to BlueJ and Object- Oriented Programming.
1 Classes begin with capital letters (i.e. UrRobot). Methods, objects, and variable names begin with lower case (camelCase) Use indentation to line up.
1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com.
Comments are for people Header comments supply basic information about the artifact.
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
The Java Programming Language
CSC204 – Programming I Lecture 4 August 28, 2002.
Lecture 6 Instructor: Craig Duckett. Assignment 1, 2, and A1 Revision Assignment 1 I have finished correcting and have already returned the Assignment.
Java Syntax and Style JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin, Gary Litvin,
BIT 115: Introduction To Programming LECTURE 3 Instructor: Craig Duckett
A First Simple Program /* This is a simple Java program. Call this file "Example.java".*/ class Example { // Your program begins with a call to main().
1 karel_part2_Inheritance Extending Robots Tired of writing turnRight every time you start a new karel project. How do we avoid re-writing code all the.
1 Karel – Chapter 5 Conditionally Executing Instructions Note: Original slides provided by and modified for Mr. Smith’s AP Computer.
Introduction to Programming Writing Java Beginning Java Programs.
Chapter 3 Introduction To Java. OBJECTIVES Packages & Libraries Statements Comments Bytecode, compiler, interpreter Outputting print() & println() Formatting.
1/16/2008ITK 1681 HardwareSoftware Theory 1800 AD  Architecture 1945 AD  What is Computer Science? Languages 1960 AD 
Indentation & Readability. What does this program do? public class Hello { public static void main ( String[] args ) { //display initial message System.out.println(
Anatomy of a Java Program. AnotherQuote.java 1 /** A basic java program 2 * 3 Nancy Harris, James Madison University 4 V1 6/2010.
Documentation and Style. Documentation and Comments  Programs should be self-documenting.  Use meaningful variable names.  Use indentation and white.
1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com.
Ch. 2 1 Karel – Primitive Instructions Basic tools with which all problems are solved (analogies: carpentry, geometry) –move() –turnLeft() –putBeeper()
1 karel_part3_ifElse Conditional Statements or ELSE if ( ) { } else { }
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computers, Programs,
© 2007 Lawrenceville Press Slide 1 Chapter 3 Classes and Objects 1. How is a class different from an object?
1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com.
Errors, GUIs, and Patterns Dr. Doug Twitchell August 30, 2005.
Chapter 3 Introducing Java. Objectives and Goals 1. Define terminology associated with object- oriented programming. 2. Explain why Java is a widely used.
Compiler Errors Syntax error Lexical Can not resolve/find symbol Can not be applied Execution error Oh wait, a run time error Intent error It ran, but.
Alice and Java Unit 7 1. Day 1  Objective: Gain an introduction to Java and Eclipse  Essential skill: DM-1: Use technology to advance critical thinking.
SUMMARY OF CHAPTER 2: JAVA FUNDAMENTS STARTING OUT WITH JAVA: OBJECTS Parts of a Java Program.
Review – Primitive Data What is primitive data? What are 3 examples of primitive data types? How is a piece of primitive data different from an object?
1 Karel J. Robot Chapter 5 Conditionally Executing Instructions.
Lecture 11 Instructor: Craig Duckett Instance Variables.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana Pronounced Bah-bah Co-fee Way-ou-see-jah-nah Call him “Baba” or “Dr. Weusijana”
1/28/2008ITK 1681 An enhanced robot Robot int street int avenue Direction direction ThingBag backback Robot(City aCity, int aStreet, int anAvenue, Direction.
The Essentials of a Java Program JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,
For Monday Read Becker, chapter 4, sections 1 and 2.
BIT 115: Introduction To Programming L ECTURE 3 Instructor: Craig Duckett
STRUCTURED PROGRAMMING Complete C++ Program. Content 2  Main Function  Preprocessor directives  User comments  Escape characters  cout statement.
Chapter 3 Extending the Robot Programming Language.
Professor: Dr. Baba Kofi Weusijana Pronounced Bah-bah Co-fee Way-ou-see-jah-nah Call him “Baba” or “Dr. Weusijana”
Lecture 13 Instructor: Craig Duckett. Assignment 2 Revision DUE TONIGHT! November 9 th DUE TONIGHT! November 9 th Uploaded to StudentTracker by midnight.
Karel – Primitive Instructions
Chapter 1 Introduction to Computers, Programs, and Java
Robot Class name Attributes Constructor Services, methods
BIT115: Introduction to Programming
Karel – Primitive Instructions
Statements, Comments & Simple Arithmetic
import becker.robots.City;
Chapter 1: Computer Systems
Unit 1 Test 1 Redo Friday at 8am here or Friday 4th BLOCK in Math Lab
class PrintOnetoTen { public static void main(String args[]) {
Anatomy of a Java Program
Controlling Program Flow
IDE (Integrated Development Environment)
Karel – Primitive Instructions
Presentation transcript:

For Friday Finish reading chapter 2 Complete WebCT quiz

Writing Constructors public class ExperimentRobot extends Robot { // A constructor to initialize the ExperimentRobot public ExperimentRobot(City aCity, int aStreet, int anAvenue, Direction aDirection) { super(aCity, aStreet, anAvenue, aDirection); } // Another constructor to initialize the ExperimentRobot to be in a standard position. public ExperimentRobot(City aCity) { super(aCity, 0, 0, Direction.EAST); } // The new services offered by an ExperimentRobot will be inserted here. } Usage: ExperimentRobot lisa = new ExperimentRobot(austin, 3, 2, Direction.SOUTH); ExperimentRobot larry = new ExperimentRobot(austin);

Creating New Services

Flow of Control What happens when we actually call a method?

RobotSE More capable version of Robot Extension vs. Modification

Planting Flowers Again We’re going to redo the planting flowers problem with two modifications: –Create and use a GardenerBot that has a method plantFlowers, which plants all the flowers. –Create an extended version of City called Garden that automatically includes the four walls.

The Importance of Style import becker.robots.*; public class ExperimentRobot extends Robot {public ExperimentRobot(City aCity, int aStreet, int anAvenue, Direction aDirection) { super(aCity, aStreet, anAvenue, aDirection);} public void turnAround() { this.turnLeft(); this.turnLeft(); } public void move3(){this.move(); this.move(); this.move(); } public void turnRight() {this.turnAround(); this.turnLeft(); }}

White Space and Indentation Start each statement on a new line. Include blank lines between blocks of code for different purposes (ideally with a comment to indicate what the following block of code does) Line up curly braces. Indent consistently Note: Eclipse will do most of this for you.

Identifiers The rules The conventions

Comments Single-line Multi-line Document

Meaning and Correctness What if move3 were defined like this: public void move3() { this.turnLeft(); this.pickThing(); this.turnLeft(); }

Modifying Inherited Methods Some people “show off” when they move. They might be loud or swagger or sway their hips or …. It seems like they can’t move in any other way. If they move, they show off. Create a ShowOff robot that turns magenta each time it moves. When it is standing still or turning (that is, not move-ing) it should continue to be red.

ShowOff Robot import becker.robots.*; public class ShowOffMain { public static void main(String[ ] args) { City ny = new City(); ShowOff karel = new ShowOff(ny, 2, 3, Direction.SOUTH); karel.turnLeft(); // red karel.move(); // magenta karel.turnLeft(); // red karel.move(); // magenta