A Foundation for Programming

Similar documents
3.1 Objects 7/29/2014 1:49:50 PM

A Founda4on for Programming

26/3/ Creating Data Types. Data Type. Defining Data Types in Java. Point Charge Data Type. Charge Data Type: A Simple Client

3.2 Creating Data Types

3.2 Creating Data Types

Computer Science. 9. Creating Data Types. Computer Science COMPUTER SCIENCE. Section 3.2.

10. Creating Data Types

10. Creating Data Types

CS 112 Introduction to Programming

Admin. CS 112 Introduction to Programming. Recap: OOP. Math.random() Design. Static Math.random() method vs Random Objects

Handout 7. Defining Classes part 1. Instance variables and instance methods.

CS 112 Introduction to Programming

A foundation for programming. Classes and objects. Overview. Java primitive types. Primitive types Creating your own data types

CLASSES AND OBJECTS. Fundamentals of Computer Science I

Chapter 4 Defining Classes I

Review. Primitive Data Types & Variables. String Mathematical operators: + - * / % Comparison: < > <= >= == int, long float, double boolean char

Chapter 6 Introduction to Defining Classes

Anatomy of a Class Encapsulation Anatomy of a Method

Objects and Classes. 1 Creating Classes and Objects. CSCI-UA 101 Objects and Classes

Programming Language Concepts: Lecture 2

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

CLASSES AND OBJECTS. Fundamentals of Computer Science I

Object Oriented Programming in C#

CHAPTER 7 OBJECTS AND CLASSES

Chapter 4: Writing Classes

COMP 202. More on OO. CONTENTS: static revisited this reference class dependencies method parameters variable scope method overloading

OBJECT ORIENTED SIMULATION LANGUAGE. OOSimL Reference Manual - Part 1

ECOM 2324 COMPUTER PROGRAMMING II

Programming Language Concepts: Lecture 2

Chapter 12 Object-Oriented Programming. Starting Out with Games & Graphics in C++ Tony Gaddis

Lecture 5: Methods CS2301

Introduction to Classes and Objects. David Greenstein Monta Vista High School

13. Java Classes. Educational Objectives. Classes - Technical. Definition: Classes

Object Class. EX: LightSwitch Class. Basic Class Concepts: Parts. CS257 Computer Science II Kevin Sahr, PhD. Lecture 5: Writing Object Classes

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

Comp 248 Introduction to Programming Chapter 4 & 5 Defining Classes Part B

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

COMP 250 Winter 2011 Reading: Java background January 5, 2011


OO Programming Concepts. Classes. Objects. Chapter 8 User-Defined Classes and ADTs

CHAPTER 7 OBJECTS AND CLASSES

Chapter 9 Objects and Classes. OO Programming Concepts. Classes. Objects. Motivations. Objectives. CS1: Java Programming Colorado State University

Encapsula)on CMSC 202

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Object-Oriented Programming Concepts

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

COMP 202. More on OO. CONTENTS: static revisited this reference class dependencies method parameters variable scope method overloading

Computer Science II (20073) Week 1: Review and Inheritance

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

CmSc 150 Fundamentals of Computing I. Lesson 28: Introduction to Classes and Objects in Java. 1. Classes and Objects

3.1 Using Data Types. Data Type. Constructors and Methods. Objects. Data type. Set of values and operations on those values.

Week 6: Review. Java is Case Sensitive

Java Primer 1: Types, Classes and Operators

Classes and Objects Miscellany: I/O, Statics, Wrappers & Packages. CMSC 202H (Honors Section) John Park

CS111: PROGRAMMING LANGUAGE II. Lecture 1: Introduction to classes

Day 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University

Chapter 9 Objects and Classes. Liang, Introduction to Java Programming, Eleventh Edition, (c) 2017 Pearson Education, Inc. All rights reserved.

Unit3: Java in the large. Prepared by: Dr. Abdallah Mohamed, AOU-KW

D Programming Language

Procedural programming. [verb-oriented] Tell the computer to do this. (Spring 2012)

Methods and Data (Savitch, Chapter 5)

Objects and Classes. Basic OO Principles. Classes in Java. Mark Allen Weiss Copyright 2000

Classes and Objects. CGS 3416 Spring 2018

COP 3330 Final Exam Review

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch

B16 Object Oriented Programming

Assignment 1 due Monday at 11:59pm

Software Programming Objectives

10. Java Classes. Classes - Technical. Example: Earthquake catalog. Classes - Conceptual

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Comments are almost like C++

Object Oriented Programming. Assistant Lecture Omar Al Khayat 2 nd Year

Comp 248 Introduction to Programming Chapter 4 - Defining Classes Part A

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012

Cpt S 122 Data Structures. Introduction to C++ Part II

Designing data types. Overview. Object Oriented Programming. Alan Kay. Object Oriented Programming (OOP) Data encapsulation. Checking for equality

JAVA: A Primer. By: Amrita Rajagopal

Classes and objects. Chapter 2: Head First Java: 2 nd Edi4on, K. Sierra, B. Bates

CMSC 202H. Classes and Objects: Reusing Classes with Composition

Lecture 7. Log into Linux New documents posted to course webpage

Chapter 4. Defining Classes I

CSE 21 Intro to Computing II. Post-Midterm Review

Java. Classes 3/3/2014. Summary: Chapters 1 to 10. Java (2)

CIS3023: Programming Fundamentals for CIS Majors II Summer 2010

Encapsulation in C++

Fundamental Concepts and Definitions

Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat

Abstract Data Types. Different Views of Data:

Programming 2. Object Oriented Programming. Daniel POP

ECE 122. Engineering Problem Solving with Java

Designing data types. Fundamentals of Computer Science I

엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University COPYRIGHTS 2017 EOM, HYEONSANG ALL RIGHTS RESERVED

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

Encapsulation. Administrative Stuff. September 12, Writing Classes. Quick review of last lecture. Classes. Classes and Objects

CS1004: Intro to CS in Java, Spring 2005

Chapter 4. Defining Classes I

CSE 142 Su 04 Computer Programming 1 - Java. Objects

Transcription:

3.1 Objects Introduction to Programming in Java: An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Copyright 2002 2010 7/28/2015 3:46:55 PM

A Foundation for Programming any program you might want to write objects functions and modules graphics, sound, and image I/O arrays conditionals and loops create your own data types Math primitive data types text I/O assignment statements 2

Data Types Data Types: set of values and associated operations Primitive Types: values map directly to the machine representation ops map directly to machine instructions Data Type boolean int double Set of Values true, false -2 31 to 2 31-1 any of 2 64 possible reals Operations not, and, or, xor add, subtract, multiply add, subtract, multiply We want to write programs that handle other data types colors, pi tures, stri gs, i put strea s, complex u ers, e tors, atri es, poly o ials, points, polygo s, harged parti les, elestial odies, 3

Objects Objects: represent values and operations for more complex data types Object variables are called fields Object operations are called methods Data Type Color Set of Values 24 bits Operations get red component, brighten Picture 2D array of colors get/set color of pixel (i, j) String sequence of characters length, substring, compare Objects are said to encapsulate (hide) its detail How an object is implemented is not important What it does is important Objects can be created and referenced with variables 4

Object-Oriented Programming Programming paradigm that views a program as a collection of interacting objects In contrast, the conventional model views the program as a list of tasks (subroutines or functions) We ll talk a out ho to: Create your own data types (set of values and operations) Use objects in your programs (e.g., manipulate objects) Why would I want to use objects in my programs? Simplify your code Make your code easier to modify Share an object with a friend 5

The String Object Fields:??? Methods: boolean equals(string anotherstring) int length() String substring(int beginidx, int endidx) String tolowercase() String touppercase()... http://download.oracle.com/javase/1.4.2/docs/api/

Constructors and Methods To construct a new object: Use keyword new (to invoke constructor) Use name of data type (to specify which type of object) with associated parameters for the constructor To apply an operation: Use name of object (to specify which object) Use the dot operator (to access a member of the object) Use the name of the method (to specify which operation) 7

Defining Your Own Objects with Classes Classes are blueprints or prototypes for new objects Classes define all field and method declarations hi h are repeated for ea h e o je t reated Using a class to create a new object is called instantiating an object reati g a e o je t instance of the class Classes often model real-world items

Constructors A special method that is used in order to instantiate an object tri g s = e tri g Hello World ; If we made a Person class where you could create people with different names then you create a new person object by doing Perso p = e Perso Arvind ; Rule Constructor has the same name as the name of the class.

Bouncing Ball Object What do we want to have the ball do? (i.e., what methods should it have?) What initial parameters should we specify in the constructor? 10

Bouncing Ball Object What do we want to have the ball do? (i.e., what methods should it have?) oid dra : Ball, dra thyself! oid update : si ulate the all s otio What initial parameters should we specify in the constructor? 11

Bouncing Ball Object What do we want to have the ball do? (i.e., what methods should it have?) oid dra : Ball, dra thyself! oid update : si ulate the all s otio What initial parameters should we specify in the constructor? Ball() : creates a ball at a random location Ball (int x, int y) : creates a ball at (x, y) These ethods o stitute the all s API (Application Programming Interface) 12

Bouncing Ball Object Given only the API, we can use the object in a program: static Ball[] balls = new Ball[20]; public class BouncingBallStdDraw { Declare an array of Balls. public static void main(string[] args) { for (int i=0; i< balls.length; i++){ balls[i] = new Ball(); for (int i =0; i <300; i++){ StdDraw.clear(); for (int j=0; j < balls.length; j++) balls[j].draw(); StdDraw.show(200); for (int j=0; j< balls.length; j++) balls[j].update(); Ball ------------------ Ball() Ball(int x, int y) void draw() void update() New objects are created with the new keyword. Methods of objects stored in the array are accessed using dot-notation. 13

Where to Write Your Class Generally put each class in a separate file A class named MyClass is expected to be found in a file named MyClass.java Declare the class to be public This lass a o e used as a data type i your other programs 14

Comparing Declarations and Initializers int i; int j = 3; float f = 0.1; float[] f2 = new float[20]; String s1 = "abc"; String s2 = new String("abc"); Ball b = new Ball(); Ball[] b2 = new Ball[20]; for (int i = 0; i < b2.length; i++) { b2[i] = new Ball();

Object References Allow client to manipulate an object as a single entity Essentially a machine address (pointer) Ball b1 = new Ball(); b1.update(); b1.update(); Ball b2 = new Ball(); b2.update(); b2 = b1; b2.update(); addr value C0 0 C1 0 C2 0 C3 0 C4 0 C5 0 C6 0 C7 0 C8 0 C9 0 CA 0 CB 0 CC 0 main memory (64-bit machine) 16

Object References Allow client to manipulate an object as a single entity Essentially a machine address (pointer) Ball b1 = new Ball(); b1.update(); b1.update(); Ball b2 = new Ball(); b2.update(); b2 = b1; b2.update(); b1 C0 addr value C0 0.50 0 C1 0.50 0 C2 0.05 0 C3 0.01 0 C4 0.03 0 C5 0 C6 0 C7 0 C8 0 C9 0 CA 0 CB 0 CC 0 registers main memory (64-bit machine) 17

Object References Allow client to manipulate an object as a single entity Essentially a machine address (pointer) Ball b1 = new Ball(); b1.update(); b1.update(); Ball b2 = new Ball(); b2.update(); b2 = b1; b2.update(); b1 C0 addr value C0 C1 C2 C3 0.55 0.50 0.50 0.51 0.05 0.01 C4 0.03 C5 0 C6 0 C7 0 C8 0 C9 0 CA 0 CB 0 CC 0 registers main memory (64-bit machine) 18

Object References Allow client to manipulate an object as a single entity Essentially a machine address (pointer) Ball b1 = new Ball(); b1.update(); b1.update(); Ball b2 = new Ball(); b2.update(); b2 = b1; b2.update(); b1 C0 addr value C0 0.60 0.55 C1 0.51 0.52 C2 0.05 C3 0.01 C4 0.03 C5 0 C6 0 C7 0 C8 0 C9 0 CA 0 CB 0 CC 0 registers main memory (64-bit machine) 19

Allow client to manipulate an object as a single entity Essentially a machine address (pointer) Ball b1 = new Ball(); b1.update(); b1.update(); Ball b2 = new Ball(); b2.update(); b2 = b1; b2.update(); Object References b1 C0 b2 addr value C0 0.60 C1 0.52 C2 0.05 C3 0.01 C4 0.03 C5 0 C6 0 C7 C7 0.50 0 C8 0.50 0 C9 0.07 0 CA 0.04 0 CB 0.04 0 CC 0 registers main memory (64-bit machine) 20

Object References Allow client to manipulate an object as a single entity Essentially a machine address (pointer) Ball b1 = new Ball(); b1.update(); b1.update(); Ball b2 = new Ball(); b2.update(); b2 = b1; b2.update(); b1 C0 b2 C7 addr value C0 0.60 C1 0.52 C2 0.05 C3 0.01 C4 0.03 C5 0 C6 0 C7 0.57 0.50 C8 0.50 0.54 C9 0.07 CA 0.04 CB 0.04 CC 0 registers main memory (64-bit machine) 21

Object References Allow client to manipulate an object as a single entity Essentially a machine address (pointer) Ball b1 = new Ball(); b1.update(); b1.update(); Ball b2 = new Ball(); b2.update(); b2 = b1; b2.update(); C7 CB can be reused for other variables. Known as garbage collection in java. b1 C0 b2 C0 registers addr value C0 0.60 C1 0.52 C2 0.05 C3 0.01 C4 0.03 C5 0 C6 0 C7 0.57 C8 0.54 C9 0.07 CA 0.04 CB 0.04 CC 0 main memory (64-bit machine) 22

Object References Allow client to manipulate an object as a single entity Essentially a machine address (pointer) Ball b1 = new Ball(); b1.update(); b1.update(); Ball b2 = new Ball(); b2.update(); b2 = b1; b2.update(); Moving b2 also moves b1 since they are aliases that reference the same object. b1 C0 b2 C0 registers addr C0 value 0.65 0.60 C1 0.52 0.53 C2 0.05 C3 0.01 C4 0.03 C5 0 C6 0 C7 0.57 C8 0.54 C9 0.07 CA 0.04 CB 0.04 CC 0 main memory (64-bit machine) 23

Pass-By-Value Arguments to methods are always passed by value. Primitive types: passes copy of value of actual parameter. Objects: passes copy of reference to actual parameter. public class PassByValue { static void update(int a, int[] b, String c) { a = 7; b[3] = 7; c = "seven"; StdOut.println(a + " " + b[3] + " " + c); public static void main(string[] args) { int a = 3; int[] b = { 0, 1, 2, 3, 4, 5 ; String c = "three"; StdOut.println(a + " " + b[3] + " " + c); update(a, b, c); StdOut.println(a + " " + b[3] + " " + c); % java PassByValue 3 3 three 7 7 seven 3 7 three 24

Encapsulation 25

Access Control Encapsulation is implemented using access control. Separates interface from implementation Provides a boundary for the client programmer Visible parts of the class (the interface) can be used and/or changed by the client programmer. Hidden parts of the class (the implementation) Can be changed by the class creator without impacting any of the client programmer s code Can t be corrupted by the client programmer 26

Access Control in Java Visibility modifiers provide access control to instance variables and methods. public visibility - accessible by everyone, in particular the client programmer A class interface is defined by its public methods. private visibility - accessible only by the methods within the class Two others protected and package outside the scope of this course 27

Good Programming Practice Combine methods and data in a single class Label all instance variables as private for information hiding The class has complete control over how/when/if the instance variables are changed Fields primarily support class behavior Minimize the class public interface Public interface should offer only those methods that a client needs in order to interact with the class 28

Using this You can think of this as an implicit private reference to the current instance. Date b1 = new Date(); Date === public ==== Date() int getyear()... === private === int month int day int year Date this... b1 C0 registers addr value C0 1 C1 1 C2 1900 C3 C0 C4? C5? C6? main memory (64-bit machine) month day year this Note that b1.year and b1.this.year refer to the same field 29

Overloaded Constructors public class Date { private int month; // 1-12 private int day; // 1-31 private int year; // 4 digits // no-argument constructor public Date() { month = 1; day = 1; year = 1900; // alternative constructor public Date(int month, int day, int year) { this.month = month; this.day = day; this.year = year;... // 1 Jan 1900 Date d1 = new Date(); // 30 Oct 2013 Date d2 = new Date(10, 30, 2013); Note the usage of the this keyword to avoid the obvious ambiguity 30

Accessors & Mutator Class behavior may allow access to, or modification of, individual private instance variables. Accessor method retrieves the value of a private instance variable conventional to start the method name with get Mutator method changes the value of a private instance variable conventional to start the name of the method with set Gives the client program indirect access to the instance variables. 31

More Accessors and Mutators Question: Doesn t the use of accessors and mutators defeat the purpose of making the instance variables private? Answer: No The class implementer decides which instance variables will have accessors. Mutators can: validate the new value of the instance variable, and decide whether or not to actually make the requested change. 32

Accessor and Mutator Example public class Date { private int month; // 1-12 private int day; // 1-31 private int year; // 4-digit year // accessors return the value of private data public int getmonth() { return month; // mutators can validate the new value public boolean setmonth(int month) { if (1 <= month && month <= 12) { this.month = month; return true; else // this is an invalid month return false; // rest of class definition follows 33

Accessor/Mutator Caution In general you should NOT provide accessors and mutators for all private instance variables. Recall that the principle of encapsulation is best served with a limited class interface. 34

Private Methods Methods may be private. Cannot be invoked by a client program Can only be called by other methods within the same class definition Most commonly used as helper methods to support top-down implementation of a public method 35

Private Method Example public class Date { private int month; // 1-12 private int day; // 1-31 private int year; // 4-digit year // accessors return the value of private data public int getmonth() { return month; // mutators can validate the new value public boolean setmonth(int month) { if (isvalidmonth(month)) { this.month = month; return true; else // this is an invalid month return false; // helper method - internal use only private boolean isvalidmonth(int month) { return 1 <= month && month <= 12; 36

Static and Final 37

Static Variable A static variable belongs to the class as a whole, not just to one object. There is only one copy of a static variable per class. All objects of the class can read and change this static variable. A static variable is declared with the addition of the modifier static. static int mystaticvariable = 0; Copyright 2008 Pearson Addison-Wesley. All rights reserved 38

Static Variable The most common usage of a static variable is in order to keep track of the number of instances of an object. Assume class called Human. There is some o trolli g lass hi h reates hu a s e Human()) and it also is responsible for the death of humans. We would like to keep track of the number of Humans. One way to do this would be have a static variable in the Human class which gets incremented upon child birth and decremented upon death. Copyright 2008 Pearson Addison-Wesley. All rights reserved 39

Static Constants A static constant is used to symbolically represent a constant value. The declaration for a static constant includes the modifier final, which indicates that its value cannot be changed: public static final float PI = 3.142; It is not necessary to instantiate an object to access a static variable, constant or method. When referring to such a constant outside its class, use the name of its class in place of a calling object. float radius = MyClass.PI * radius * radius; Copyright 2008 Pearson Addison-Wesley. All rights reserved 40

Rules for Static Methods Static methods have no calling/host object (they have no this). Therefore, static methods cannot: Refer to any instance variables of the class Invoke any method that has an implicit or explicit this for a calling object Static methods may invoke other static methods or refer to static variables and constants. A class definition may contain both static methods and non-static methods. 41

main = Static Method Note that the method header for main( ) is public static void main(string[] args) Being static has two effects: main can be executed without an object. Helper methods called by main must also be static. Hence public static when you were first introduced to functions 42

Any Class Can Have a main( ) Every class can have a public static method name main( ). Java will execute the main that exists in whichever class you choose to run java <classname> A convenient way to write test code for your class. 43

Static Review Given the skeleton class definition below public class C { public int a = 0; public static int b = 1; public void f() { public static void g() { Can body of f() refer to a? Can body of f() refer to b? Can body of g() refer to a? Can body of g() refer to b? Can f() call g()? Can g() call f()? For each, explain why or why not. 44

BACKUP/EXTRA SLIDES 45

Complex Numbers

Complex Number Data Type Goal: Create a data type for complex numbers Values: the real and imaginary parts (doubles) a = 3 + 4i, b = -2 + 3i a + b = 1 + 7i a b = -18 + i a = 5 47

Applications of Complex Numbers Fractals Impedance in RLC circuits Signal processing and Fourier analysis Control theory and Laplace transforms Quantum mechanics and Hilbert spaces 48

Complex Number Data Type: A Simple Client public static void main(string[] args) { Complex a = new Complex( 3.0, 4.0); Complex b = new Complex(-2.0, 3.0); Complex c = a.times(b); StdOut.println("a = " + a); StdOut.println("b = " + b); StdOut.println("c = " + c); % java TestClient a = 3.0 + 4.0i result of c.tostring() b = -2.0 + 3.0i c = -18.0 + 1.0i 49

Complex Number Data Type: Implementation public class Complex { private final double re; private final double im; fields public Complex(double real, double imag) { re = real; im = imag; constructor public String tostring() { return re + " + " + im + "i"; public double abs() { return Math.sqrt(re*re + im*im); public Complex plus(complex b) { double real = re + b.re; double imag = im + b.im; return new Complex(real, imag); creates a Complex object, and returns a reference refers to b's public Complex times(complex b) { instance variable double real = re * b.re im * b.im; double imag = re * b.im + im * b.re; return new Complex(real, imag); methods 50

Mandelbrot Set Mandelbrot set: A set of complex numbers Plot (x, y) black if z = x + y i is in the set, and white otherwise. 51

Mandelbrot Set Is complex number z 0 in the set? Iterate z t + 1 = (z t ) 2 + z 0 If z t diverges to infinity, then z 0 is not in set; otherwise z 0 is in set t z t t z t 0-1/2 + 0i 0 1 + i 1-1/4 + 0i 1 1 + 3i 2-7/16 + 0i 2-7 + 7i 3-79/256 + 0i 3 1-97i 4-26527/65536 + 0i 4-9407 193i 5-1443801919/4294967296 + 0i 5 88454401 + 3631103i z = -1/2 is in Mandelbrot set z = 1 + i not in Mandelbrot set 52

Plotting the Mandelbrot Set Practical issues: Cannot plot infinitely many points Cannot iterate infinitely many times Approximate solution: Sample from an N-by-N grid of points in the plane Fact: if z t > 2 for any t, then z not in Mandelbrot set if z 255 2 then z "likely" in Mandelbrot set (0.5, 1) -0.6 + 0.1i (-1.5, -1) 10-by-10 grid 53

Complex Number Data Type: Another Client Mandelbrot function with complex numbers Is z 0 in the Mandelbrot set? Returns white (definitely no) or black (probably yes) public static Color mand(complex z0) { Complex z = z0; for (int t = 0; t < 255; t++) { if (z.abs() > 2.0) return StdDraw.WHITE; z = z.times(z); z = z.plus(z0); z = z 2 + z 0 return StdDraw.BLACK; new Color(255-t, 255-t, 255-t) More dramatic picture: replace StdDraw.WHITE with grayscale or color 54

Complex Number Data Type: Another Client Plot the Mandelbrot set in gray scale. public static void main(string[] args) { double xc = Double.parseDouble(args[0]); double yc = Double.parseDouble(args[1]); double size = Double.parseDouble(args[2]); int N = 512; Picture pic = new Picture(N, N); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { double x0 = xc - size/2 + size*i/n; double y0 = yc - size/2 + size*j/n; Complex z0 = new Complex(x0, y0); Color color = mand(z0); pic.set(i, N-1-j, color); (0, 0) is upper left pic.show(); scale to screen coordinates 55

Mandelbrot Set % java Mandelbrot.5 0 2 % java Mandelbrot.1045 -.637.01 56