Robot Class name Attributes Constructor Services, methods

Slides:



Advertisements
Similar presentations
Based on Java Software Development, 5th Ed. By Lewis &Loftus
Advertisements

CS18000: Problem Solving and Object-Oriented Programming.
INHERITANCE BASICS Reusability is achieved by INHERITANCE
Object Oriented Programming in Java. Object Oriented Programming Concepts in Java Object oriented Programming is a paradigm or organizing principle for.
1 Inheritance: From membership point of view Vehicle SUV Honda Pilot Object Number Integer Double Base concept Derived concept Java Base class Derived.
Inheritance Inheritance Reserved word protected Reserved word super
Inheritance Polymorphism Briana B. Morrison CSE 1302C Spring 2010.
Dialogs. Displaying Text in a Dialog Box Windows and dialog boxes –Up to this our output has been to the screen –Many Java applications use these to display.
UML – Class Diagrams.
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
Using JOptionPanes for graphical communication with our programs. Pages Horstmann 139.
1 Introduction to Java Programming Lecture 4 Using JOptionPane Spring 2008.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Relational Operators Control structures Decisions using “if” statements  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course.
JOptionPane class. Dialog Boxes A dialog box is a small graphical window that displays a message to the user or requests input. A variety of dialog boxes.
Lab 1 City, Robot, Thing, Wall. Documentation of Classes and Methods.
1 Purposes: Learn JAVA 1.What is programming languages 2.How to solve problems by computers 1.a CS major student, get a degree in BS 2.a programmer  system.
9/12/2015IT 2751 IDE ( Integrated Development Environment ) 1.A customized plain text editor 2.Compiler 3.Loader 4.Debugging tool JDK (Java Development.
1 Object-Oriented Software Engineering CS Interfaces Interfaces are contracts Contracts between software groups Defines how software interacts with.
Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-
1 Cash = Double.parseDouble( JOptionPane.showInputDialog("Cash: ") ); Package – Class (application programming interface)
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Chapter 12 – Object-Oriented Design.
Programming Fundamentals 2: Simple/ F II Objectives – –give some simple examples of Java applications and one applet 2. Simple Java.
1 COMP 241: Object-Oriented Programming with Java Fall 2004 Lecture 1 September 27, 2004 Serdar Taşıran.
BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class.
Object Oriented Programming Examples: C++, Java Advantages: 1. reusibility of code 2. ability to adapt (extend) previously written code.
1/28: Inputs, Variable Types, etc. Addition.java in depth Variable types & data types Input from user: how to get it Arithmetic operators.
Outline Creating Subclasses Overriding Methods Class Hierarchies Visibility Designing for Inheritance Inheritance and GUIs The Timer Class Copyright ©
Chapter 8 Inheritance Part 1. © 2004 Pearson Addison-Wesley. All rights reserved8-2 Inheritance Inheritance is a fundamental object-oriented design technique.
Data Types – Reference Types Objective To understand what reference types are The need to study reference types To understand Java standard packages To.
1/16/2008ITK 1681 HardwareSoftware Theory 1800 AD  Architecture 1945 AD  What is Computer Science? Languages 1960 AD 
Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used.
Topics Inheritance introduction
AP Computer Science A – Healdsburg High School 1 Inheritance - What is inheritance? - “Is-a” vs. “Has-a” relationship - Programming example “CircleBug”
 2005 Pearson Education, Inc. All rights reserved. 1 Introduction to Classes and Objects.
AD Lecture #1 Object Oriented Programming Three Main Principles 1 Inheritance Encapsulation Polymorphism.
For Friday Finish reading chapter 2 Complete WebCT quiz.
1 Classes: A class is a concept of something Vehicle 4 wheels, seats, engine, windows, color…… accelerate, start, stop, turn, … attributes.
Java Inheritance 1/13/2015. Learning Objectives Understand how inheritance promotes software reusability Understand notions of superclasses and subclasses.
Casting, Wrapper Classes, Static Methods, JOptionPane Class.
Object Oriented Programming Object and Classes Lecture 3 MBY.
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 6 Acknowledgement: Contains materials provided by George Koutsogiannakis and Matt Bauer.
© 2004 Pearson Addison-Wesley. All rights reserved April 10, 2006 Inheritance (part 2) ComS 207: Programming I (in Java) Iowa State University, SPRING.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Outline Creating Subclasses Overriding Methods Class Hierarchies Inheritance.
Introduction to UML and Rational Rose UML - Unified Modeling Language Rational Rose 98 - a GUI tool to systematically develop software through the following.
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.
Chapter 12 – Object-Oriented Design
Lecture 12 Inheritance.
A Java Program: // Fig. 2.1: Welcome1.java // Text-printing program.
OBJECT ORIENTED PROGRAMMING II LECTURE 7 GEORGE KOUTSOGIANNAKIS
Java Inheritance.
Chapter 10 Thinking in Objects
Java Inheritance.
OBJECT ORIENTED PROGRAMMING II LECTURE 8 GEORGE KOUTSOGIANNAKIS
ITK 168 Lecture 5 - Inheritance
Chapter 2 - Introduction to Java Applications
import becker.robots.City;
INHERITANCE BASICS Reusability is achieved by INHERITANCE
Unit 1 Lab16.
ITK 168 Section 13 Dr. Doug Twitchell.
Basics of OOP A class is the blueprint of an object.
Branching Statement Condition Statement Condition list 1 list
IDE (Integrated Development Environment)
JOptionPane class.
F II 2. Simple Java Programs Objectives
Java Inheritance.
Presentation transcript:

Robot Class name Attributes Constructor Services, methods int street int avenue Direction direction ThingBag backbag ... Robot(City aCity, int aStreet, int aAvenue, Direction aDir) void move() void turnLeft() void pickThing() void putThing() Class name Attributes Constructor Services, methods UML class diagram for Robot 1/23/2008 ITK 168

Modeling what? Modeling Robots in a City with Software Classes. Robot int street int avenue Direction direction ThingBag backbag ... Robot(City aCity, int aStreet, int aAvenue, Direction aDir) void move() void turnLeft() void pickThing() void putThing() City String name int stree_No int ave_No ... .... City(...........) 1/23/2008 ITK 168

Task: deliver X from (1,2) to (3,1) and step away import becker.robot.*; public class DeliverX{ public static void main(String args[]){ // set up Initial situation City A = new City(); Thing X = new Thing(A,1,2); Robot karel = new Robot(A,0,0, Direction.East); // direct the robot karel.move(); karel.turnLeft(); karel.turnLeft(); karel.turnLeft(); karel.pickThing(); karek.move(); karel.move(); karel.move(); karel.putThing(); } 1 2 3 4 X 1 2 3 4 named Karel 1/23/2008 ITK 168

Task: deliver X from (1,2) to (3,1) and step away import becker.robot.*; public class DeliverX{ public static void main(String args[]){ // set up Initial situation City A = new City(); Thing X = new Thing(A,1,2); Robot karel = new Robot(A,0,0, Direction.East); // direct the robot karel.turnLeft(); karel.turnLeft(); karel.turnLeft(); karel.move(); karel.pickThing(); karek.move(); karel.putThing(); } 1 2 3 4 X 1 2 3 4 named Karel 1/23/2008 ITK 168

Anatomy of a Java Program import becker.robot.*; public class DeliverX{ public static void main(String args[]){ // set up Initial situation City A = new City(); Thing X = new Thing(A,1,2); Robot karel = new Robot(A,0,0,Direction.East); // direct the robot karel.move(); karel.turnLeft(); karel.turnLeft(); karel.turnLeft(); karel.pickThing(); karek.move(); karel.move(); karel.move(); karel.putThing(); } 1/23/2008 ITK 168

Package: collection of classes // Java API: Java Application Programming Interface // (java., javax.) // GUI: Graphical User Interface // // using swing package, JOptionPane class // showMessageDialog method import javax.swing.JOptionPane; public class TestPane{ public static void main(String args[]){ JOptionPane.showMessageDialog( null, "Welcome\nTo\nswing\nPackage"); System.exit(0); } 1/23/2008 ITK 168

class defined in the package A Java program package import javax.swing.JOptionPane; public class time{ public static void main(String args[]){ int x,y,z; String X,Y; X = JOptionPane.showInputDialog("Input x"); Y = JOptionPane.showInputDialog("Input y"); x = Integer.parseInt(X); y = Integer.parseInt(Y); z = x*y; JOptionPane.showMessageDialog( null, x + " * " + y + " = " + z, "The product of " + x + " and " + y, JOptionPane.PLAIN_MESSAGE ); System.exit(0); } class defined in the package 1/23/2008 ITK 168

A Java Program: // Text-printing program. public class Welcome1 { // main method begins execution of Java application public static void main( String args[] ) { System.out.println( "Welcome to Java Programming!" ); } // end method main } // end class Welcome1 /********************************************************* *(C) Copyright 1992-2003 by ...... * * * **********************************************************/ 1/23/2008 ITK 168

Reusing Codes Composition A class has another class, “has a” relation Inheritance A class has another class, “has a” relation A car has an engine A class inherits another class, “is a” relation An SUV is a car 1/23/2008 ITK 168

Composition: has a A DeliverX has a main, The main has a City, Thing, and a Robot import becker.robot.*; public class DeliverX{ public static void main(String args[]){ // set up Initial situation City A = new City(); Thing X = new Thing(A,1,2); Robot karel = new Robot(A,0,0, Direction.East); ...... } 1/23/2008 ITK 168

Composition: has a A BankAccount has a Client, has a List of BankTransaction public class BankAccount { private Client client; private List<BankTransaction> transactions; // other fields ... } 1/23/2008 ITK 168

Classes: A class is a concept of something Vehicle 4 wheels, seats, engine, windows, color…… accelerate, start, stop, turn, lock, ............... Truck ………… Sedan ………… Focus ………… Matrix ………… SUV ………… 1/23/2008 ITK 168

Inheritance: From membership point of view A SUV is a vehicle, but a vehicle may not be a SUV Any SUV is a Vehicle Vehicle SUV Base concept Honda Pilot Derived concept Java Object Number Base class Integer Double Derived class 1/23/2008 ITK 168

Inheritance: From functionality point of view All vehicle can do, SUV can too The SUV has every properties and function of the Vehicle SUV Vehicle Derived class Base class 1/23/2008 ITK 168

UML (Unified Modeling Language) Diagram Vehicle SUV Truck Sedan Honda Pilot Focus Matrix Matrix XRS 1/23/2008 ITK 168

my_a is invisible to B = A - my_a: int +get_a():int B B - my_b: int +get_b():int B - my_b: int +get_a():int +get_b():int = 1/23/2008 ITK 168

Base class (superclass) & Derived class (extended subclass) // A is a base class public class A { private int my_a; Public A(int a) { my_a = a; } public int get_a() { return my_a; // B is a derived class Public class B extends A { private int b; public B(int a, int b) { super(a); this.b = b; } public int get_b() { return b; A a = new A(2); B b = new B(3,7); I = a.get_a(); J = b.get_a(); K = b.get_b(); B inherits A’s functions and variables. 1/23/2008 ITK 168

An enhanced robot = Robot ExperimentRobot ExperimentRobot int street int avenue Direction direction ThingBag backback Robot(City aCity, int aStreet, int anAvenue, Direction aDir) void move() void turnLeft() void pickThing() void putThing() An enhanced robot ExperimentRobot int street int avenue Direction direction ThingBag backback ExperimentRobot(City aCity, int aStreet, int anAvenue, Direction aDir) void move() void turnLeft() void pickThing() void putThing() void turnAround(); void turnRight(); void move3(); ExperimentRobot ExperimentRobot(City aCity, int aStreet, int anAvenue, Direction aDir) void turnAround(); void turnRight(); void move3(); = 1/23/2008 ITK 168