1 Classes begin with capital letters (i.e. UrRobot). Methods, objects, and variable names begin with lower case (camelCase) Use indentation to line up.

Slides:



Advertisements
Similar presentations
1 karel_IF_part1 Conditional Statements Flavor 1: if ( ) { } For now: these are method invokations (see next slide)
Advertisements

1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com.
1 karel_part4_functions.ppt Functions Functions return values or Objects. –Using a function allows the programmer to focus on other task. –Using a function.
Classes  All code in a Java program is part of a class  A class has two purposes  Provide functions to do work for the programmer  Represent data.
Murphy’s Laws. Things are more complex than they seem to be. Things take longer than expected. Things cost more than expected. If something can go wrong,
Chapter 3 Extending the Robot Programming Language.
1 eclipse Tips. 2 What is eclipse? Eclipse is a popular IDE (Integrated Development Environment) that we will use to create, compile, execute, and test.
IT151: Introduction to Programming
You ARE NOT ALLOWED To Copy Files!!!. You ARE NOT ALLOWED To Be Told What to Write in the Program.
How to Create a Java program CS115 Fall George Koutsogiannakis.
Karel The Robot In the beginning… software. Karel the Robot  All robots are controlled by software  Artificially intelligent robots that can “think”
Introduction to Computers and Programming for Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to.
Conditionals How do we solve tasks in which every particular of a task is not specifically known? – A robot needs the ability to survey its immediate environment.
Robot? What’s a Robot? Introducing Karel-the-Robot.
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
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.
Introducing Java.
1 eclipse Tips. 2 What is eclipse? Eclipse is a popular IDE (Integrated Development Environment) that we will use to create, compile, execute, and test.
UNIT 3 TEMPLATE AND EXCEPTION HANDLING. Introduction  Program errors are also referred to as program bugs.  A C program may have one or more of four.
Chapter 5 Conditionally Executing Instructions
1 karel_part5_loops Iteration (Loops) Loops repeat a set of instructions Two types of loops: –Definite loops ( for ) perform instructions explicit (known)
Ch. 2 1 Karel – Primitive Instructions Basic tools with which all problems are solved (analogies: LeftSpinngingRobot, RightSpinningRobot, GuardRobot, etc)
Karel J Robot An introduction to BlueJ and Object- Oriented Programming.
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()
Karel J. Robot A Gentle Introduction to the Art of Object Oriented Programming.
JAVA BASICS: Variables and References SYNTAX, ERRORS, AND DEBUGGING.
Week 1 - Friday.  What did we talk about last time?  Our first Java program.
Programming Errors Lexical errors – occur whenever Karel reads a word that is not in his vocabulary. Example in English: We are asking directions and instead.
Thanks to Dr. Kris Schindler for this (and all Karel the Robot slides)
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
BUILDING JAVA PROGRAMS CHAPTER 1 ERRORS. 22 OBJECTIVES Recognize different errors that Java uses and how to fix them.
Karel J. Robot Tool for learning OOP (Lecture covers Ch. 1 and 2)
1 Karel – Chapter 5 Conditionally Executing Instructions Note: Original slides provided by and modified for Mr. Smith’s AP Computer.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
15-100: Introduction to Programming w/ Java * Ananda Gunawardena -- Lecture – School of Computer Science – Phone : (x81559) – Office: Wean Hall.
Chapter 5.  We’ve been using UrRobot – knows only 5 things  Let’s now use a new type of Robot: Robot!  i.e. – public class MileMover extends Robot.
Extending Karel’s Vocabulary This PPT originated with Dr. Judy Hankins Modifications have been done by Dr. Untch & Dr. Cripps.
1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com.
Programming in Karel Eric Roberts CS 106A January 6, 2016.
Introduction to Computer Science
Ch. 2 1 Karel – Primitive Instructions Basic tools with which all problems are solved (analogies: carpentry, geometry) –move() –turnLeft() –putBeeper()
Error Handling Tonga Institute of Higher Education.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computers, Programs,
11 ITI 1120 Lab # 2 Contributors: G. Arbez, M. Eid, D. Inkpen, A. Williams, D. Amyot.
1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com.
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
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.
SUMMARY OF CHAPTER 2: JAVA FUNDAMENTS STARTING OUT WITH JAVA: OBJECTS Parts of a Java Program.
1 Karel J. Robot Chapter 5 Conditionally Executing Instructions.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
The Essentials of a Java Program JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,
Chapter 3 Extending the Robot Programming Language.
Karel – Primitive Instructions
In the beginning… software
Chapter 1 Introduction to Computers, Programs, and Java
GC101 Introduction to computer and program
Copyright © 2008 by Helene G. Kershner
Loops We have already seen instances where a robot needs to repeat instructions to perform a task turnRight(); moveMile(); Harvesting beepers in a field.
Copyright © 2008 by Helene G. Kershner
Karel – Primitive Instructions
Karel J Robot.
String Output ICS 111: Introduction to Computer Science I
Karel the Robot – Making Decisions
A Gentle Introduction to the Art of Object Oriented Programming
Karel – Primitive Instructions
Presentation transcript:

1 Classes begin with capital letters (i.e. UrRobot). Methods, objects, and variable names begin with lower case (camelCase) Use indentation to line up statements Brackets {} should be on a line by themselves Use comments // to identify what the code is supposed to do (very useful)

2 A Definition of Symbol: A symbol is a written word or sequence of characters used to represent something else. Special symbols: ; {}. (they mean something special in Java) Names are symbols: karel, UrRobot, putBeeper. UrRobot is not a robot itself, but represents a type of robot. Reserved words are symbols: class, void, new (they have a built-in purpose) Note: Symbols must match in case when used in Java programs (i.e. karel is not the same as Karel and putBeeper is not the same as PutBeeper)

3 (Errors are referred to as bugs) lexical error (compiler catches) –word not in its dictionary (i.e. you type MOVE() instead of move() ) syntax error (compiler catches) –incorrect grammar, punctuation, incorrect location of a statement (i.e. leaving out a parenthesis or using a colon instead of semi-colon) execution error (run-time environment catches) –can ’ t perform what you ask (i.e. error shutoff if performing move() when a wall is in the way) intent error (logic - guess who catches this one!) –program terminates successfully – junk output, however (i.e. moving robot to the wrong corner) Which is the hardest type of error to correct? Why?

4 public Class SampleTest implements Directions { public static void main(String args[] { UrRobot karel = New UrRobot(2, 1, East, 0). karel.move(); karel.turnLeft() getBeeper(); karel.Move(); karel.turnOff; karel.move(); } IDENTIFY THE BUGS (Clue: There are at least 9 errors)

5 public class SampleTest implements Directions 1) should be class instead of Class { public static void main(String args[]) 2) needs parentheses { UrRobot karel = new UrRobot(2, 1, East, 0);. 3) should be new instead of New 4) use semi-colon instead of period karel.move(); karel.turnLeft(); 5) needs a semi-colon on end karel.pickBeeper(); 6) needs an object and is named pickBeeper karel.move(); 7) Move is not a method karel.turnOff(); 8) needs () (i.e. turnOff() ); karel.move(); 9) can ’ t perform move after turnOff } } IDENTIFY THE BUGS SOLUTION public Class SampleTest implements Directions { public static void main(String args[] { UrRobot karel = New UrRobot(2, 1, East, 0). karel.move(); karel.turnLeft() getBeeper(); karel.Move(); karel.turnOff; karel.move(); } }

6 Now You Try Writing a Short Program to Draw the Letter H Robot starts at origin (1,1), facing north Robot draws the letter H The bottom of the left bar of the H starts at (2,2) The H is 5 beepers high The middle bar should be 2 beepers between the bars Robot should return to origin, face north, and turn itself off when finished (leaving the world in its original state of being Take a little time to think about the best approach before jumping into the code. It may help to sketch the robot ’ s path on a sheet of paper.

7 import kareltherobot.*; public class DrawH_YOURNAME implements Directions { public static void main(String args[]) { World.setVisible(true); UrRobot karel = new UrRobot(1, 1, North, infinity); // …….insert your code here to draw the letter H } DrawH program Starting Point Name your class like this: (i.e. DrawH_JohnDoe)

8 Beginning SituationEnding Situation

9 Copying Classes between School and Home Since there are times when you will want to continue your work at home, you will need to be able to transfer your code back and forth. This is where your flash drive becomes handy. To reduce confusion, keep the folder structure on your flash drive the same as the folder structure on your school computer Use file manager to locate the Java source file (that has extension.java) within the package folder. Copy only the.java files (not the.class files) to your flash drive folder. You can then copy these files to your package folder on your destination computer. Note: After you launch jGRASP, it is important to refresh the project.