An OOP Example ACO 101: Intro to CS. Engineer the illusion of simplicity.

Slides:



Advertisements
Similar presentations
Machine Learning Homework
Advertisements

2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
CS0004: Introduction to Programming Visual Studio 2010 and Controls.
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
How to use a scanner Throughout this slide show there will be hyperlinks (highlighted in blue) follow the hyperlinks to navigate to the specified Topic.
Problem Solving and Algorithm Design
Chapter 6 Problem Solving and Algorithm Design. 6-2 Chapter Goals Determine whether a problem is suitable for a computer solution Describe the computer.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington UML for design: Class Diagrams.
Event Driven Programming and GUIs Part 3 CS221 – 4/15/09.
Alice Variables Pepper. Set to Java look Edit / preferences restart.
ObjectDraw and Objects Early Chris Nevison Barbara Wells.
Lecture Notes 1/21/04 Program Design & Intro to Algorithms.
Chapter 6 Problem Solving and Algorithm Design Nell Dale John Lewis.
CS 201 Functions Debzani Deb.
A Simple Applet. Applets and applications An applet is a Java program that runs on a web page –Applets can be run from: Internet Explorer Netscape Navigator.
A Simple Applet.
Lecture Notes 8/30/05 Program Design & Intro to Algorithms.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
Introduction to Computers and Programming
Programming Paradigms Imperative programming Functional programming Logic programming Event-driven programming Object-oriented programming A programming.
C++ Crash Course Class 1 What is programming?. What’s this course about? Goal: Be able to design, write and run simple programs in C++ on a UNIX machine.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Functions Part I (Syntax). What is a function? A function is a set of statements which is split off into a separate entity that can be used like a “new.
Information Trapping Subscribing to RSS Feeds or Alerts to Make Research Easier.
ACO 101 – Intro to Computer Science.  28object-oriented_programming%29
CS 350 – Software Design The Object Paradigm – Chapter 1 If you were tasked to write code to access a description of shapes that were stored in a database.
4/2/03I-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Software Architecture and Design Readings: Ambler, Chap. 7 (Sections to start.
CSE 219 Computer Science III Images. HW1 Has been posted on Blackboard Making a Game of Life with limited options.
Constructing Objects Lab. Log into Wiley Plus Read the problem Write a BankAccountTester class whose main method constructs a bank account, deposits.
Lab 6: Shapes & Picture Extended Ellipse & Rectangle Classes Stand-Alone GUI Applications.
> 1 Diagrams in Word Faculty of Health Alan Grace.
Chapter 1 - Getting to know Greenfoot
Go to your school’s web locker site school name.schoolweblockers.com) Your user name is the first letter of your first name, the first 4.
ACO 101 Instantiating Graphic Objects. Review: 4 Phases to the Development Lifecycle Inception (Analysis & Design) – Business Requirements Business Analyst.
Lab 6: event & input intro User Interface Lab: GUI Lab Oct. 2 nd, 2013.
Moving Around in Scratch The Basics… -You do want to have Scratch open as you will be creating a program. -Follow the instructions and if you have questions.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. In order to display a drawing in a frame, define a class that extends.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
UML Class Diagram Trisha Cummings. What we will be covering What is a Class Diagram? Essential Elements of a UML Class Diagram UML Packages Logical Distribution.
BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class.
Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.
Making Python Pretty!. How to Use This Presentation… Download a copy of this presentation to your ‘Computing’ folder. Follow the code examples, and put.
© 2000 McGraw-Hill Modified by C.W.Pang with author's permission Intro to OOP with Java--Wu Chapter Chapter 1 Introduction to Object-oriented Programming.
Intro to CS ACO 101 Lab Rat. Academic Integrity What does that mean in programming? Log into Blackboard and take the test titled “Applied Computing Course.
CS0007: Introduction to Computer Programming Classes: Documentation, Method Overloading, Scope, Packages, and “Finding the Classes”
Algebraic Thinking 5 th Grade Guided Instruction Finding Rules and Writing Equations For Patterns.
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 12 Object-Oriented Programming Starting Out with Games & Graphics.
“Planning” or “why use objects?” ACO101: Introduction to Computer Science.
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
1 Project 2: Using Variables and Expressions. 222 Project 2 Overview For this project you will work with three programs Circle Paint Ideal_Weight What.
A PC Wakes Up A STORY BY VICTOR NORMAN. Once upon a time…  a PC (we’ll call him “H”) is connected to a network and turned on. Aside: The network looks.
Observer / Observable COMP 401 Fall 2014 Lecture 14 10/7/2014.
Basic Organization of UI Software. 2 The User Interface n Typically want to think of “UI” as only one component of an overall system – The part that “deals.
Georgia Institute of Technology Comic Strip Analysis and Design Inheritance, Abstract Classes, and Polymorphism part1 Barb Ericson Georgia Institute of.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Today Javadoc. Packages and static import. Viewing API source code. Upcoming Topics: –protected access modifier –Using the debugger in Eclipse –JUnit testing.
CompSci 4 Java 4 Apr 14, 2009 Prof. Susan Rodger.
Visual Basic Programming Introduction to Computers Programming.
Week 10: Object Modeling (1)Use Case Model
Adding Assignments and Learning Units to Your TSS Course
Programming We have seen various examples of programming languages
Problem Solving Designing Algorithms.
Tonga Institute of Higher Education IT 141: Information Systems
Building Java Programs
Tonga Institute of Higher Education IT 141: Information Systems
Presentation transcript:

An OOP Example ACO 101: Intro to CS

Engineer the illusion of simplicity

Abstraction: Turner “about atmospherics, not finicky topographical description” How awful is the silence of the waste Where Nature lift* her mountains to the sky; Majestic solitude, behold the tower, Where hopeless Owen, long imprison'd, pined And wrung his hands for liberty in vain

about atmospherics

Review: Object Oriented Abstraction : aka Entity Abstraction

Review: Identifying Classes During design, you need to identify the classes. Classes are used to model things: Tangible things in the design: nouns, such as – purse, mailbox, bank account, keypad, message Users – Student, Administrator, Bank Manager Agents ("-er" or "-or" words) – Scanner, file reader, sentence reader, CSVreader – agents perform some operation (sentence reader) Events and Transactions – Button click, ATM Withdrawal, Register for Course are all events – transactions are uses for interactions between classes, usually contain info that doesn't "belong" in a thing class

See the big picture

Recognize the pieces

Identify the modules and abstract

Step 1 Take the time to read and understand the problem. Look up stuff in the API you don’t understand Make a sequence diagram to try to understand what you need to do – a sequence diagram is a way to make a picture of the solution

Launch labrat Don’t forget to run the bat file [at school only] and pick the JDK.

The problem: draw a house

Implement a class house and supply a method draw

Supply a method draw(Graphics 2D g2)

draw(Graphics 2D What does this tell us? If you are not sure what this means look it up in the API pi/index.html pi/index.html

Graphics 2D in the API look it has a method called draw

Soo…. We are supposed to supply a method called draw And one of the objects we are required to use has a draw method – The draw method of the Graphics 2D class is used to: “Strokes the outline of a Shape using the settings of the current Graphics2D context.” Huh. – Who talks like that?

Take a moment to understand Strokes the outline of a Shape using the settings of the current Graphics2D context. – Strokes the outline of a Shape = draw an outline of a shape Shape = what shape have we seen so far? – Rectangle

Take a second moment to understand Strokes the outline of a Shape using the settings of the current Graphics2D context. – What alien planet talks like that? Is that where Shakespeare is from? – What makes sense? Graphics 2D – Lets go look at it again in the problem

Supply a method draw(Graphics 2D g2) Hmmm… the Graphics 2D object is being passed into the method draw that I am supposed to supply. – using the settings of the current Graphics2D context – Looks like the current context is g2 And g2 will have a method called draw

The draw method of the Graphics 2D class has a Shape parameter

huh Soooo…. If I pass in a shape to the draw method of the Graphics 2D object – will it draw it?

There are shapes in that there drawin’

Ok so let me see if I grock this I gotta write a program that will draw shapes in the configuration of a house using the Graphics 2D object. – This is the big picture – about atmospherics, not finicky topographical description So back to the code snippet [now we need to be finicky]

Make a new frame and set it up, oh, I need a piece of paper [all the stuff in the main method is code that they gave me]

Make a new frame and set it up, I need a piece of paper

Make a house component and add it to the frame

Make the frame visible

Ok so I get the main method On to the house component next. Look at the code snippet –

HouseComponent extends JComponent

What does it mean to extend? this is part of what you will learn in 102; but for now you can google terms you don’t understand

Tell me please, what is JComponent? Where can I find that answer? It is a class in the Java Library Where do you find the java library documentation?

JComponent has fields

It has a constructor and methods

Hummpf… I am stumped I'm going back to the code.

Point at which people get lost because they don’t slow down and take notice: HouseComponent has a method called paint component – since it extends JComponent I wonder if JComponent has a method of the same name

And it does; so now we know what the HouseComponent method will do. It will draw the UI.

How does paint component get called? When a window becomes visible (uncovered or deminimized) or is resized, the "system" automatically calls the paintComponent() method for all areas of the screen that have to be redrawn. – lowlevel/graphics/15who-calls- paintcomponent.html lowlevel/graphics/15who-calls- paintcomponent.html Back to the code – how did Wiley Plus override the method?

Make a graphics 2D object, make a house object and draw

What the whole sequence looks like

What is happening inside draw?

a series of steps to draw the house You need an algorithm

Review: the Ways to break it down (abstract the problem domain) Procedurally = algorithms – Things happen when subprograms are called and statements are executed Object-oriented = classes and objects – Things happen when objects are operated on Logic = goals – Things happen based on what need to happen next to attain a goal Rule based = if then rules – Things happen when events cause new rules to fire Constraint = invariant relationships – Things happening is dependent on what you can’t do.

Your first Algorithm An algorithm is a step sequence. It has 3 characteristics – Unambiguous = precise instructions for what to do at each step and where to go next – Executable = can be carried out in practice – Terminating = it will end You can describe an algorithm with pseudocode

Everyday Algorithms

Pseudocode is an informal way of saying what a program is going to do there are no real rules – there is no right or wrong way

Pseudocode for the algorithm for draw Create a new Rectangle for the window Create a new Rectangle for the door Create a new Rectangle for the outline Create a new Line for the roof on the left side Create a new Line for the roof on the right side Draw the window Draw the door Draw the outline Draw the roof left side Draw the roof right side

Now that you have a plan It is time to code – Use the sequence diagram and the pseudocode to help you code

Download the files

Here are the files

Open the house class the ellipses […] indicate where you need to code

The comments are telling you what you need. You have 2 parameters [one for x and one for y] and you need to assign them to the left corner coordinate and the bottom corner

So what do I need for the coordinates? The parameters are already there but the coordinates are not…. The coordinates are what an the house object knows about itself. What part of an object holds the state again?

Fields hold the state

And then what do we do with The fields in the constructor???

Assign them

The constructor and the fields are done It is time for the draw method

What goes in here? Consult your pseudocode

Pseudocode for the algorithm for draw Create a new Rectangle for the window Create a new Rectangle for the door Create a new Rectangle for the outline Create a new Line for the roof on the left side Create a new Line for the roof on the right side Draw the window Draw the door Draw the outline Draw the roof left side Draw the roof right side

Create rectangles

Draw rectangles

The lines are up to you Look up Line2D.Double in the API and figure out how to create and draw them on your own. This is an in class assignment so you can discuss it all you want to outside of class.

Homework Finish Wiley plus More rectangles Start on your first program: rubric posted