Programming What is a program? A set of instructions Understood by - - PowerPoint PPT Presentation

programming
SMART_READER_LITE
LIVE PREVIEW

Programming What is a program? A set of instructions Understood by - - PowerPoint PPT Presentation

Programming What is a program? A set of instructions Understood by a computer What does a program look like? An algorithm is a set of instructions designed to accomplish a specific goal For a temperature f in Fahrenheit


slide-1
SLIDE 1

Programming

 What is a program?

 A set of instructions  Understood by a computer

slide-2
SLIDE 2

What does a program look like?

 An algorithm is a set of instructions designed to

accomplish a specific goal

 For a temperature f in Fahrenheit

 Subtract 32 from f.  Divide f by 1.8.  Display the value of f.  [Converts to Celsius]

 Don’t need to understand the goal to follow

instructions

slide-3
SLIDE 3

Programming Languages

 A language is a tool with which we tell a

computer an algorithm

 Compilers translate from one computer language

to another

 Each language has own advantages and

disadvantages

slide-4
SLIDE 4

What is Alice?

 A programming environment.

slide-5
SLIDE 5

What is Alice?

 A programming language.  A library of graphic objects

slide-6
SLIDE 6

What is Alice?

A tool for running animations

slide-7
SLIDE 7

What about JAVA?

 BlueJ - a programming environment designed to

teach programming

slide-8
SLIDE 8

The Java Language

 A programming language (Widely Used)  Can be compiled on many computer systems

public class TouchyWindow extends WindowController { public void onMousePress ( Location point ) { new Text("I’m touched", 40, 50, canvas ); } public void onMouseRelease( Location point ) { canvas.clear(); } }

slide-9
SLIDE 9

What about Java?

 A huge library, but less visual

 2D Graphical shapes - circles, lines, …  User interface elements - buttons, sliders, …  Networking  Image manipulation  Many, many things

 A tool for running a wide range of applications

slide-10
SLIDE 10
slide-11
SLIDE 11
slide-12
SLIDE 12
slide-13
SLIDE 13

Methods in Java

public class TouchyWindow extends WindowController { public void onMousePress ( Location point ) { new Text("I’m touched", 40, 50, canvas ); } public void onMouseRelease( Location point ) { canvas.clear(); } }

slide-14
SLIDE 14

Types

 Number  Boolean  Object  int  double  boolean  Penguin  Location  Train  …

slide-15
SLIDE 15

Event Handling

In Alice:

In Java: public class TouchyWindow extends WindowController { public void onMousePress ( Location point ) { new Text("I’m touched", 40, 50, canvas ); } public void onMouseRelease( Location point ) { canvas.clear(); } }

slide-16
SLIDE 16

Creating Objects

 In Alice:  In Java:

In Java: public class TouchyWindow extends WindowController { public void onMousePress ( Location point ) { new Text("I’m touched", 40, 50, canvas ); } public void onMouseRelease( Location point ) { canvas.clear(); } }

slide-17
SLIDE 17

Anatomy of a Java Class: set, collection group, or configuration containing members regarded as having certain attributes or traits in common

import objectdraw.*; import java.awt.*; public class TouchyWindow extends WindowController { public void onMousePress ( Location point ) { new Text("I’m touched", 40, 50, canvas ); } public void onMouseRelease( Location point ) { canvas.clear(); } }

Method Instruction parameter class

slide-18
SLIDE 18

Coordinate system

 Coordinates measure pixels, the smallest dot of

color a display can make

slide-19
SLIDE 19

Methods and Constructors

public class TouchyWindow extends WindowController { public void onMousePress ( Location point ) { new Text("I’m touched", 40, 50, canvas ); } public void onMouseRelease( Location point ) { canvas.clear(); } }

Constructor call Method call

slide-20
SLIDE 20

Graphical Objects

new Text ( "I’m Touched", 40, 50, canvas );

 new an instruction that tells we want to construct

a new object

 Text the object we want to construct  (…) comma delineated “parameters” that tell how

to construct the object

 ; semicolons are important too!

 every command semicolon terminated

slide-21
SLIDE 21

Graphical Objects

new Text ( "I’m Touched", 40, 50, canvas );

slide-22
SLIDE 22

Events

In Alice, need to specify which method to call when an event occurs Java: public void onMousePress( Location point )

 Will run the code when mouse button is pressed

 onMouseRelease:

 Runs code when the buttons released

 Many more mouse event handling methods

slide-23
SLIDE 23

Summary

 Many similarities in programming concepts  Alice - limited to creating animations  Java - wide applicability  Alice programming environment - menu,

drag&drop eliminates syntax errors, but clumsy

 Java programming environment - less clumsy, but

requires learning syntax