import becker.robots.City;

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
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.
Loops – While Loop Repetition Statements While Reading for this Lecture, L&L, 5.5.
Introduction to Computers and Programming Lecture 5 New York University.
Introduction to Computers and Programming for Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to.
Introduction to Computers and Programming Lecture 5 Boolean type; if statement Professor: Evan Korth New York University.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 4 Control Structures I: Selection.
UNIT II Decision Making And Branching Decision Making And Looping
Lab 1 City, Robot, Thing, Wall. Documentation of Classes and Methods.
Lecture 10 Instructor: Craig Duckett. Assignment 2 Revision TONIGHT DUE TONIGHT Wednesday, August 5 th Assignment 3 NEXT DUE NEXT Monday, August 10 th.
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.
Instructor: Craig Duckett Assignment 1 Due Lecture 5 by MIDNIGHT – NEXT – NEXT Tuesday, October 13 th I will double dog try to.
Chapter 4: Control Structures I J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition Second.
Chapter 4: Control Structures I J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design,
Chapter 5 Loops.
Lecture 6 Instructor: Craig Duckett. Assignment 1, 2, and A1 Revision Assignment 1 I have finished correcting and have already returned the Assignment.
BIT 115: Introduction To Programming LECTURE 3 Instructor: Craig Duckett
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
 Learn about control structures  Examine relational and logical operators  Explore how to form and evaluate logical (Boolean) expressions  Learn how.
Repetition Statements while and do while loops
Chapter 4 Control Structures: Part I 1 3 “ There is No goto in Java ” Structured programming: the building blocks There are 3 different kinds.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
1/16/2008ITK 1681 HardwareSoftware Theory 1800 AD  Architecture 1945 AD  What is Computer Science? Languages 1960 AD 
Java Programming: From Problem Analysis to Program Design, 3e Chapter 4 Control Structures I: Selection.
Review TEST 2 Chapters 4,5,7. QUESTION For which type of operands does the == operator always work correctly: (a) int, (b) double, or (c) String?
ITK 168 Decisions Dr. Doug Twitchell September 20, 2005.
1/30/2016IT 2751 Operators Arithmetic operators: + - / * % Relational operators: == > = != Logical operators: || && !
Instructor: Craig Duckett Assignment 1 Due Lecture 5 by MIDNIGHT – NEXT – NEXT Wednesday, January 20 th one week from today I will.
For Friday Finish reading chapter 2 Complete WebCT quiz.
Programming With Java ICS201 University Of Ha’il1 Chapter 11 Recursion.
2/19/2016IT 279, Chung-Chih Li1 Branching Condition Statement list 1 T F Statement list 2 Condition Statement list T F.
Java I--Copyright © Tom Hunter. Chapter 4 Control Structures: Part I.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
Lesson 7 Iteration Structures. Iteration is the third control structure we will explore. Iteration simply means to do something repeatedly. All iteration.
Karel J Robot Chapter 5.
1 Chapter 5 Karel J Robot 2 Chapter 5 Chapter 5 Conditional Statements Flavor 1: if ( ) { } For now: these are method invocations (see next slide)
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.
For Monday Read Becker, chapter 4, sections 1 and 2.
Instructor: Craig Duckett Assignment 1 Due Lecture 5 by MIDNIGHT – NEXT – NEXT Monday, October 10 th I will double dog try to have.
BIT 115: Introduction To Programming L ECTURE 3 Instructor: Craig Duckett
CS0007: Introduction to Computer Programming
Chapter 4 Repetition Statements (loops)
using System; namespace Demo01 { class Program
Robot Class name Attributes Constructor Services, methods
BIT115: Introduction to Programming
Chapter 4: Control Structures I
Introduction to programming in java
Building Java Programs
Decision statements. - They can use logic to arrive at desired results
Conditional Loops.
Chapter 4: Control Structures I
Java I.
null, true, and false are also reserved.
Unit 3 - The while Loop - Extending the Vic class - Examples
Building Java Programs
ITK 168 Section 13 Dr. Doug Twitchell.
class PrintOnetoTen { public static void main(String args[]) {
Branching Statement Condition Statement Condition list 1 list
Names of variables, functions, classes
IDE (Integrated Development Environment)
while loop Condition Statement list
Loops CGS3416 Spring 2019 Lecture 7.
Loops and Iteration CS 21a: Introduction to Computing I
Flow of Control Flow of control is the order in which a program performs actions. Up to this point, the order has been sequential. A branching statement.
Presentation transcript:

1 2 3 4 5 6 7 1 2 3 import becker.robots.City; import becker.robots.Direction; import becker.robots.RobotSE; import becker.robots.Thing; import becker.robots.Wall; public class NoBrainerRobot { public static void main(String[] args) { City ny = new City(); Thing parcel = new Thing(ny, 1, 6); Wall blockade1 = new Wall(ny,1,4,Direction.WEST); Wall blockade2 = new Wall(ny,1,4,Direction.EAST); Wall blockade3 = new Wall(ny,1,6,Direction.NORTH); Wall blockade4 = new Wall(ny,1,6,Direction.SOUTH); Wall blockade5 = new Wall(ny,1,6,Direction.WEST); RobotSE mark = new RobotSE(ny, 1, 0, Direction.EAST); 1 2 3 4 5 6 7 1 2 3 12/1/2018 ITK 168

1 2 3 4 5 6 7 import .... public class NoBrainerRobot { public static void main(String[] args) { .... mark.move(); 1 2 3 4 5 6 7 12/1/2018 ITK 168

Rrobot V2 Robot RobotV2 RobotSE void walkAroundToEast(); int street int avenue Direction direction ThingBag backpack void move() void turnLeft() void pickThing() void putThing() RobotV2 void walkAroundToEast(); void walkAroundToWest(); RobotSE void turnAround(); void turnRight(); 12/1/2018 ITK 168

import becker.robots.*; public class RobotV2 extends RobotSE { public RobotV2(City theCity, int aStreet, int anAvenue, Direction aDirection) { super(theCity, aStreet, anAvenue, aDirection); } public void walkAroundToEast() { this.turnRight(); this.move(); this.turnLeft(); this.move(); this.turnRight(); public void walkAroundToWest() { this.turnLeft(); 12/1/2018 ITK 168

1 2 3 4 5 6 7 import .... public class NoBrainerRobot { public static void main(String[] args) { .... mark.move(); mark.walkAroundToEast(); mark.pickThing(); mark.turnAround(); mark.walkAroundToWest(); mark.putThing(); } 1 2 3 4 5 6 7 12/1/2018 ITK 168

Rrobot V3 RobotV2 void walkAroundToEast(); void walkAroundToWest(); RobotV3 void moveEast(); void moveWest(); If there is a blockade, then walk around; otherwise move along. 12/1/2018 ITK 168

Branching Statement Condition Statement Condition list 1 list F F Statement list 2 12/1/2018 ITK 168

The Syntax of if and if-else statements A Boolean expression (logical expression). In Java, there are two possible values: true and false. if ( condition ) { statement list; } Reserved words A reserved word can’t be used as an identifier if ( condition ) { statement list1; } else statement list2; Indentation indicates that the statements in the statement list are at the level next to the if-else statement. 12/1/2018 ITK 168

if – else statement Statement list 1 Statement list 1 if (Condition) { } else // The rest of the // program Statement list 1 Condition Statement list 1 T Could have another if F Statement list 2 Statement list 2 The rest of the program 12/1/2018 ITK 168

More services provided by Robots int street int avenue Direction direction ThingBag backbag +Robot(City aCity, int aStreet, int anAvenue, Direction aDir) +boolean canPickThing() +int countThingsInBackpack() +boolean frontIsClear() +int getAvenue() +Direction getDirection() +String getLabel() +double getSpeed() +int getStreet() + public # protected - private 12/1/2018 ITK 168

If there is a blockade, then walk around; otherwise move along. import becker.robots.*; public class RobotV3 extends RobotV2 { public RobotV3(City theCity, int aStreet, int anAvenue, Direction aDirection) { super(theCity, aStreet, anAvenue, aDirection); } public void moveEast() { if (this.frontIsClear()) { this.move(); else { this.walkAroundToEast(); public void moveWest() { this.walkAroundToWest(); If there is a blockade, then walk around; otherwise move along. 12/1/2018 ITK 168

1 2 3 4 5 6 7 import .... public class UsingRobotV3 { public static void main(String[] args) { .... RobotV3 mark = new RobotV3(ny, 1, 0, Direction.EAST); mark.moveEast(); mark.pickThing(); mark.turnAround(); mark.moveWest(); } 1 2 3 4 5 6 7 12/1/2018 ITK 168

Disney Roller Coaster Ride Measure the kid’s height, h h < 4 No Yes Ride the roller coaster Boy or Girl? boy girl Give a Mickey Give a Mini Next Stop 12/1/2018 ITK 168

Disney Ride in Java h = Integer.parseInt( JOptionPane.showInputDialog(“How tall is the kid?”)); // IsBoy = true or false; if (h < 4) { if (IsBoy)// Same as if (IsBoy == true) System.out.println(“Take a Mickey”); } else System.out.println(“Take a Mini.”); } // end true part of if (h < 4) else // else part of if (h < 4) System.out.println(“You can ride!!”); } // end else part of if (h < 4) System.out.println(“Go to the next stop.”); 12/1/2018 ITK 168

This is still to specific!! import .... public class UsingRobotV3 { public static void main(String[] args) { .... RobotV3 mark = new RobotV3(ny, 1, 0, Direction.EAST); mark.moveEast(); mark.pickThing(); mark.turnAround(); } They are repeated operations 1 2 3 4 5 6 7 This is still to specific!! 12/1/2018 ITK 168

Loops Condition Statement list T F 12/1/2018 ITK 168

while when there is nothing to pick Statement Condition list while (Condition) { Statement list } Statement list T F move to next pos. 12/1/2018 ITK 168

1 2 3 4 5 6 7 import .... public class UsingRobotV3 { public static void main(String[] args) { .... RobotV3 mark = new RobotV3(ny, 1, 0, Direction.EAST); while (!mark.canPickThing()) { mark.moveEast(); } mark.pickThing(); mark.turnAround(); 1 2 3 4 5 6 7 12/1/2018 ITK 168

Definite Loop In programming a definite loop is more welcome. I.e., number of iterations is known before the loop begins, at least the upper bound is known. I.e., repeat the loop 100 times. Precisely speaking, there is no definite loop in Java We will talk about it in Chapter 5 12/1/2018 ITK 168